$(document).ready(function()
{
	
	/* Navigation */
	slide("#sliding-navigation", 25, 15, 150, .8);
	
	/* Part search Navbar text */ 
	$(function() {
		$("#navpart_txt").watermark();
		$("#navpart_txt").watermark({
			watermarkClass: 'innerText',
			defaultText: 'Enter Part Number / Keywords'
		});
	});
	
	
	$('#navpart').submit(function(){
			
		var partnumber = $("#navpart_txt").val();
//		alert('http://www.sierraic.com/store.php/buy_online/parts/' + escape(partnumber));
		location.href = 'http://www.sierraic.com/store.php/buy_online/parts/' + escape(partnumber);
		
		return false;
	});
	
	
	
	
});




/* Navigation Jquery  */
function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		$(this).css("margin-left","-180px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).animate({ marginLeft: "10px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
		
		
		
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
			
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
}




/* Watermark inside text boxes */
(function($) {
	// Create a plug-in with the name 'watermark'
	$.fn.watermark = function(settings) {
		// Defaults
		var config = {
			watermarkClass: 'watermark',
			defaultText: ''
		};
	
		// merge the passed in settings with our default config
		if(settings) $.extend(config, settings);

		// Loop through the elements in the selector that we call the plug-in on
		this.each(function() {
			// Apply defaults to the box
			$(this).addClass(config.watermarkClass).val(config.defaultText);

			// Apply our focus and blur events
			// When we click on the field, we expect it to clear the field and remove the watermark
			$(this).focus(function() {
				$(this).filter(function() {
					// Check to see if we have a blank field or the default text
					return $(this).val() === "" || $(this).val() === config.defaultText;
				}).val("").removeClass(config.watermarkClass);
			});
			
			// When we click off of the field, we expect it to replace the watermark,
			// unless we have entered text
			$(this).blur(function() {
				$(this).filter(function() {
					// Check to see if the field is blank
					return $(this).val() === "";
				}).addClass(config.watermarkClass).val(config.defaultText);
			});
		});
	};
})(jQuery);

