﻿
 	$(window).load(
		function() {
		   setHeightLeftNavMain();
		}
	);
	
	$(document).ready(function() {
	
	
 		// disable right click
		$(document).bind("contextmenu",function(e){
	        if (window.location.href.toLowerCase().indexOf('www.isuppli.com') >= 0 ) {
	        	return false;
	        }
	    });
	    

		if (webName != "") { 
			$("#LeftNavList li a[href*=" + webName + "]").parent().addClass('current');
			$("#AnalystList li a[href*=" + webName + "]").parent().addClass('current');	

			if($("#AboutList").length > 0) {
				$("#AboutList li a[href*=" + highlightLink + "]").parent().addClass('current');	
			}
			
		}
		
		if (urlTest('Automotive-Infotainment-and-Telematics') > 0){		
			$("#loginLink").attr('href', 'http://ilibrary.isuppli.com/Portal/Index/');	
			$("#loginLink").attr('title', 'Client Portal Login');
			$("#loginLink").attr('onClick', "pageTracker._trackPageview('/portal/login');");			
		}
			
		
		// works in IE, isn't working in others
		//if (TopNav != "") { 
		//	$("#menu li a[innerHTML^=" + TopNav + "]").parent().removeClass('menuItem').addClass('menuItemSelected');
		//}

		$("#menu li a").each(function (i) {
			if (  this.innerHTML == TopNav  ) {
				 $(this).parent().removeClass('menuItem').addClass('menuItemSelected');
			}
			if ( TopNav == "newsletter")  {
				$("#newsletter").removeClass('newsletter').addClass('newsletterSelected');
			}
		});
	
		$("#menu li[class=menuItem] a").hover(
		  function () {
		    $(this).parent().removeClass('menuItem').addClass('menuItemSelected');
		  },
		  function () {
		    $(this).parent().removeClass('menuItemSelected').addClass('menuItem');
		  }
		);
		
		$("#menu li[class=newsletter] a").hover(
		  function () {
		    $(this).parent().removeClass('newsletter').addClass('newsletterSelected');
		  },
		  function () {
		    $(this).parent().removeClass('newsletterSelected').addClass('newsletter');
		  }
		);

		$("#subtabs li a").hover(
		  function () {
		    $(this).parent().addClass('over');
		  },
		  function () {
		    $(this).parent().removeClass('over');
		  }
		);
		
		doSearchSetup();

		
		$("#meganchor").hover(
		  function () {
			  showMega();
		  },
		  function () {
			  hideMega();
		  }
		);

		$("#megadrop").hover(
		  function () {
			  showMega();
		  },
		  function () {
			  hideMega();
		  }
		);


		function showMega() { 
			$("#megadrop").css("left", $("#meganchor").position().left );
			$("#megadrop").show();
		}

		function hideMega() { 
			$("#megadrop").hide();
		}
			
		//$("div#expandclick").click(function() { 
		//	$("#readmore").slideToggle("fast");
		//	$(this).toggleClass("active");		
		//});
	
		var expandclick1 = $("#homeexpandclick");
		expandclick1.click(function() { 
			$("#homereadmore").slideToggle("fast");
			$(this).toggleClass("active");
			if ( expandclick1.text() == 'Close »' ) {
				expandclick1.text('Learn More »');
			} else {
				expandclick1.text('Close »');
			}
		});

		var expandclick = $("#expandclick");
		expandclick.click(function() { 
		
			$("#readmore").slideToggle("fast");

			if ( expandclick.text() == 'Close »' ) {
				expandclick.text('Learn More »');
			} else {
				expandclick.text('Close »');
			}

		});

		// setHeightLeftNavMain();
		
		$("a[href^='mailto:info@isuppli.com']").click(function(){
			_gaq.push(['_trackEvent','Contact Us','Common']);
		});
		
		$(".infopv").click(function(){
			_gaq.push(['_trackEvent','Contact Us','Photovoltaics'])
		});
		
		$(".infomems").click(function(){
			_gaq.push(['_trackEvent','Contact Us','Mems'])
		});		
		
		
	});
	

	function setHeightLeftNavMain() {

		var foot = 0 ;		
		var x	= $("#main").height() ;
		var y 	= $("#leftnav").height();
		var max	= Math.max(x,y);
		
		
		$("#main").height(max + foot);
		$("#leftnav").height(max + foot);
		//$("#main-subfooter").position({ my: "left bottom",  at: "left bottom",  of: "#main"	});

	}


   function adjustHeight() {

            var x = $("#maincontent").height();
            var y = $("#leftnav").height();

            if (y < 700) { y = 700 };
            y = Math.max($("#iLibMenu").height(), y);

            var max = Math.max(x, y);
            $("#main").height(max);
            $("#leftnav").height(max);

    }
        
	function doSearchSetup() {
	
		$("#SearchKeyword").focus( function() {
			if ($("#SearchKeyword").val() == 'Search All of iSuppli')	{
				$("#SearchKeyword").val('');
			}
		});
		
		$("#SearchKeyword").focus( function() {
			$('#SearchKeyword').keypress(function(event) {
			  if (event.keyCode == '13') {
			  	 event.preventDefault();
			     GotoSearch();
			  }
			});
		});
		
		$("#SearchKeyword").focus( function() {
			$('#SearchButton').click(function(event) {
			  	 event.preventDefault();
			     GotoSearch();
			});
		});
		
		
		$("#iLibSearchKeyword").focus( function() {
			if ($("#iLibSearchKeyword").val() == 'Search the iLibrary')	{
				$("#iLibSearchKeyword").val('');
			}
		});
		
		$("#SearchKeyword").focus( function() {
			$('#iLibSearchKeyword').keypress(function(event) {
		  	if (event.keyCode == '13') {
		  	 event.preventDefault();
		     iLibSearch();
		  	}
			});
		});
		
		$("#SearchKeyword").focus( function() {
			$('#iLibSearchButton').click(function(event) {
  	 		event.preventDefault();
		 		iLibSearch();
			});
		});
		
	}
	
 	function GotoSearch() {
		str = $("#SearchKeyword").val();
		if (str == 'Search All of iSuppli') { 
			document.location = "/Pages/Market-Research-Search.aspx";
		} else {
			document.location = "/Pages/Market-Research-Search.aspx?k=" + str ;
		}
	}
	
	function iLibSearch() { 
		str = $("#iLibSearchKeyword").val();
		if (str != 'Search the iLibrary' ) { 
			if (str != '') {  
				document.location = "/Default.aspx?k=" + str ;
			} 
		}

	}
	
	function urlTest(testString) {
			var url = window.location.href;
			var resultsArray = url.split('/');
            var result = jQuery.inArray(testString, resultsArray);
			return result;
    }




