$jQuery(document).ready(function() {
  
  
//compare products table show/hide script
  var compClick=0;
  
  $jQuery(".compare-trigger").bind("mouseenter",function(){
      var allCheck = 0; 
      $jQuery('table.compare').each( function() {
        $jQuery(this).find(".compare").each( function() { 
          if(this.checked) allCheck++;
        });
      });
      if ( allCheck == 0 ) {
        var position = $jQuery(this).position();
        var positionL = position.left + 80;
        var positionT = position.top + 5;
        $jQuery(this).parent('span').find('span').css({'top': positionT });
        $jQuery(this).parent('span').find('span').css({'left': positionL });
        $jQuery(this).parent('span').find('span').css({'display':'block'});
      }
    }).bind("mouseleave",function(){
      $jQuery(this).parent('span').find('span').css({'display':'none'}); 
  });
  
  $jQuery(".compare-trigger").click( function() {
    if (compClick == 0) {
      var allCheck = 0; 
      $jQuery('table.compare').each( function() {
        $jQuery(this).find(".compare").each( function() { 
          if(this.checked) allCheck++;
        });
      });
      if ( allCheck > 0 ) {
        $jQuery(".compare-trigger").css({'background-position':'0 -31px'});

        $jQuery('table.compare').each( function() {
          $jQuery(this).parent("div").find("img.compare").fadeOut();
          var check = 0; 
          $jQuery(this).find(".compare").each( function() {
            if(!this.checked) $jQuery(this).parents('tr').fadeOut("slow"); 
            if(this.checked) check++;
          });
          $jQuery(this).css({'margin':'18px 0'}); 
          $jQuery(this).parent("div").css({'border':'none'});
          if (check == 0) $jQuery(this).parent("div").fadeOut("slow");
          compClick = 1; 
          return check;
        });
      }
    }
    else {
      $jQuery(".compare-trigger").css({'background-position':'0 0'});
      $jQuery('div.compare').each( function() {
        $jQuery(this).parent("div").find("img.compare").fadeIn();
        $jQuery(this).css({'border-bottom':'3px solid #eaeaea'});
        $jQuery(this).fadeIn();
        $jQuery(this).find("table").fadeIn();
        //$jQuery(this).find("tr").fadeIn();
        $jQuery(this).find("tr").css({'display':'block'});
        compClick = 0; 
        $jQuery('div.compare:last').css({'border':'none'});
      });
    }
  });

//image map product compare column hover script
  $jQuery("area").mouseover(function(){
      var className = ($jQuery(this).attr("class"));
      var highest = 0; //ie 6,7 damaged box model hack
      $jQuery('div.compare').each( function() {
        var columnH = $jQuery(this).height();
        var columnW;
        $jQuery(this).find("td."+className).each( function() {
          var position = $jQuery(this).position();
          if (position.left > highest) highest = position.left; 
          if ($jQuery(this).width() != 0) columnW = $jQuery(this).width();
        });
        //console.log(highest);  
        $jQuery("div.indicator").css({'left':highest+110});    
        $jQuery(this).find("div.indicator").css({'height':columnH});
        $jQuery(this).find("div.indicator").css({'width':columnW});      
        $jQuery(this).find("div.indicator").css({'display':'block'});
      });
    }).mouseout(function(){
       $jQuery("div.indicator").css({'height':'0'});
       $jQuery("div.indicator").css({'display':'none'});
  });
 
//product compare row hover script  
  $jQuery("tr.item").find("td").mouseover(function(){
    var className = ($jQuery(this).attr("class"));
    if (className == "details") $jQuery(this).parents("tr").children("td").css({'background':'none'});
    else {
      $jQuery(this).parents("tr").children("td").css({'background':'#f2f1f1'});
      $jQuery(this).css({'cursor':'pointer'});
      $jQuery(".details").css({'background':'#fff'});
    }
  }).mouseout(function(){
    $jQuery(this).parents("tr").children("td").css({'background':'none'});
  });
  
  $jQuery("table.compare").find("tr.item > td").click(function(){
      var className = ($jQuery(this).attr("class"));
      if (className != "model" && className != "details" ) {
        var boxCheck = $jQuery(this).parents("tr").find(".compare");
        if (boxCheck.attr('checked')) boxCheck.attr('checked',false);
        else boxCheck.attr('checked',true);
      }
  });

//dropdown menu  

/*  $jQuery(document).bind('click', function(e){
      var $jQueryclicked = $jQuery(e.target);
      if (!($jQueryclicked.is('li.features > a.progress-sub-menu') || $jQueryclicked.parents().is('ul.progress-sub-list'))) {
        $jQuery("li.features").find("ul.progress-sub-list").fadeOut();
      }
      else {
        $jQuery("li.features").find("ul.progress-sub-list").fadeIn();
      }
  });
    
  $jQuery(document).bind('click', function(e){
    var $jQueryclicked = $jQuery(e.target);
    if (!($jQueryclicked.is('li.colours > a.progress-sub-menu') || $jQueryclicked.parents().is('ul.progress-sub-list'))) {
      $jQuery("li.colours").find("ul.progress-sub-list").fadeOut();
    }
    else {
      $jQuery("li.colours").find("ul.progress-sub-list").fadeIn();
    }
  });
  
  $jQuery(document).bind('click', function(e){
    var $jQueryclicked = $jQuery(e.target);
    if (!($jQueryclicked.is('li.fitting > a.progress-sub-menu') || $jQueryclicked.parents().is('ul.progress-sub-list'))) {
      $jQuery("li.fitting").find("ul.progress-sub-list").fadeOut();
    }
    else {
      $jQuery("li.fitting").find("ul.progress-sub-list").fadeIn();
    }
  });
  
  $jQuery(document).bind('click', function(e){
    var $jQueryclicked = $jQuery(e.target);
    if (!($jQueryclicked.is('li.solution > a.progress-sub-menu') || $jQueryclicked.parents().is('ul.progress-sub-list'))) {
      $jQuery("li.solution").find("ul.progress-sub-list").fadeOut();
    }
    else {
      $jQuery("li.solution").find("ul.progress-sub-list").fadeIn();
    }
  });

  $jQuery(document).bind('click', function(e){
    var $jQueryclicked = $jQuery(e.target);
    if (!($jQueryclicked.is('div.spot-box > a.sub-menu') || $jQueryclicked.parents().is('div.spot-box'))) {
      $jQuery("div.spot-box").find("ul.progress-sub-list").fadeOut();
    }
    else {
      $jQuery("div.spot-box").find("ul.progress-sub-list").fadeIn();
    }
  }); 
  
  $jQuery(document).bind('click', function(e){
    var $jQueryclicked = $jQuery(e.target);
    if (!($jQueryclicked.is('div.spot-box-blue > a.sub-menu') || $jQueryclicked.parents().is('div.spot-box-blue'))) {
      $jQuery("div.spot-box-blue").find("ul.progress-sub-list").fadeOut();
    }
    else {
      $jQuery("div.spot-box-blue").find("ul.progress-sub-list").fadeIn();
    }
  }); */

  //menu
		$jQuery(".progress-sub-menu").click(function()
		{
			var dd = $jQuery(this).parents("li").find("ul");

			if(dd.css("display") == "none")
			{
				$jQuery('.progress-sub-list').hide(); // hide any other open drop downs
				dd.show();
			}
			else
			{
				dd.hide();
			}
		});

		$jQuery('#progress-bar > li').click(function(e)
		{
			e.stopPropagation();
		});

		
		
		//spotbox
		$jQuery(".sub-menu").click(function()
		{
			var dd = $jQuery(this).parents("div.spot-box").find("ul.progress-sub-list");

			if(dd.css("display") == "none")
			{
				$jQuery('.progress-sub-list').hide(); // hide any other open drop downs
				dd.show();
			}
			else
			{
				dd.hide();
			}
		});

		$jQuery('div.spot-box').click(function(e)
		{
			e.stopPropagation();
		});
		
		$jQuery(".sub-menu").click(function()
		{
			var dd = $jQuery(this).parents("div.spot-box-blue").find("ul.progress-sub-list");

			if(dd.css("display") == "none")
			{
				$jQuery('.progress-sub-list').hide(); // hide any other open drop downs
				dd.show();
			}
			else
			{
				dd.hide();
			}
		});

		$jQuery('div.spot-box-blue').click(function(e)
		{
			e.stopPropagation();
		});


$jQuery(document).click(function()
		{
			$jQuery('ul.progress-sub-list').hide();
		});
		

//product compare range img overlay
  $jQuery(".range-overlay").colorbox();
  
//features table info overlay 
  $jQuery('.bandwith-overlay').colorbox({inline:true, href:"#bandwith-info"}); 
  $jQuery('.proccessing-overlay').colorbox({inline:true, href:"#proccessing-info"}); 
  $jQuery('.synchronisation-overlay').colorbox({inline:true, href:"#synchronisation-info"}); 
  $jQuery('.coordination-overlay').colorbox({inline:true, href:"#coordination-info"});
  $jQuery('.floating-linear-overlay').colorbox({inline:true, href:"#floating-linear-info"}); 
  $jQuery('.spatial-noise-overlay').colorbox({inline:true, href:"#spatial-noise-info"}); 
  $jQuery('.dfc2-overlay').colorbox({inline:true, href:"#dfc2-info"}); 
  $jQuery('.life-learning-overlay').colorbox({inline:true, href:"#life-learning-info"});
  $jQuery('.identities-overlay').colorbox({inline:true, href:"#identities-info"}); 




// 5th column resize script
  var footColNo = $jQuery("#regions_2_footer_0_NavigationBottomMenuPanel").children("div.Column").size(); 
  if (footColNo > 4) $jQuery("#regions_2_footer_0_NavigationBottomMenuPanel .Column").css({'width':'158px'});
  
  $jQuery('ul.dropdown').each( function() {
        var dropdColNo = $jQuery(this).children("li").size(); 
        if (dropdColNo > 6) $jQuery(this).children("li").slice(1,dropdColNo-1).css({'width':'166px'});
  });
});