jQuery(document).ready(function()
{
	// Instigate No Conflict Mode
	//jQuery.noConflict();
	
	/*** Begin Global Behaviors ***/
	
	// Search query overtype even
	jQuery("input.searchQuery").click(function()
	{
		// If the field contains the default value
		if(jQuery(this).val() == "Enter key word or part #")
		{
			// Then blank out the input field
			jQuery(this).val("");
		}
	});
	
	/*** End Global Behaviors ***/
	
	/*** Begin Story Switcher Behavior ***/
	
	// Initialize counter variable
	var i = 1;
	
	// Give the story buttons unique classes
	jQuery("img.featureButton").each(function()
	{
		// Add a unique class to this button
		jQuery(this).addClass("button_" + i);
		
		// Increment the counter
		i++;
	});
	
	// Reset counter variable
	i = 1;
	
	// Give the featureMix divs unique classes
	jQuery("div.featureMix").each(function()
	{
		// Add a unique class to this button
		jQuery(this).addClass("mix_" + i);
		
		// Increment the counter
		i++;
	});
	
	// Reset counter variable
	i = 1;
	
	// Show the first story feature
	jQuery("div.featureMix").eq(0).show();
	
	// Set the first button to the on state
	jQuery("img.featureButton").eq(0).attr("src", "/~/Media/Extranet/Images/Icons/feature_1_on.ashx");
	
	// Story events
	jQuery("img.featureButton").click(function()
	{
		if(slideAutoStart == true)
		{
			// Disable the autoslide
			slideAutoStart = false;
			
			// Clear the interval
			clearInterval(slideInterval);
		}
		
		// Get the index
		var buttonClassName = jQuery(this).attr("class");
		
		// Split the class name by space
		var buttonClassNameArr = buttonClassName.split(" ");
		
		// Split the second class name by the underscore to get the index
		var storyIndexArr = buttonClassNameArr[1].split("_");
		
		// Initialize a counter
		var j = 1;
		
		// Loop through all of the images and turn them off
		jQuery("img.featureButton").each(function()
		{
			// Turn off this button
		    jQuery(this).attr("src", "/~/Media/Extranet/Images/Icons/feature_" + j + ".ashx");
			
			// Increment the counter
			j++;
		});
		
		// Reset the counter
		j = 1;
		
		// Turn on the current image
		jQuery("img.button_" + storyIndexArr[1]).attr("src", "/~/Media/Extranet/Images/Icons/feature_" + storyIndexArr[1] + "_on.ashx");
		
		// Hide all stories
		jQuery("div.featureMix").hide();
		
		// Show the corresponding one
		jQuery("div.mix_" + storyIndexArr[1]).show();
	});
	
	// Autoplay behavior
	if(jQuery("div.featureMix").length > 0)
	{
		// Declare the autostart variable
		var slideAutoStart = true;
		
		// Declare the index variable(s)
		var x = 2;
		var y = 1;
		
		// Do the autostart
		var slideInterval = setInterval(function()
		{
			// Hide all of the divs at first.
			jQuery("div.featureMix").hide();
			
			// Turn off all of the image on states
			jQuery("img.featureButton").each(function()
			{
			    jQuery(this).attr("src", "/~/Media/Extranet/Images/Icons/feature_" + y + ".ashx");
				
				// Increment the counter
				y++;
			});
			
			// Reset the image flip counter
			y = 1;
			
			// Show the current index
			jQuery("div.mix_" + x).show();
			
			// Turn on the corresponding button
			jQuery("img.button_" + x).attr("src", "/~/Media/Extranet/Images/Icons/feature_" + x + "_on.ashx");
			
			// Increment or reset behavior
			if(x == jQuery("div.featureMix").length)
			{
				x = 1;
			}
			else
			{
				x++;
			}
		}, 5000);
	}
	
	/*** End Story Switcher Behavior ***/
	
	/*** Begin Menu Hovering Behavior ***/
	
	jQuery("div.menuItem").mouseover(function()
	{
		// If this menu item is not set to be permanently on...
		if(!jQuery(this).hasClass("permOn"))
		{
			// ...Add the on class.
			jQuery(this).attr("class", (jQuery(this).attr("class") + "On"));
		}
	}).mouseout(function()
	{
		// If this menu item is not set to be permanently on...
		if(!jQuery(this).hasClass("permOn"))
		{
			// ...Remove the on class.
			jQuery(this).attr("class", (jQuery(this).attr("class").substr(0, (jQuery(this).attr("class").length - 2))));
		}
	});
	
	/*** End Menu Hovering Behavior ***/
	
    /*** Begin Overtype Behaviors for Signup Form ***/

//    jQuery("div.inputField input[type=text]").click(function() {
//        // If the field has the italic class, it assumes there is a default value to be overtyped.
//        if (jQuery(this).hasClass("overtype")) {
//            jQuery(this).removeClass().val("").addClass("black11");
//        }
//        else {
//            jQuery(this).removeClass().addClass("black11");
//        }
//    }).focus(function() {
//        if (jQuery(this).hasClass("overtype")) {
//            jQuery(this).removeClass().val("").addClass("black11");
//        }
//        else {
//            jQuery(this).removeClass().addClass("black11");
//        }
//    }).blur(function() {
//        if (jQuery(this).hasClass("overtype")) {
//            jQuery(this).removeClass().val("").addClass("black11");
//        }
//        else {
//            jQuery(this).removeClass().addClass("black11");
//        }
//    });

	/*** End Overtype Behaviors for Signup Form ***/
    
    /*** Begin IE6 Tagline Warning ***/
    	
	    if(jQuery.browser.msie == true && jQuery.browser.version == "6.0")
	    {
		    jQuery("body").prepend("<div class=\"browserWarning\">We've detected that you are using an obsolete web browser. Consider upgrading for increased compatibility and security: <a href=\"http://www.microsoft.com/ie\" target=\"_blank\">IE 8</a> | <a href=\"http://www.getfirefox.com\" target=\"_blank\">Firefox</a> | <a href=\"http://www.google.com/chrome\" target=\"_blank\">Chrome</a> | <a href=\"http://www.apple.com/safari\" target=\"_blank\">Safari</a></div>");
	    }
    	
	    /*** End IE6 Tagline Warning ***/
});

