function switchCategory(id) {
    if (id=='configurator') {
        
        return false;
    }
    if ($('#'+id).length ) {
        $('#content .double>div').each(function () {
            if (this.id && this.id!=id  ) {
                $(this).fadeOut(0);
                
            } 
            $('#'+id).fadeIn(500);    
        });
        
    } else if (id=='all') {
        $('#content .double>div:hidden').each(function () {
            $(this).fadeOut(0).fadeIn(500);
            
        });
        
        
    }
    $('#content ul.mini.local a').removeClass('selected');
    $("#content ul.mini.local a[href*='"+id+"']").addClass('selected');
    
    return false;
}

function isParent(el1,el2) {
    if (!el1.parentNode) { return false};
    if (el1.parentNode==el2) { return true};
    return isParent(el1.parentNode,el2);
}


    var hovers=[];
    var objects=[];
    var n=0;

function hide(n) {
  object=objects[n];
  if (!indexOf(hovers,object)) {
    $(object).removeClass('hover');
  }
  
}

function setActions() {
  $('#actions').css('padding-left',(document.body.clientWidth-906)/2+'px');
}

$(window).resize(function(){
  setActions();
});

$(document).ready(function() {
  $('#model_img_mini').parents('a').click(function() {
    $('#model_img').attr('src',this.href);
    if (this.href.indexOf('cabstar-dc')>0) {
        href=$('#model_img').attr('src');
        $('img',this).attr('src','/upload/cabstar_mini.png');
        $(this).attr('href','/upload/iblock/00d/cabstar_norm.png');
        $('#color').css('visibility','hidden');
    } else {
        $('img',this).attr('src','/upload/cabstar-dc_small.png');
        $(this).attr('href','/upload/cabstar-dc_normal.png');
        $('#color').val('').css('visibility','visible');
    
    }
    return false;
  })
    $('input').placeholder();
    $('.popeye').each(function () {$(this).popeye();});
    $('#color').bind('change', function () {
    
            $('#model_img').attr('src',this.value);
            if ($.browser.msie && $.browser.version<7) {
      $('#model_img')[0].style.behavior='';
     
      $('#model_img')[0].style.behavior=' url("/css/fix/iepngfix.htc")';
     
   
   }
    });
    
    $('#actions').width('auto').css('text-align','left');
    
    $first=$('#actions div:visible:first');

    setActions();
    
    if ($.browser.msie && $.browser.version) {
       
         $('ul#menu, ul#menu ul').hover(
            function () {
                $(this).addClass('hover');
            },
            function () {
                $(this).removeClass('hover');
            }
        ); 
      /*$('div#grey').hover(
       function () {
      
         $('div#grey').css('z-index','1');    
       $('div#grey *').css('z-index','1');    
     }
    ) */
        $('#menu li').hover(
            function () {
                
                if (this.tagName=='LI') {
            
                    $ul=$('ul',this);
                    if (this.parentNode.id=='menu' ) {
                    //    $('div#grey').css('z-index','-10');
                       /* $('div#grey *').css('z-index','-7');
                        $('div#footer *').css('z-index','1');
                        $('div#grey>div:first-child').css('z-index','-1'); */
                        $('li',$ul).css('width',$ul.width()-0+"px");
                        $('li a',$ul).css('width',$ul.width()-40+"px");
                        $('li li',$ul).css('width',$ul.width()+10+"px");
                        $('li li a',$ul).css('width',$ul.width()-30+"px");
                        
                    }
              }
                
        $(this).siblings().removeClass('hover'); 
                $(this).addClass('hover');
              hovers.push(this); 
            },
            function  () {
            
                if (this.tagName!='UL' && this.tagName!='LI' && this.tagName!='A' ) {
           
                  $('div#grey').css('z-index','1');    
          $('div#grey *').css('z-index','1');                
        } 
        n++;
        objects[n]=this;
        hovers[indexOf(hovers,this)]='';
        setTimeout('hide('+n+')' ,100)
            }
        );
         
     }
     $('ul.photos').gallery();
     //if ($.browser.msie) {
       $('ul.photos img, img.big').load(function() {
         $(this).hide().show();
     } )
   //}
    if ($.browser.msie && $.browser.version<7 && $('#model_img').length) {
      $('#model_img')[0].style.behavior=' url("/css/fix/iepngfix.htc")';
     
   }
     $('.scrolableTable').each(function() {
       
            var tables=$('div table',this);
       
       var tr1=$('tr',tables[0]);
       var tr2=$('tr',tables[2]);
       
       
       
       var count=tr1.length;
       
        t_tr2=$('div.heading tr',this)[0];
       
       count=tr1.length;
       
       for (var i=0; i<count; i++) {
         $(tr1[i]).height()>$(tr2[i]).height()?$(tr2[i]).height($(tr1[i]).height()):$(tr1[i]).height($(tr2[i]).height());
       }
       
       var td1=$('th span',tables[1]);
       var td2=$('td',tables[2]);
      
       count=td1.length; 
       for (var i=0; i<count; i++) {
        
         $(td1[i]).width()>$(td2[i]).width()?$(td2[i]).width($(td1[i]).width()):$(td1[i]).width($(td2[i]).width());
       }
       var parent=this;
       $('.data',this).bind('scroll', function (e)  {
        
         $('.heading',parent)[0].scrollLeft=$(e.target)[0].scrollLeft;
     });
     $('.scroller',this).bind('scroll', function (e)  { 
      $('.columns',parent)[0].scrollTop=this.scrollTop;
      $('.data',parent)[0].scrollTop=this.scrollTop;
     });
      $('.body',this).bind('scroll', function (e)  {
        
        $('.data',this)[0].style.width=500+$(e.target)[0].scrollLeft+'px';
     });
     
      $('div.body',this).height($('div.columns',this).height()+$('div.heading',this).height()+20);
     
      
      $('div.columns',this).css('margin-top',$('div.heading table',this).height()+'px');
   });
  
     setTimeout('$.historyInit(switchCategory)',1000);
});
var event;

function indexOf(array,item) {
  for (var i in array) {
    if (array[i]==item)
      return i;
  }
  return false;
  
}

$.fn.gallery=function () {
    return $(this).each(function() {
       var w=1000; var h=$('img.big').height();
        if (this.tagName!='UL') return false;
        
        $('a', this).click(function () {
          var h=$('img.big').height();
          //if ($(this).parents('.news_list').length) { w=1000; h=450;}
            var src='/resize/?random=5&width='+w+'&height='+h+'&file='+$(this).attr('href');
            $('img.big',this.parentNode.parentNode.parentNode).attr('src',src);
            return false;
        })
        
    }); 
    
}

function hideActions() {
    $('#actions').animate({marginTop:'-200px'},600);
}
$(document).ready(function () {
    $('#help').click(toogleHelp);
});

function toogleHelp(e) {
    $this=$(this);
    if (e.target.tagName!="FORM" && e.target.tagName!='DIV' && e.target.type!='submit') return false; 
    if (parseInt($this.css("top"))<0) {
        $this.animate({left:"100px", top:"50px",width:"596px", height:"336px"},1500,null,function(){$('div',this).fadeIn(300)});    
    } else {
        $('div',this).fadeOut(300,function() {$this.animate({left:"17px", height:"0", top:"-6px",width:"48px"},1500)});
        
    
    }
    
    
}

$('ul.tabs a').live('click',function() {
  var id=this.href.split('#')[1];

  $('.tabs .selected').removeClass('selected');
  $('#'+id).addClass('selected');
  $(this).addClass('selected');
  return false;
})