
// image rollover
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// toggle content
$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$("#toggle div, #toggle p").hide();

	//Switch the "Open" and "Close" state per click
	$("#toggle h2, #toggle h3").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("#toggle h2").click(function(){
		$(this).next("div").slideToggle("normal");
	});
	
	$("#toggle h3").click(function(){
		$(this).next("p").slideToggle("normal");
	});

});



/**
 * Slideshows
 */
initSlideshow = function( id ) {
	var slideshow = document.getElementById( id );
	if ( slideshow ) {
		var current = -1;
		var imgs = slideshow.getElementsByTagName('img');
		if ( imgs.length > 1 ) {
			for ( var i = 1; i < imgs.length; i++ ) {
				imgs[i].xOpacity = 0;
				if ( current == -1 && imgs[i].className == "first" ) {
					imgs[i].style.display = 'block';
					imgs[i].xOpacity = .99;
					current = i;
				}
			}
			
			if ( current == -1 ) {
				current = 0;
				imgs[0].style.display = 'block';
				imgs[0].xOpacity = .99;
			}
			
			var desc = {
				mainDiv: slideshow,
				imgs: imgs,
				current: current
			}
		
			setTimeout( function() {slideshow_xfade(desc);}, 3000 );
		}
	}
}

slideshow_xfade = function( desc ) {
		
	var cOpacity = desc.imgs[ desc.current ].xOpacity;
	var nIndex = desc.imgs[ desc.current + 1 ] ? desc.current + 1 : 0;
	var nOpacity = desc.imgs[ nIndex ].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	desc.imgs[ nIndex ].style.display = 'block';
	desc.imgs[ desc.current ].xOpacity = cOpacity;
	desc.imgs[ nIndex ].xOpacity = nOpacity;

	setOpacity( desc.imgs[desc.current] );
	setOpacity( desc.imgs[nIndex] );

	if ( cOpacity <= 0 ) {
		desc.imgs[ desc.current ].style.display = 'none';
		desc.current = nIndex;
		setTimeout( function() {slideshow_xfade(desc);}, 3000 );
	}
	else {
		setTimeout( function() {slideshow_xfade(desc);}, 50 );
	}

	function setOpacity( obj ) {
		if ( obj.xOpacity > .99 ) {
			obj.xOpacity = .99;
			return;
		}
	
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}


var isIE = false /*@cc_on || true @*/;

/**
 * Form field hints
 */
wireInputHints = function() {
	var fields = { login_email:{pswd:false}, login_pswd:{pswd:true} };
	for ( var id in fields ) {
		var field = fields[ id ];
		wireInputHint( id, field.pswd );
	}
}

wireInputHint = function( id, isPassword ) {
	var el = document.getElementById( id );
	if ( el ) {
		el.setAttribute( "isPassword", isPassword ? "1" : "0" );
		if ( el.value == "" || el.value == el.getAttribute("hint") ) {
			if ( el.getAttribute("isPassword") == "1" ) {
				if ( isIE )
					el.className = "pswd_instruct";
				else {
					el.type = 'text';
					el.value = el.getAttribute("hint");
				}
			}
			else
				el.value = el.getAttribute("hint");
			el.style.color = "#999999";
			el.showingInstruction = true;
		}
		else {
			if ( el.getAttribute("isPassword") == "1" ) {
				if ( isIE )
					el.className = "";
				else {
					el.type = 'password';
				}
			}
			el.style.color = "#000000";
			el.showingInstruction = false;
		}
		el.onfocus = function() {
			if ( this.showingInstruction ) {
				this.value = "";
				this.showingInstruction = false;
				this.style.color = "#000000";
				if ( this.getAttribute("isPassword") == "1" ) {
					if ( isIE )
						this.className = "dummy";
					else {
						this.type = 'password';
						if ( navigator.userAgent.indexOf("Safari") != -1 ) {
							/* changing the input type on Safari screws up the input focus... */
							this.focus();
							this.select();
						}
					}
				}
			}
		}
		el.onblur = function() {
			if ( this.value == "" ) {
				this.showingInstruction = true;
				this.style.color = "#999999";
				if ( this.getAttribute("isPassword") == "1" ) {
					if ( isIE ) {
						this.className = "pswd_instruct";
					}
					else {
						this.type = 'text';
						this.value = this.getAttribute("hint");
					}
				}
				else
					this.value = this.getAttribute("hint");
			}
		}
	}
}



// generates a centered popup
function popup(url, w) 
{
 var width  = 500;
 if ( w )
 	width = w;
 var height = 550;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
// params += ', resizable=no';
// params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname'+width, params);
 if (window.focus) {newwin.focus()}
 return false;
}

var web_path = "/sixflags/";

function onLoaded() {
	wireInputHints();
	
	MM_preloadImages(
		web_path + 'images/signup_over.png',
		web_path + 'images/nav_signup_over.png',
		web_path + 'images/nav_home_over.png',
		web_path + 'images/nav_about_over.png',
		web_path + 'images/nav_questions_over.png',
		web_path + 'images/nav_wild_over.png',
		web_path + 'images/nav_parents_over.png',
		web_path + 'images/nav_six_flags_over.png',
		web_path + 'images/nav_find_park_over.png',
		web_path + 'images/subnav_about_over.png',
		web_path + 'images/subnav_eligibility_over.png',
		web_path + 'images/subnav_signing_up_over.png',
		web_path + 'images/subnav_get_over.png',
		web_path + 'images/signup_over.png' );
	
	initSlideshow( "slideshow" );
}

window.onload = onLoaded;



