// POPUP WINDOWS

		function randOrd(){
			return (Math.round(Math.random())-0.5);
		} 


	// object creator for handling image swappers
		function swapImg(url, width, height, rate, parent, interval) {
			root            = this;
		// globals
			root.docsArr    = [];
			root.current    = false;
			root.total      = false;
			root.timer      = false;
			interval        = (interval) ? interval*1000 : 8000;
		// determine placement
			root.swapQry = new queryHandler(url)
			switch(root.swapQry.pos) {
				case 'right':  root.pos = 'promo_rightnav';   break;
				case 'bottom': root.pos = 'bottomnav_banner'; break;
			}
		// populates docs array
			root.init    = function(arrayData, interval) {
				if (typeof(arrayData) == 'string') {
					try {
						arrayData = eval(arrayData)
					} catch (e) {
						//alert(arrayData)
					}
				}
				arrayData.sort(randOrd);

			// create DOM structure
				root.domStruct              = document.createElement('a');
				root.domStruct              = parent.appendChild(root.domStruct);
				root.domStruct.style.width  = width  + 'px';
				root.domStruct.style.height = height + 'px';
				root.domStruct.href         = '#';
				root.domStruct.name         = '&lpos=' + root.pos + '&lid=#';
				root.domStruct.className    = 'imgFadeSwap';
			// set custom attributes
			// set initial values
				root.domStruct.docsArr  = arrayData;
				root.domStruct.current  = 0;
				root.domStruct.total    = arrayData.length;
				root.domStruct.interval = interval;
			// make botttom image
				var botImage                = document.createElement('img');
					botImage                = root.domStruct.appendChild(botImage);
					botImage.width          = width;
					botImage.height         = height;
					botImage.className      = 'bottom';
					botImage.style.position = 'absolute';
				// initiates an image swap
					botImage.onload = function() {
						if (client.engine != 'gecko') {
							motion.set(this.nextSibling, 'opacity', ['1.0', '0.0'], 0.1);
						} else {
							this.style.visibility = 'hidden';
						}
					}
			// make top image
				var topImage                = document.createElement('img');
					topImage                = root.domStruct.appendChild(topImage);
					topImage.width          = width;
					topImage.height         = height;
					topImage.className      = 'top';
					topImage.style.position = 'absolute';
				// initiates an image swap
					topImage.onload = function() {
						var src    = this.getAttribute('src');
						var top    = this;
						var parent = this.parentNode;
						var bottom = this.previousSibling;
					// transfer top image to bottom image
						var setBase = function() {
							bottom.src = src;
						}
						var nextImage = function() {
							parent.current = (parent.current + 1) % parent.total;

							var src  = parent.docsArr[parent.current][0];

							var name = src.split('/')[src.split('/').length-1].split('.')[0];
							top.src        = src;
							parent.href    = parent.docsArr[parent.current][1];
							parent.name    = parent.name.split('&lid=')[0] + '&lid=' + name;
						}
					// do it
						if (client.engine != 'gecko') {
							motion.set(this, 'opacity', ['0.0', '1.0'], 0.5, setBase);
						} else {
							this.style.visibility = 'visible';
						}
						root.timer = setTimeout(nextImage, this.parentNode.interval);
				}
			// set initial appearance.
				topImage.src        = root.domStruct.docsArr[0][0];
				root.domStruct.href = root.domStruct.docsArr[0][1];
			}
		// make reqest and initialize
			ajax.get(url, root.init, [interval]);
			return false;
		}


	// FLASH LINKS
/*	
		function goLink(arg1, arg2, arg3) {
			_hbLink(arg1, arg2);
			if (arg2.indexOf('_video_') != -1) { hbxMediaPlay(arg_2, hbxCurrentPos) }
			if (arguments.length == 3) {
				if (arg3.indexOf('//') != -1) {
					var thsDomain = document.location.href.split('//')[1].split('/')[0];
					var thsProtoc = document.location.href.split('//')[0];
					var lnkDomain = arg3.split('//')[1].split('/')[0];
						///lnkDomain = lnkDomain.split('.')[lnkDomain.split('.').length-2];
					if (lnkDomain == 'tickets.sixflags.com') { thsDomain = 'tickets.sixflags.com'; } // exception
						lnkPath   = arg3.split('sixflags.com/')[1];
					if (lnkDomain == 'sixflags') {
						arg3 = thsProtoc + '//' + thsDomain + '/' + lnkPath;
					}
				}
				document.location.href = arg3;
			}
		}
*/


	// FLASH LINKS
		function goLink(arg1, arg2, arg3) {
		//alert('test');
			if (arguments.length == 2) {
				
			}
			if (arguments.length == 3) {
				document.location.href = arg3;
			}
			
			//alert(arg3);
			
		}


	// PROMO CODE
		function processPromo(promoSite, promoCode)	{
			var fullUrl = promoSite + "&promo_code=" + promoCode;
				if (fullUrl.indexOf('//') != -1) {
					var thsDomain = document.location.href.split('//')[1].split('/')[0];
					var thsProtoc = document.location.href.split('//')[0];
					var lnkDomain = fullUrl.split('//')[1].split('/')[0];
						lnkDomain = lnkDomain.split('.')[lnkDomain.split('.').length-2];
						lnkPath   = fullUrl.split('sixflags.com/')[1];
					if (lnkDomain == 'sixflags') {
						fullUrl = thsProtoc + '//' + thsDomain + '/' + lnkPath;
					}
				}
			window.open(fullUrl,'ecom').focus();
		}
	// PRINT FUNCTIONS
	function PageQuery(q) {
		this.queryString = (q.indexOf("?") == 0 ? q.substring(1, q.length) : q);
		this.nameValuePairs = this.queryString.split("&");
		this.getValue = function(s) {
			for (var i=0; i<this.nameValuePairs.length; i++) {
				if (this.nameValuePairs[i].split("=")[0] == s) {
					return this.nameValuePairs[i].split("=")[1];
				}
			}
			return "";
		}
	}


	function sendFriend() {
	    var url = escape(location.href);
		var title = document.title;
		window.open('/global/asp/sendfriend/sendfriend.asp?url=' + url + "&parkname=" + parkname + "&title=" + title,'sendfriend','height=500,width=375,resizable=0,scrollbars=0,location=0,toolbar=0,status=0,left=100,top=100,screenX=100,screenY=100').focus;
	}

	var qs = (location.search) ? new PageQuery(location.search) : new PageQuery('');


	var nationalFlashDiv = false;
	var nationalFlashMov = false;


	function nationalFlash() {
		var pageQuery  = new queryHandler(document.location.href);
	// set default flashvars
		var flashQuery = new queryHandler('\
?bg_xml=%2Fglobal%2Fasp%2Fcode%2Fhomepageheroxml.aspx%3Fpage%3D%7Cglobal%7Cxml%7CactivatePromo%7Cnational%7CHomepageHero.xml\
&promo_xml=%2Fglobal%2Fasp%2Fcode%2Fhomepagerightpromo.aspx%3Fparkname%3Dnational\
&ticker_xml=%2Fglobal%2Fasp%2Fcode%2Fticker.aspx%3Fparkname%3Dnational');
	// override flashvars with any supplied values
		if (pageQuery.bg_xml)     { flashQuery.bg_xml     = pageQuery.bg_xml;     }
		if (pageQuery.promo_xml)  { flashQuery.promo_xml  = pageQuery.promo_xml;  }
		if (pageQuery.ticker_xml) { flashQuery.ticker_xml = pageQuery.ticker_xml; }
	// construct screwy qs for flash
		var flashVars = 'bg_xml=' + unescape(flashQuery.bg_xml) + '&promo_xml=' + unescape(flashQuery.promo_xml) + '&ticker_xml=' + unescape(flashQuery.ticker_xml);
	// make and set
		nationalFlashDiv = document.getElementById('flash-home');
		nationalFlashMov = swf.movie('/global/assets/swf/sixflags_national.swf', 965, 377, 8, '/noflash.html');
		nationalFlashMov.setParam('wmode', 'opaque');
		nationalFlashMov.setParam('flashvars', flashVars);
		nationalFlashMov = nationalFlashDiv.appendChild(nationalFlashMov);
	}

	function updateNationalSwf(varValue) {
		if (nationalFlashDiv && nationalFlashDiv) {
			nationalFlashMov.setVar('a.bgxml_', varValue);
		}
	}


	// RETURNS CURRENT MOUSE POSITION IN VIEWPORT
		function mouseCoords() {
		// globals
			var root = this;
		// gets the coords
			root.get = function(e) {
			// get coords
				root.X = (client.engine != 'msie') ? e.pageX : event.clientX;
				root.Y = (client.engine != 'msie') ? e.pageY : event.clientY;
			// limit coords to sensible values
				if (root.X < 0){ root.X = 0; }
				if (root.Y < 0){ root.Y = 0; }
				return [root.X, root.Y]
			}
		}



			// real offset in pixels from one object to another (parent) of it.
				function getObjOffset(thisObj, stopAt) {
					stopAt = (stopAt) ? stopAt : document.getElementsByTagName('body')[0];
					var parentNode  = thisObj;
					var offsets = [0,0];
					while (parentNode != stopAt) {
							offsets[0] += parentNode.offsetLeft;
							offsets[1] += parentNode.offsetTop;
							parentNode  = parentNode.parentNode;
					}
					return offsets;
				}



	// INITIALIZE
		var mouse = new mouseCoords();
			document.onmousemove = function (event) { window.mouseX = mouse.get(event)[0]; window.mouseY = mouse.get(event)[1]; }



