
/* START jQUERY */
$(document).ready(function(){
	
	/*
	
	INITIALIZE IE NAVMAIN FIX
	
	*/	
	$("#nav-global li").hover(
		function () {
			$(this).addClass("sfhover");
		}, 
		function () {
			$(this).removeClass("sfhover");
		}
	);
	
	/*
	
	INITIALIZE FIELD VALUE RESET (looks for presence of "alt" attribute in the input tag)
	
	*/
	$("input[alt!='']").focus(function(){
		setValue(this,"onfocus"); 
		return false;
	});
	$("input[alt!='']").blur(function(){
		setValue(this,"onblur"); 
		return false;
	});
	
	//load other images in the current open period as soon as the dom is fully loaded
	$("div.open img").each(function(i, img){
		if(!img.getAttribute("src")){
			img.setAttribute("src", img.getAttribute("_src"));
		}
	})	

	//load the first 6 images of the other periods, the open period will have the src already set
	$("div.period li:first-child img").each(function(j, img){
		if(!img.getAttribute("src")){
			img.setAttribute("src", img.getAttribute("_src"));
		}
	})	
	
	/*
	
	IMAGE BROWSER
	
	*/
	
	$("#image-browser h2").click(function(){
		
		$(this).children("img").removeClass("default-on");
		$("#image-browser h2").children("img.on").css("z-index","0");
		$("div.open").hide().removeClass("open");
		//$(this).next("div.period").animate({width: "show"}, 250, "expoin").addClass("open");
		var period=$(this).next("div.period");
		period.show().addClass("open");
		if(!period.hasClass("openedAlready"))
		{
			$(period.find(".image-set")[0]).scrollLeft(0);
		}
		period.addClass("openedAlready");

		$(this).children("img.on").css("z-index","10");
	
		period.find("img").each(function(i, img){
			if(!img.getAttribute("src")){
				img.setAttribute("src", img.getAttribute("_src"));
			}
		})
		
	});
	
	
	$("#image-browser h2").hover(
		function () {
			$(this).children("img.off").fadeOut("50");
		}, 
		function () {
			$(this).children("img.off").fadeIn("50");
		}
	);
	
		
	
	$('.image-set').serialScroll({
		//target:'.image-set',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.previous',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'x',// The default is 'y' scroll on both ways
		duration:500,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		cycle:true,
		stop:true,
		
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
		//stop:false,// Each click will stop any previous animations of the target. (false by default)
		//lock:true, // Ignore events if already animating (true by default)		
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:true, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
		
			
			// alert("ON BEFORE ");
		
			/*
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.y7
			//e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
	
	/*
			
	SHOW/HIDE VIDEOS
	
	*/
	
	$("#videos h2").click(function(){				
		$(this).toggleClass("open").next("div.asset-flash").slideToggle(250);	
	});
	
	/*
			
	SHOW/HIDE COMMENTS
	
	*/
	
	$("#comments h2.toggler").click(function(){				
		$(this).toggleClass("open").next("div.your-comments").slideToggle(250);	
	});
	
	$("#comments h2.toggler").hover(
		function () {
			$(this).addClass("hover");
		}, 
		function () {
			$(this).removeClass("hover");
		}
	);
	
	/*
	
	-- BEGIN LCOAL NAV FUNCTIONS --
	
	*/
	
		/*
		
		LOCAL NAV: USER CLICKS ARROW EXPANDERS
		
		*/
		$("#nav-local em").click(function(){		
			var $parentLI = $(this).parents("li:eq(0)");		
			var $siblingLIs = $parentLI.siblings();
			var $subMenu = $parentLI.children("ul");		
			var navLevel = ($(this).parents("li").length);
			var slideSpeed = 500;				
			if ($parentLI.hasClass("on")) {		
				$subMenu.slideUp(slideSpeed, function(){ $parentLI.removeClass("on");  });
			} else {
				$parentLI.addClass("on");
				$subMenu.slideDown(slideSpeed, function(){ 
					if (navLevel == 2) {
						$siblingLIs.removeClass("on").children("ul").slideUp(slideSpeed);
					}
				});
			} 
		});
		
		/*
		
		LOCAL NAV: ONLOAD STATE: CSS HAS CERTAIN THINGS TURNED ON/OFF, OVERRIDE HERE:
		
		*/
		$("#nav-local em").css("display","block"); // Show the more/less arrows
		$("#nav-local li.on").children("ul").show(); // make sure sub menus are open on load
		
		/*
		
		LOCAL NAV IE HOVER FIXES
		
		*/
		$("#nav-local em").hover(
			function () {
				$(this).addClass("hover");
			}, 
			function () {
				$(this).removeClass("hover");
			}
		);
	
	/*
	
	-- END LCOAL NAV FUNCTIONS --
	
	*/
 
 
 // -- END jQUERY START BLOCK --
 
 });
 
 

/* setValue clear's a text input's value and resets it to the input's alt attribute if the user doesn't enter a value */
function setValue(pEl,pSwitch) {	
	if (pSwitch == "onfocus") {
		if (pEl.value == pEl.alt) {
			pEl.value = "";	
		}
	}
	if (pSwitch == "onblur") {
		if (pEl.value == "") {
			pEl.value = pEl.alt;
		}
	}
}

/* functionality disbaled popUp window */
function popDisabled() {	
	var strUrl = "../disabled/"; //in case this function is triggered by a button within the ship form	
	var strFeatures	= "width=200,height=200";
	var strTarget		= "disabled";
	window.open(strUrl, strTarget, strFeatures);
	return false;	
}

window.onload=function(){
	
	/* call for suckerfish elements, fsm_common.js */
	//suckerfish(sfHover, "LI", "nav-global");
	
	/* Look for text inputs with the alt attribute set so we can clear/reset onfocus/onblur */
	/*if( document.getElementById && document.getElementsByTagName ){
		var tempEl = document.getElementsByTagName("input");
		for( var i=0; i < tempEl.length; i++ ){		
			if (tempEl[i].type=="text") {						
				if (tempEl[i].alt != "") {
					tempEl[i].onfocus = function(){
					return setValue(this,"onfocus"); 
					};
				}								
				if (tempEl[i].alt != "") {
					tempEl[i].onblur = function(){
					return setValue(this,"onblur"); 
					};
				}
				
			}		
		}
	}	*/

}

/* suckerfish script to allow hover/rollover on non-anchor elements for IE */
function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}

sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
/* end suckerfish */

/* setValue clear's a text input's value and resets it to the input's alt attribute if the user doesn't enter a value */
function setValue(pEl,pSwitch) {	
	if (pSwitch == "onfocus") {
		if (pEl.value == pEl.alt) {
			pEl.value = "";	
		}
	}	
	if (pSwitch == "onblur") {
		if (pEl.value == "") {
			pEl.value = pEl.alt;
		}
	}	
}

