/* jQueryId: imgflip.jquery.js,v 1.1.2.1 2008/08/14 01:05:41 gburns Exp jQuery


Unobtrusive Accessible jQuery 1.2.1 image flips.

Supports:
	- Parent objects triggering flips on images (first child img or input[type='image'] found
	- Focus flips (for accessibility/tabbing)

Usage:
	Name your images with the proper scheme: <name>_off for "regular" state, <name>_on for "over" state.
	In your JavaScript use the syntax jQuery('.rollOverName').imgflip();

Authors:
	bcurtis, gburns

TODO:
	Support "down" state.
	"active" state?
*/


jQuery.fn.imgflip = function() {
	var img_obj, src_parts, hasRolls, jQuerytrigger;
	var reg_match = /^(.*?)([^\/]+)_(on|off|down|active|selected)\.(\w{3,4})jQuery/;
	var self = this;
	return jQuery(this).each(function() {
		// if the element has a src, use it
		// TODO: make sure these are img or input[type='image'] as opposed to something else with a src property?
		if ( this.src ) {
			img_obj = this;
		// otherwise find the first image or input[type='image'] found within the element
		// TODO: make it possible for the flip to not be the first image?
		} else {
			jQuery('img, input[type=\'image\']', this).each(function() {
				if ( this.src.match(reg_match) ) {
					img_obj = this;
					return;
				}
			});
		}

		if (!img_obj) return;
		src_parts = img_obj.src.match(reg_match);
		hasRolls = false;
		if ( src_parts ) {
			// Load images/image paths into object
			if ( !this[src_parts[1] + src_parts[2]] ) this[src_parts[1] + src_parts[2]] = [];
			this[src_parts[1] + src_parts[2]]['default'] = new Image();
			this[src_parts[1] + src_parts[2]]['default'].src = img_obj.src;
			this[src_parts[1] + src_parts[2]]['on'] = new Image();
			this[src_parts[1] + src_parts[2]]['on'].src = src_parts[1] + src_parts[2] + '_on.' + src_parts[4];
			// If the parent is an anchor tag, use that for the mouseover/focus trigger rather than the object itself
			if ( jQuery(this).attr('type') == 'image' || this.parentNode.nodeName != 'A' ) {
				jQuerytrigger = jQuery(this);
			} else {
				jQuerytrigger = jQuery(this).parent()
			}

			jQuerytrigger
				.mouseover(function(img_obj, flip_name) {
					return function() {
						img_obj.src = flip_name;
					}
				}(img_obj, this[src_parts[1] + src_parts[2]]['on'].src))
				// Make sure we don't fire "out" functions too many times if they are clicking
				.mousedown(function(img_obj) {
					return function() {
						img_obj['mouseisdown'] = true;
					}
				}(img_obj))
				.click(function(img_obj) {
					return function() {
						img_obj['mouseisdown'] = false;
					}
				}(img_obj))
				.focus(function(img_obj, flip_name) {
					return function() {
						img_obj.src = flip_name;
					}
				}(img_obj, this[src_parts[1] + src_parts[2]]['on'].src));
			hasRolls = true;
		}

		// TODO: maybe reexamine the logic here
		if ( hasRolls ) {
			if ( jQuery(this).attr('type') == 'image' ) {
				jQuerytrigger = jQuery(this);
			} else {
				jQuerytrigger = jQuery(this).parent()
			}

			jQuerytrigger
				.mouseout(function(img_obj, flip_name) {
					return function() {
						img_obj.src = flip_name;
					}
				}(img_obj, this[src_parts[1] + src_parts[2]]['default'].src))
				.blur(function(img_obj, flip_name) {
					return function() {
						if ( img_obj['mouseisdown'] == false ) img_obj.src = flip_name;
					}
				}(img_obj, this[src_parts[1] + src_parts[2]]['default'].src));
		}

		this['mouseisdown'] = false;
	});

}











jQuery.fn.navRollovers = function() {

    jQuery("#header li img").hover(
		function () {

			var imgSrc = jQuery(this).attr("src");
			if (imgSrc.indexOf("_off") != -1) {
				var img_on = imgSrc.replace("_off", "_on");
				jQuery(this).attr("src", img_on);

			} 


		}, 
		function () {
			var imgSrc = jQuery(this).attr("src");

			if ( jQuery(this).hasClass("nav_locked") ) { 
				//used to ensure menu dropdown button states are not changed on mouse out.	  
			} else {
			
				if (imgSrc.indexOf("_on") != -1) {
					var img_off = imgSrc.replace("_on", "_off");
					jQuery(this).attr("src", img_off);				
				
				}
			
			}

		}
    );

}

var ro = {
	delay: 100,
	products: {
		isOver: false,
		isactive: false,		
		intervalID: null
	},
	retro: {
		isOver: false,
		isactive: false,
		intervalID: null
	},
	closeMenuDropDown: function(isactive, isOver, intervalID, selector, menuID)
	{
		if(!isOver)
		{
			// nav image to off state	
			var img_src_raw = jQuery(selector).attr("src");
			if (isactive) {
				var img_on = img_src_raw.replace("_don", "_active");
			} else {
				var img_on = img_src_raw.replace("_don", "_off");			
			}
			jQuery(selector).attr("src", img_on);		
			
			clearInterval(intervalID);
			jQuery("#" + menuID).addClass("hide");
			intervalID = null;
			isOver = false;
			return;
		}
	}
};

jQuery.fn.topNavDropDowns = function() {

	
	jQuery("#main_nav_products img").mouseover(
		function () {
			if(!jQuery("#products_drop_down:visible").length)
			{				
				var imgSrc = jQuery(this).attr("src");
				if (imgSrc.indexOf("_active") != -1) {
					var img_off = imgSrc.replace("_active", "_don");
					ro.products.isactive = 1;
				} else {
					var img_off = imgSrc.replace("_on", "_don");
			
				}
				jQuery(this).attr("src", img_off);
				jQuery("#products_drop_down").removeClass("hide");	
				hideLanguageDropDown();
				hideLoginDropDown();
				ro.products.isOver = true;
			}
	}).mouseout(	
		function () {
			ro.products.isOver = false;
			clearInterval(ro.products.intervalID);
			ro.products.intervalID = setInterval("ro.closeMenuDropDown( ro.products.isactive, ro.products.isOver,ro.products.intervalID,'#main_nav_products img','products_drop_down')", ro.delay);
		}		
	);
	
	jQuery("#products_drop_down").mouseover(function() {
		ro.products.isOver = true;
	}).mouseout(function() {
		ro.products.isOver = false;
	});
	

	jQuery("#main_nav_retro img").mouseover(
		function () {
			if(!jQuery("#retro_drop_down:visible").length)
			{				
				var imgSrc = jQuery(this).attr("src");

				if (imgSrc.indexOf("_active") != -1) {
					var img_off = imgSrc.replace("_active", "_don");
					ro.retro.isactive = 1;
				} else {
					var img_off = imgSrc.replace("_on", "_don");
			
				}
			
				jQuery(this).attr("src", img_off);
				jQuery("#retro_drop_down").removeClass("hide");	
				hideLanguageDropDown();
				hideLoginDropDown();
				ro.retro.isOver = true;	
			}						
	}).mouseout(
		function () {
			ro.retro.isOver = false;
			clearInterval(ro.retro.intervalID);
			ro.retro.intervalID = setInterval("ro.closeMenuDropDown( ro.retro.isactive, ro.retro.isOver,ro.retro.intervalID,'#main_nav_retro img','retro_drop_down')", ro.delay);
		}
	);
	
	jQuery("#retro_drop_down").mouseover(function() {
		ro.retro.isOver = true;
	}).mouseout(function() {
		ro.retro.isOver = false;
	});


    jQuery("#products_column_2 li").hover(
		function () {
			jQuery("#products_column_2 li").removeClass('current');	
			jQuery(this).addClass('current');
			var link_id = this.id;
			var link_id_length = link_id.length;
			var section_id = link_id.substring(0, (link_id_length - 5) );
			var section_id_element = '#' + section_id;
			jQuery(".products_column_3").addClass('hide');
			jQuery(section_id_element).removeClass('hide');
	
		}, 
		function () {

		}
    );



}
