/*vars*/
var docH = 0;
var docW = 0;
var mulW = 0;
var cH = 0;
var pH = 0;
var menu_index =0;
var anim =0;
var browser = '';
var href = 'http://www.kompix.pl/';
/*functions*/
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
//--
function unique_requestid() { var timestamp = Number(new Date()).toString(); var random = Math.random()*(Math.random()*100000*Math.random()); var unique = new String(); unique = timestamp + random; return unique; }
//--
docW = pageWidth();
docH = pageHeight();
function isset(varname)
{
	if(typeof(varname) != "undefined") return true;
	else return false;
}

$(function(){
/*begin*/
var viewed = 0;
//var ppp = $('#pages').html();
cH = docH-4-parseInt($('.top').css('height'))-parseInt($('.menu').css('height'))-parseInt($('.bottom').css('height'));
pH = cH-parseInt($('#pages').css('margin-top'))-parseInt($('#pages').css('margin-bottom'));
$('ul#menu_btns li').each(function(){ mulW += ($(this).width()+15)});
$('#menu_btns').css({'width':mulW,'margin-left':docW*.5-mulW*.5});
$('#pagesContainer').css({'width':$('#pagesContainer .page').size()*(parseInt($('.page').css('width'))+(docW-parseInt($('.page').css('width')))*$('#pagesContainer .page').size())});
$('.center').css({'height':cH});
$('#pages').css({'height':pH/*,'margin-top':(cH-parseInt($('.page').css('height')))*.5,'margin-bottom':(cH-parseInt($('.page').css('height')))*.5*/});
$('.page').css({'padding-left':(docW-parseInt($('.page').css('width')))*.5,'padding-right':(docW-parseInt($('.page').css('width')))*.5});
$('.partner').css({'margin-right':0})
$('.logo').css({'margin-left':0})

$.ajax({
			   url:href+'extra/index/9',
			   data:'title=Kompix',
			   type:'POST',
			   success:function(data)
			   {
				$('#pagesContainer .page:eq(0)').html(data);
			   }
		});

var index = 999;
//var anim = 0;
$('#navigation li').click(function()
{
	if(anim!=1)
	{
	var curr_index =  $('#navigation').find('li').index(this);
	if (index != curr_index || index == 0)
	{
		index = $('#navigation').find('li').index(this);
		var id = $('input:eq(1)',this).val();
		var module = $('input:eq(0)',this).val();
		var www = href+module;
		if(module =='extra')
		{ 
			www += '/index/'+id; 
		}
		$.ajax({
			   url:www,
			   data:'title='+$(this).text(),
			   success:function(data)
			   {
				menu_index =0;
				anim = 1;
				//$('#pagesContainer div:eq(0)').hide('slide', {direction: 'left'},500,function(){$('#pagesContainer div:eq(0)').html(data);});
				//$('#pagesContainer div:eq(1)').show('slide', {direction: 'right'},500,function(){anim = 0;}); 
				$('#pagesContainer').animate({'marginLeft':'-='+docW},800,
								 function()
								 {
									 $('#pagesContainer .page:eq(0)').html(data);
									 $('#pagesContainer').css({'margin-left':docW+'px'});
									 $('#pagesContainer').animate({'marginLeft':'0px'},800);
									 //$('#pagesContainer .page:eq(0)').insertAfter($('#pagesContainer .page:eq(1)'));
									 anim = 0;
								});
			   }
		});
	}
	}	
});
$.ajaxSetup({type:"POST"});
/**/

$('#swfBanner7img').css({'margin-left':docW*.5-parseInt($('#swfBanner7img').css('width'))*.5});
$('#swfBanner7').css({'margin-left':docW*.5-parseInt($('#swfBanner7').css('width'))*.5});
$('#swfBanner1').flash({swf: 'banners/'+$('#swfBanner1').attr('title'), height:parseInt($('#partner').css('height')),width:parseInt($('#partner').css('width'))});
$('#swfBanner6').flash({swf: 'banners/'+$('#swfBanner6').attr('title'), height:parseInt($('#bottom').css('height')),width:parseInt($('#swfBanner6').css('width'))});
$('#swfBanner7').flash({swf: 'banners/'+$('#swfBanner7').attr('title'), height:parseInt($('#swfBanner7').css('height')),width:parseInt($('#swfBanner7').css('width'))});

$('#bcgFlash').flash({swf: 'bcg.swf', height:docH,width:docW,wmode:'opaque'});
/**/
$('li','#menu_btns').mouseover(function()
{
	if(parseInt($('#menubcgImgTransparent').val()) == 0)
	{
		$(this).css({'color':$('#menufontColorHover').val(),'background-color':$('#menubcgColorHover').val()})
	}else
	{
		$(this).css({'color':$('#menufontColorHover').val(),'background':$('#menubcgColorHover').val()+' url(gfx/menu_transparent_'+$('#menubcgImgTransparent').val()+'.png)'})
	}
});
$('li','#menu_btns').mouseout(function()
{
	if(parseInt($('#menubcgImgTransparent').val()) == 0)
	{
		$(this).css({'color':$('#menufontColor').val(),'background-color':$('#menubcgColor').val()});
	}else
	{
		$(this).css({'color':$('#menufontColor').val(),'background':$('#menubcgColor').val()+' url(gfx/menu_transparent_'+$('#menubcgImgTransparent').val()+'.png)'})
	}
});

$('.innerLink').live('click',function()
{
	var m = $(this).attr('module');
	var g = $(this).attr('go');
	if(anim!=1)
	{
		/*$.ajax({
			   url:href+m+'/index/'+g,
			   data:'title= ',
			   success:function(data)
			   {
				menu_index =0;
				anim = 1;
				$('#pagesContainer div:eq(0)').hide('slide', {direction: 'left'},500,function(){$('#pagesContainer div:eq(0)').html(data);});
				$('#pagesContainer div:eq(1)').show('slide', {direction: 'right'},500,function(){anim = 0;}); 
			   }
		});*/
		g = (m == 'extra') ? g+'/link' : g;
		$.ajax({url:href+m+'/index/'+g,
			   data:'title= ',success:function(data)
			   {
				menu_index =0;
				anim = 1;
				//$('#pagesContainer div:eq(0)').hide('slide', {direction: 'left'},500,function(){$('#pagesContainer div:eq(0)').html(data);});
				//$('#pagesContainer div:eq(1)').show('slide', {direction: 'right'},500,function(){anim = 0;}); 
				$('#pagesContainer').animate({'marginLeft':'-='+docW},800,
								 function()
								 {
									 $('#pagesContainer .page:eq(0)').html(data);
									 $('#pagesContainer').css({'margin-left':docW+'px'});
									 $('#pagesContainer').animate({'marginLeft':'0px'},800);
									 //$('#pagesContainer .page:eq(0)').insertAfter($('#pagesContainer .page:eq(1)'));
									 anim = 0;
								});
			   }
			   });
	}
});

});