//Show Hide opacity layers at the images modelu

function hidediv(id) {
	$(".navdropdown").css({"display":"none"});
}

function showdiv(id) {
	document.getElementById(id).style.display = 'block';
	//$("#"+id).slideDown('slow');
}
function showdiv2(id) {
	$(".navdropdown").css({"display":"none"});
	$("#navdropdown"+id).css({"display":"block"});
}





	function findValue(li) {
		if( li == null ) return alert("No match!");
		
		// if coming from an AJAX call, let's use the CityId as the value
		if( !!li.extra ) var sValue = li.extra[0];
		
		// otherwise, let's just display the value in the text box
		else var sValue = li.selectValue;
		
		//alert("The value you selected was: " + sValue);
		}
			
		//function selectItem(li) {
		//findValue(li);
		//}
		
		function selectItem(li) {
		window.location.href='/viewproduct.asp?pid='+li.extra[0];
		}
		
		function formatItem(row) {
		return row[0];// + " (id: " + row[1] + ")";
		}
		
		function lookupAjax(){
		var oSuggest = $("#searchbar_text")[0].autocompleter;
		oSuggest.findValue();
		return false;
		}
		

$(document).ready(function(){
	//$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
		
		//$("ul.topnav li").mouseover(function() { //When trigger is clicked...
		/* $("ul.topnav li").mouseover(function() { //When trigger is clicked...									   
			
			$(this).parent("li.mainmenu").css({"background":"url(/nimages/menubar_hi.gif)"});
			
			//Following events are applied to the subnav itself (moving subnav up and down)
			//$(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
			$(this).find("ul.subnav").css({"display":"block", "z-index":"999"});
			$(this).find("ul.subnav li").css({"z-index":"999"});
			$("#promomenu li").css({"z-index":"1"});
	
			$(this).hover(function() {
			}, function(){	
				//$(this).find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
				$(this).find("ul.subnav").css({"display":"none"});
				$(this).parent("li.mainmenu").css({"background":"url(../nimages/menubar_sep.gif) no-repeat right"});
			});
	
			//Following events are applied to the trigger (Hover events for the trigger)
			}).hover(function() { 
				$(this).addClass("subhover"); //On hover over, add class "subhover"
			}, function(){	//On Hover Out
				$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		}); */
		 
		
		
		$(".electromenu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    40,   // maximum width of sub-menus in em units 
            extraWidth:  2     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
			animation: {height:'show'}, delay: 120, autoArrows: false
		}); //.find('ul').bgIframe({opacity:false}); 
		
		//$("ul").bgiframe();
		//alert( $(".electromenu").superfish().find("ul").bgIframe({opacity:false}).attr("id") ); 
		
		$("#searchbar_text").focus(function(){
		 	if($("#searchbar_text").val()=="Keyword / Model #"){
				$("#searchbar_text").val('');	
			}
		});
		
		$("#searchbar_text").blur(function(){
		 	if($("#searchbar_text").val()==""){
				$("#searchbar_text").val('Keyword / Model #');	
			}
		});
		
		$("#searchform").submit(function(){
			if($("#searchbar_text").val().length < 2 || $("#searchbar_text").val()=="Keyword / Model #"){
				//alert("ooppsss");
				$("#errorbar").html("Error: please enter a valid search term.");
				$("#errorbar").css({"opacity": "1"});
				$("#errorbar").slideDown();
				$("#searchbar_text").focus();
				$("#errorbar").animate({
					"opacity": "0.1"					   
				}, 9000, "swing", function(){$("#errorbar").slideUp();});
				
				
				return false;
			}else{return true;}
								
		});
		
		jQuery.each(jQuery.browser, function(i) {
			  if($.browser.msie){
					//Best for IE8
					if($.browser.version!=/6.0/){
						$(".electromenu li ul").hover(function(e){
							var thisID = (this.id).split("-");
							$("#"+thisID[1]).addClass("forceHover");
						},
						function(){
							var thisID = (this.id).split("-");
							$("#"+thisID[1]).removeClass("forceHover");
						});
					};
			  }else{
					 //Best for Firefox
					 $(".electromenu li ul").mouseover(function(e){
						var thisID = (this.id).split("-");
						$("#"+thisID[1]).addClass("forceHover");
					});
					
					$(".electromenu li ul").mouseout(function(e){
						var thisID = (this.id).split("-");
						$("#"+thisID[1]).removeClass("forceHover");
					});
			  }
		});


		
		$(".electromenu li.menheader").mouseout(function(e){
			//alert("test");
			//var thisID = (this.id).split("-");
			//$("#"+thisID[1]).removeClass("forceHover");
		});
		
		
		//autocomplete
		 
			
			
			$("#searchbar_text").autocomplete(
			"/includes/autocomplete.asp",
			{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			maxItemsToShow:10,
			cacheLength:1,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:false,
			width:300
			}
			);
		
		$('#bgblack').css({'height':$(document).height(), 'width':$(document).width()})
});