$(document).ready(function() {

 if($('body').attr('id')=='hp') {
  if(screen.height>1900) {$('body').addClass("bigSite");}
  swfobject.embedSWF("http://www.datacom.pl/f/partnerzy.swf", "flashBox", "610", "126", "9.0.0", "expressInstall.swf");
 }
 var slidePos=0;
 var activeHead=0;
 var timer=0;
 
 function setCounter(){
   timer=setInterval(function() {
            var next=(activeHead==3?1:activeHead+1);
            var act=activeHead;
            //alert(activeHead);
  					$('#header'+act).fadeOut(400,function(){$('#header'+next).fadeIn(400);activeHead=next;setAct(activeHead)});
  				}, 15000);
 }

 $('#header1').fadeIn(400,function(){activeHead=1; setCounter(); setAct(activeHead)});
 
 function setAct(x){
  $('#headerNav li').removeClass('act');
  $("#headerNav li[name='"+x+"']").addClass('act');
 }
 
 /*header nav*/
 $('#headerNav li').click(function(){
  if($(this).attr('name')==activeHead || activeHead==0) return;
  var next=eval($(this).attr('name'));
  clearInterval(timer);
  $('#header'+activeHead).fadeOut(400,function(){$('#header'+next).fadeIn(400);activeHead=next;setCounter();setAct(activeHead)});
 });
 
 /* nav */
 $('#nav li').hover(function(){
  if($(this).find('ul').length > 0){
   $(this).addClass('hovered');
   $(this).find('ul').eq(0).css({display: 'block'});
  }
 },function(){
  if($(this).find('ul').length > 0){
   $(this).removeClass('hovered');
   $(this).find('ul').eq(0).css({display: 'none'});
  }
 });
 
 $('#searchBtn').click(function(){
    var adr="wdrozenia_filter.php?produkt="+($('#produkt').attr("value"))+"&branza="+($('#branza').attr("value"))+"";
    window.location=adr;

 });
 
   $('#searchBtnENG').click(function(){
    var adr="deployments_filter.php?produkt="+($('#produkt').attr("value"))+"&branza="+($('#branza').attr("value"))+"";
    window.location=adr;

 })
 
 
 $('.polecamyHP .changeL,.polecamyBox .changeL').click(function(){
    var tmp=$('#movingPanels .panel').css('width');
    slideW=tmp.substr(0,tmp.indexOf('px'));
    slideBoxCount=$('#movingPanels .panel').length;
    slidePos-=1;
    if(slidePos<0) {$("#movingPanels0").animate({"left": ("-="+(slideW*(slideBoxCount-1))+"px")}, 500); slidePos=(slideBoxCount-1);}
    else $("#movingPanels0").animate({"left": ("+="+slideW+"px")}, 500);
 });
 
 $('.polecamyHP .changeR,.polecamyBox .changeR').click(function(){
    var tmp=$('#movingPanels .panel').css('width');
    slideW=tmp.substr(0,tmp.indexOf('px'));
    slideBoxCount=$('#movingPanels .panel').length;
    slidePos+=1;
    if(slidePos>(slideBoxCount-1)) {$("#movingPanels0").animate({"left": ("+="+(slideW*(slideBoxCount-1))+"px")}, 500); slidePos=0;}
    else {$("#movingPanels0").animate({"left": ("-="+slideW+"px")}, 500);}
 });
 
 
 
 $('.bigTabs .tabber').click(function(){
    var p=$(this).parent().parent();
    var clickId=p.attr('id');
    var ck=$.cookie('datacomTabs');
    if (ck==null || ck===0 || ck=='') ck = '';
    ck=ck.split(',');
    if(p.hasClass('expanded')){ //collapse
      p.removeClass('expanded');
      var tmp=new Array();
      for (key in ck){
        if(ck[key]!=clickId) tmp[tmp.length]=ck[key];
      }
      $.cookie('datacomTabs', tmp.join(','), {expires: 7});
    }
    else {                      //expand
      p.addClass('expanded');
      if(!$.in_array(clickId,ck)) {
        ck[ck.length]=clickId;
        $.cookie('datacomTabs', ck.join(','), {expires: 7});
      }
    }
    return false;
 });
 

 
});
