var LTEPTA = window.LTEPTA || {};

LTEPTA.namespace = function(ns) {
	if(!ns || !ns.length) {
		return null;
	}

	var n_2 = ns.split(".");
	var n_3 = LTEPTA ;

	for(var i=(n_2[0]=="NY")?1:0;i<n_2.length;++i) {
		n_3[n_2[i]] = n_3[n_2[i]] || {};
		n_3 = n_3[n_2[i]];
	}
	return n_3;
};

// Global behaviors/actions
LTEPTA.namespace("Behavior");


/*** Behavior ***/
LTEPTA.Behavior = {
	init : function(){
		$(document).ready(function(){
			NY.Behavior.liHover();
			//NY.Behavior.setMenuHover("navMain");
			//NY.Behavior.setButtonHover(".submit");
			NY.Behavior.noHref();
		});
	},
	noHref : function() {
		$("a[href=#noHref]").unbind("click.noHref");
		$("a[href=#noHref]").bind("click.noHref", function(){
			return false;
		});
	},
	// takes a jQuery object as an argument
	// binds an image swap behavior on an image
	// if the image is wrapped in an href tag, hovering the linked text will also trigger the image swap
	imageHover : function (jqObjs){
		$(jqObjs).each(function(){
			$(this).unbind("mouseover.imageHover");
			$(this).bind("mouseover.imageHover", function(){
				var imageSrc = $(this).attr('src');
				if (typeof imageSrc !== 'undefined') {
					if (imageSrc.indexOf("-on") == -1){
						imageSrc = imageSrc.replace(/\.png/, "-on.png");
						imageSrc = imageSrc.replace(/\.gif/, "-on.gif");
					}
					$(this).attr('src', imageSrc);
				}
			});
			$(this).unbind("mouseout.imageHover");
			$(this).bind("mouseout.imageHover", function(){
				var imageSrc = $(this).attr('src');
				
				imageSrc = imageSrc.replace(/-on/, "");
				$(this).attr('src', imageSrc);
			});
			// bind an action to any link wrapping this image to trigger the hover behavior
			$(this).parent("a").unbind("mouseover.imageHover");
			$(this).parent("a").bind("mouseover.imageHover", function(){$(this).children('img').trigger("mouseover.imageHover");});
			$(this).parents("a:eq(0)").unbind("mouseout.imageHover");
			$(this).parents("a:eq(0)").bind("mouseout.imageHover", function(){$(this).children('img').trigger("mouseout.imageHover");});
		});
	},
	buttonHover : function(jqObjs){
		/* gobal button hover actions */
		$(jqObjs).each(function(){
			// text button hover for ie6
			if ( $.browser.msie && $.browser.version=="6.0" ){
				$(this).hover(
					function() {
						$(this).addClass("hover");
					},
					function() {
						$(this).removeClass("hover");
					}
				);
			}
			
			// Needs more work.  This worked at one time but is no longer effective
			// fire button click when parent container is clicked
			$(this).unbind("click.buttonHover");
			$(this).bind("click.buttonHover",
				function() {
					$(this).children().find("a").eq(0).trigger("click");
				}
			);
		});	
	},
	fixIE : function() {
		if ($.browser.msie) {

			//ie6 fix for global header
			if ( $.browser.version=="6.0" ){
				$("#navigation>ul>li").hover(function() {
					$(this).addClass("hover");
					$(this).height(31);
					$(this).find('div').show();
				},function(){
					$(this).removeClass("hover");
					$(this).find('div').hide();
				});
			}
		}
	},
	liHover : function() {
		if ($.browser.msie) {
			var cssRule;
			var newSelector;
			for (var i = 0; i < document.styleSheets.length; i++)
				for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
					{
					cssRule = document.styleSheets[i].rules[x];
					if (cssRule.selectorText.indexOf("LI:hover") != -1)
					{
						 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
						document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
					}
				}
			var getElm = document.getElementById("navMain").getElementsByTagName("LI");
			for (var i=0; i<getElm.length; i++) {
				getElm[i].onmouseover=function() {
					this.className+=" iehover";
				}
				getElm[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" iehover\\b"), "");
				}
			}
			var getElm2 = document.getElementById("navLeft").getElementsByTagName("LI");
			for (var i=0; i<getElm2.length; i++) {
				getElm2[i].onmouseover=function() {
					this.className+=" iehover";
				}
				getElm2[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" iehover\\b"), "");
				}
			}
		}
	}	
};

// TODO - BEHAVIORS
// CLICK TO OPEN FAQ?  IS THIS NEEDED?
LTEPTA.Behavior.init();



