function clearSearch()
	{
		document.getElementById('searchField').value = '';
	}
function addSearchTxt()
	{
		var srchFld = document.getElementById('searchField').value;
		
		 if (srchFld == '')
				{
					document.getElementById('searchField').value = 'Keyword or part number';
				}
	}
function mainmenu(){
	$("#main_nav ul.horisontalNav").css({display: "none"}); // Opera Fix
	$("#main_nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(200);
	},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
}

function addToFavorites(urlAddress,pageName) { 
	if (window.external) { window.external.AddFavorite(urlAddress,pageName) 
	} else { alert("Sorry! Your browser doesn't support this function."); 
	} 
} 

function slideShow() {
	var children = $("#topBanner").children().size();
	if( children > 1 ) {

	//Set the opacity of all images to 0
	$('#topBanner li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#topBanner li:first').css({opacity: 1.0});
	

	$('#topBanner li:first').addClass('show');
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	}
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#topBanner li.show')?  $('#topBanner li.show') : $('#topBanner li'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#topBanner li:first') :current.next()) : $('#topBanner li:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#topBanner .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#topBanner .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );

}

function removeHighlightedDelayedDelayed() {
	if(!bool_over_menu) {
		$('#main_nav a').removeClass('highlighted');
	}
}

function removeHighlightedDelayed() {
	if(!bool_over_menu) {
		setTimeout('removeHighlightedDelayedDelayed();',200);
	}
}

function removeHighlighted() {
	setTimeout('removeHighlightedDelayed();',200);
}

$(document).ready(function(){					
	mainmenu();
	slideShow();
	
	// remember when you are over a menu item
	bool_over_menu = false;
	
	// highlight menu items and keep trail as go
	$('ul#horisontalNav li a').bind('mouseover',function() {
														 
		bool_over_menu = true;
		
		// remove color from item and siblings
		$(this).parent().parent().find('a').removeClass('highlighted');
		
		// add color to selected item
		$(this).addClass('highlighted');
		
	});
	
	$('ul#horisontalNav li a').bind('mouseout',function() {
		bool_over_menu = false;
		// allow a brief delay for user to mouseover next menu item, then remove highlighted class from all menu items, including top row
		removeHighlighted();
	});
	
	$('#horisontalNav li ul li').bind('mouseover',function() {
		// if submenu bottom is lower than current page bottom, move submenu up so that it can be seen
		var label_this = $(this).find('a:first').html();
		var label_child = $(this).find('ul:first').find('a:first').html();
		var h_window = Math.round($(window).height());
		var y_this = Math.round($(this).offset().top);
		var y_submenu = y_this; // initially same
		var ar_li = $(this).find('ul:first li');
		var size_ar_li = ar_li.size();
		var h_submenu = 0;
		for(var i=0;i<size_ar_li; ++i) {
			h_submenu += $(this).find('ul:first li:eq(' + i + ')').height();
		}
		var visible_submenu = Math.round($(this).find('ul:first').is(':visible'));
		var bottom_submenu = y_submenu + h_submenu;
		var dy_submenu = h_window - bottom_submenu;
		var memory_dy_submenu = dy_submenu;
		var y_toprow = Math.round($('#horisontalNav').offset().top);
		var h_toprow = Math.round($('#horisontalNav').height());
		var y_mod = false;
		if(((y_this - y_toprow - h_toprow) + dy_submenu) < 0) {
			dy_submenu = 0 - y_this + y_toprow + h_toprow + 10; // 10 is the clearance allowance mentioned below
			y_mod = true;
		}
		dy_submenu = Math.round(dy_submenu);
		if(bottom_submenu > h_window) {
			$(this).find('ul:first').css({
				top: dy_submenu - 10 + 'px' // 10 clearance off bottom to ensure no scrollbar appears
			})
		}
	});
	
	$('.sideNav li a').each(function() {
		$(this).wrap('<div class="indentation" />');
	});
	
	// ie6 fix
	$('.divBoxHeader a').css({
		"color":"#FFFFFF"
	});
	
	// table cell padding fix (translates mce table cellpadding values into td padding values)
	$('table').each(function() {
		var cellpadding = $(this).attr('cellpadding');
		if(cellpadding != undefined) {
			$(this).find('td').css({
				padding:cellpadding + 'px'
			});
		}
	});

});



