var $lk = jQuery.noConflict();

var win = $lk(window);
var minHeight = 808;

var headerSpeed = 800;
var footerSpeed = 600;

function imageToWindowSize(imgPath, layerName) 
{
  var height=minHeight;
  if(win.height()>minHeight)
     height=win.height();
	 
  $lk("#"+layerName).html('<img src="assets/templates/lukkos/'+imgPath+'" alt="Agencja Internetowa Lukkos" style="width:'+win.width()+'px; height:'+height+'px; position:absolute; left:0; top:0;"/>');
}

function setContentParams() 
{
  if(win.height()>minHeight)
  {
	  $lk("#content").height(win.height());	
  }
  else
  {
	  $lk("#content").height(minHeight);
  }
  $lk("#chmura").css({'opacity':0});
  $lk("#chmura").animate({'opacity':1},1900);
}

function addHeader() {
  var ratio = 0.17;
  var height = 137;
  var width = 1275;
  var newHeight = win.height()*ratio;
  var newWidth  = (1275*newHeight)/height;
  var marginLeft = (win.width()-newWidth)/2;
  var header = $lk("#header");
  
  if(newHeight<height || newWidth<width)
  {    
     newHeight=height;
	 newWidth = width;
	 marginLeft=(win.width()-newWidth)/2;
  }
  header.css({ 'height': newHeight, 'width':newWidth, 'left': marginLeft });	
  header.html('<img src="assets/templates/lukkos/images/header.png" alt="Strony internetowe Warszawa" style="width:'+header.width()+'px; height:'+header.height()+'px; position:absolute; left:0; top:-300px;"/>');
  //header.children('img').animate({"top":0 },headerSpeed); 
  header.children('img').animate({"top":0 }, {
                                     duration: headerSpeed,
                                     easing: 'easeInQuad'
								 });
}
function addFooter() {
  var ratio = 0.23;
  var height = 187;
  var width = 1275;
  var newHeight = win.height()*ratio;
  var newWidth  = (1275*newHeight)/height;
  var marginLeft = (win.width()-newWidth)/2;  
  var footer = $lk("#footer");

  if(newHeight<height || newWidth<width)
  {    
     newHeight=height;
	 newWidth = width;
	 marginLeft=(win.width()-newWidth)/2;
  }
	 
  footer.css({ 'height': newHeight, 'width':newWidth, 'left': marginLeft  });	
  footer.html('<img src="assets/templates/lukkos/images/footer.png" alt="Strony internetowe Warszawa" style="width:'+footer.width()+'px; height:'+footer.height()+'px; position:absolute; left:200px; bottom:-250px;"/><div id="zaufaliNam">'+footer.children('#zaufaliNam').html()+'</div>');
  footer.children("img").animate({"bottom":0, 'left':0 }, {
                                     duration: footerSpeed,
                                     easing: 'easeInQuad'
							 });
  if(newHeight>215){
	 $lk('#zaufaliNam').animate({'right':100},2000).show(1000);
  }
  else 
  {
	$lk('#zaufaliNam').animate({'right':80},2000).show(1000);  
  }
}

function addAnimation()
{
 	var mechanik = $lk('#mechanik');
	var monitor = $lk('#malpa');
	var zz = $lk('#znakZapytania');
	var haslo = $lk('#haslo');
	
	if(!$lk.browser.msie)
	{
	  mechanik.css({ 'opacity': 0 });
	  monitor.css({ 'opacity': 0 });
	  zz.css({ 'opacity': 0 });
	  haslo.css({ 'opacity': 0 });
	}
	mechanik.css({ 'display': 'block'});
	monitor.css({ 'display': 'block'});
	zz.css({ 'display': 'block'});
	haslo.css({ 'display': 'block'});
    if($lk.browser.msie)
	{
	  monitor.animate({ 'top':'270px', 'left':'590px', 'width':'319px', 'height':'358px' },
										 {
											 duration: 1000, 
					                         specialEasing: {
							                                   width: 'linear',
      								                           height: 'linear'
					                         }
										 }
	  );
	  zz.animate({ 'top':'470px' },{"duration": 700, "easing": "easeOutBounce"});
	  return false;	
	}
	mechanik.animate({ 'opacity': 1 },{
					 duration: 1000, 
					 specialEasing: {
							        width: 'linear',
      								height: 'easeOutBounce'
					 },
					 complete: function() {
                         monitor.animate({ 'opacity': 0 },2500).animate({ 'opacity': 1, 'top':'270px', 'left':'590px', 'width':'319px', 'height':'358px' },
										 {
											 duration: 1000, 
					                         specialEasing: {
							                                   width: 'linear',
      								                           height: 'linear'
					                         },
										     complete: function() {
											           zz.animate({'opacity': 0.5},300).animate({ 'opacity': 1, 'top':'470px' },{"duration": 700, "easing": "easeOutBounce"});
										     }
										 }); 
                     }
					 }
	);
	haslo.animate({ 'opacity': 0 },1000).animate({ 'opacity': 1 },2000);
}

function rotateBaner() 
{
  var zn = $lk('#zaufaliNam');
  zn.children('a').hide(50);
  if(zn.children('a.active').html()==null)
  {
	zn.children('a').hide(50);
	var active = zn.children('a:first');  
	active.addClass('active');
	active.show(500);
  }
  else
  {
	var active = zn.children('a.active');
	zn.children('a').hide(50);
	zn.children('a.active').removeClass('active');
	if(active.next().html()==null)
	{
	   active = zn.children('a:first');
	   active.addClass('active');
	   active.show(555);
	}
	else
	{
	   active.next().addClass('active');
	   active.next().show(555);
	}
  }
}

function initialize() 
{
	$lk().framerate({framerate: 150 })
  	// Ustawienie tla: biala chmura, wysokosc kontentu, naglówek, stopka
	imageToWindowSize('images/bgChmura.png','chmura');
	setContentParams();
    addHeader();
	addFooter();
	addAnimation();
	clearInterval(si);
	var si = window.setInterval('rotateBaner()', 5500);
}

function mOver() {
	$lk(this).animate({'paddingLeft':'100px'},{"duration": 800, "easing": "easeOutElastic"});
}
function mOut() {
	$lk(this).animate({'paddingLeft':'130px'},{"duration": 300, "easing": "easeOutBounce"});
}

$lk(document).ready(function() {

 $lk(document).pngFix();
 
 initialize(); 
 $lk(window).resize( function() {initialize();} );
 
 var config = {    
     over: mOver, // function = onMouseOver callback (REQUIRED)    
     timeout: 100, // number = milliseconds delay before onMouseOut    
     out: mOut, // function = onMouseOut callback (REQUIRED)  
	 interval: 50
};

 if($lk.browser.msie){
   $lk('#leftColumn ul li a').hover(mOver,mOut);
 }
 else
 {
   $lk('#leftColumn ul li a').hoverIntent( config );
 }


 //$lk('.opinie').feedback({id:'opinie',top:130});
 $lk('.zamow').feedback({id:'zamow',top:240, btImage:'http://www.lukkos.pl/lukkos/assets/templates/lukkos/images/btKonsultant.gif',btHeight:104});

}); 
