/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright (c) 2004 Walt Disney Internet Group.  All Rights Reserved.

$Workfile: global.js $
$Author: Rwong $
$Revision: 6 $
$Date: 4/26/05 11:47a $

$Revised By: DSanderson $
$Revision Date: 5/17/06 1:55P $

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
//dummy js code for missing functions - _hbPageView
var country = "hong kong";
function _hbPageView(){
	return true;
}
function includeFiles()
{
  // you can add more files if you want
  var scripts = ["http://tredir.go.com/capmon/GetDE/?set=j&param=connection&param=metrocode&param=domain&param=country"];

  var scriptElement = new Array(scripts.length);
  var headTag = document.getElementsByTagName("head")[0];
  var fragment = document.createDocumentFragment();

  for(var i=0, count = scripts.length; i < count; i++)
  {
    scriptElement[i] = document.createElement("script");
    scriptElement[i].setAttribute("src", scripts[i]);
    fragment.appendChild(scriptElement[i]);
  }

  headTag.appendChild(fragment);
}

function thisMovie(movieName) {
		    if (navigator.appName.indexOf("Microsoft") != -1) {
		        return window[movieName]
		    }
		    else {
		        return document[movieName]
		    }
		}
function addEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};


function send2flash() {
	//alert("C" + country);
	//if(getQuerystring("name") == "HomePage") { 
		thisMovie("HomePageMainMedia").ChangeBanner(country);
	//	}
	}

//addEventHandler(window, "load", send2flash);
includeFiles();

//RCMD menu hide functions
function hideRcmdMenu(){
	var $D = WDPRO.util.Dom; 
	$D.setStyle("exp","visibility","hidden");
}

function showRcmdMenu(){
	var $D = WDPRO.util.Dom; 
	$D.setStyle("exp","visibility","visible");
}

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function popup(url,name,features){
		var w;
		w=window.open(url,name,features);
		w.focus();
}

function safeOnload(funcName) {
	var winOnLoad = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = funcName;
	} else {
		window.onload = function() {
			winOnLoad();
			funcName();
		}
	}
}

function countItems (item)  {
	i = 0;
	while (this.getElements(item + i)) {
		i=i+1;
	}
	return i;
}

function getElements(itemId)  {
	if (document.getElementById) {
	    objValue = document.getElementById([itemId]);
	}
	return objValue;
}

function addEvent (objTarget, strType, objFunction)  {
	if ( objTarget.addEventListener ) {
		objTarget.addEventListener(strType, objFunction, true);
		return true;
	} else if ( objTarget.attachEvent ) {
		var bResult = objTarget.attachEvent('on' + strType, objFunction);
		return bResult;
	} else {
		return false;
	}
}

Function.prototype.bind = function(object) { 
	var __method = this; 
    return function(event) { 
    	return __method.call(object, event || window.event);
	}
}

function toggleDiv(divId){
     var div = document.getElementById(divId);
     if (div.className == null || div.className == '') {
            div.className = 'hide';
     } else {
            div.className  = '';
     }
}

/********************************************
 This is part of the workaround for the new
 Internet Explorer Flash Update
*********************************************/
function writeFlash(mediaHTML) {
	document.write(mediaHTML);

}

//////////////////////////////////////////////
//Experience Tab Control Start
collapseExpTab = function() {
	//Setting height by adding a class to the element has no effect on IE6.
	//Therefore height is declared here.
	YAHOO.util.Dom.setStyle('exp', 'height', '77px');
}

expandExpTab = function() {
	YAHOO.util.Dom.setStyle('exp', 'height', '360px');
}
//Experience Tab Control End
//////////////////////////////////////////////

//////////////////////////////////////////////
//image toggle Start
//img is an image element
imgOver = function(img) {
	img.src = img.src.replace('/off/', '/on/');
}

//img is an image element
imgOut = function(img) {
	img.src = img.src.replace('/on/', '/off/');
}

//image toggle End
//////////////////////////////////////////////


// WDPRO  Start
WDPRO_LOADER.require("wdprodom"); 
WDPRO_LOADER.require("event"); 
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = WDPRO.util.Dom; 
		var $E = YAHOO.util.Event; 
		var isIE6 = (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie <= 7);

//////////////////////////////////////////////



		// Global Nav Menus
		
		
		if (isIE6) {
			var shim = document.createElement("iframe");
			shim.src = 'javascript:false;document.write("");'; 
			$D.setStyle(shim, 'position', 'absolute');
			$D.setXY(shim, [0,0]);
			$D.setStyle(shim, 'display', 'none');
			$D.setStyle(shim, 'border', 'none');
			$D.setStyle(shim, 'padding', '0');
			$D.setStyle(shim, 'margin', '0');
		}

		var menus = $D.getElementsByClassName("globalNavMenu", "div", "globalNav");

		var menuLists = $D.getElementsByClassName("menuList", "ul", "globalNav");
		
		// Pre-load background images of menus
		var imgArray = new Array();
		if(!isIE6){
			for (i=0;i<menuLists.length;i++) {
		
				var headDiv = menuLists[i].getElementsByTagName("div")[0];
				imgArray[i] = new Image();
				var strBackgroundImage = $D.getStyle(headDiv, "backgroundImage");
				strBackgroundImage = strBackgroundImage.replace('url(','');
				strBackgroundImage = strBackgroundImage.replace(')','');
				imgArray[i].src = strBackgroundImage;
			}
			}
		

		var hideMenuLists = function() {
			$D.setStyle(menuLists, 'display', 'none');
			$D.removeClass(menus, 'active');
			if (isIE6) {
				$D.setStyle(shim, 'display', 'none');
			}
		}
		var showSubMenu = function(el) {
			//hideMenuLists();
			$D.removeClass(menus, 'active');
			$D.addClass(el, 'active');
			var lists = el.getElementsByTagName("ul");
			if (lists.length != 0) {
				var list = lists[0];
				$D.setStyle(list, 'display', 'block');
				if (isIE6) {
					$D.insertAfter(shim, list);
					$D.setStyle(shim, 'height', $D.getHeight(list));
					$D.setStyle(shim, 'width', $D.getWidth(list));
					$D.setStyle(shim, 'display', 'block');
					$D.setXY(shim, $D.getXY(list));
				}
			}
		}

		$E.addListener(
				menus
				, "mouseover"
				, function(ev) {
					var elTarget = $E.getTarget(ev); 
					if ($D.hasClass(elTarget, "globalNavMenu")) { 
						showSubMenu(elTarget);
					}
					else {
						showSubMenu($D.getAncestorByClassName(elTarget, "globalNavMenu"));
					}
				}
		);

		$E.addListener(menus, "mouseout", function() {
			//alert("hiding menu lists");
			hideMenuLists();
		});
		var isPopUpPage = getQuerystring("name").match(/\b(.*PopupPage$)\b/ig);
		if(
			getQuerystring("name") != "TermsOfUsePage" &&
			getQuerystring("name") != "ExplorerParkMapPage" &&
			getQuerystring("name") != "PrivacyPolicyPage" &&
			getQuerystring("name") != "ParkRulesPage" &&
			getQuerystring("name") != "TermsOfUsePage" &&
			getQuerystring("name") != "ContactUsPage" &&
			getQuerystring("name") != "SiteMapPage" &&
			getQuerystring("name") != "TicketExpressMapPage" &&
			!isPopUpPage &&
			getQuerystring("name") != "AnnualPassBoltLuckyDrawPopupPage" 
		)
		{
			$D.setStyle("exp","visibility","visible");
		}
		if (getQuerystring("name") == "RcmdOverviewPage" || getQuerystring("name") == "RcmdCouplesPage" || getQuerystring("name") == "RcmdFriendsPage" || getQuerystring("name") == "RcmdBigKidsPage" || getQuerystring("name") == "RcmdSmallKidsPage") {
			$D.setStyle("exp","width","160px");
		}

		//check country 
		//if (country == "hong kong" || country == "china") {
		//if (country == "united states") {
			//$D.setStyle("SummerGlobalSubNavMedia","display","none");
		//}
		//if(getQuerystring("name") == "HomePage") { 
			//thisMovie("HomePageMainMedia").ChangeBanner(country);
		//}
		
		hideMenuLists();
//////////////////////////////////////////////


//////////////////////////////////////////////
//exp expand Start

function expandRecExpDiv() {
	var strHeight = '360px';
	
	if ($D.hasClass('contentWrapper','narrow') || getQuerystring("name") == "RcmdOverviewPage" || getQuerystring("name") == "RcmdCouplesPage" || getQuerystring("name") == "RcmdFriendsPage" || getQuerystring("name") == "RcmdBigKidsPage" || getQuerystring("name") == "RcmdSmallKidsPage") {
		strHeight = '260px';
	}
	$D.setStyle("exp","height",strHeight);
}

function shrinkRecExpDiv() {
	var strHeight = '77px';
	if ($D.hasClass('contentWrapper','narrow') || getQuerystring("name") == "RcmdOverviewPage" || getQuerystring("name") == "RcmdCouplesPage" || getQuerystring("name") == "RcmdFriendsPage" || getQuerystring("name") == "RcmdBigKidsPage" || getQuerystring("name") == "RcmdSmallKidsPage") {
		strHeight = '52px';
	}
	$D.setStyle("exp","height",strHeight);
}

$E.addListener("exp","mouseover",expandRecExpDiv);
$E.addListener("exp","mouseout",shrinkRecExpDiv);

//exp expand End
//////////////////////////////////////////////

	} // WDPRO_LOADER.addCallback function() End
); 
// WDPRO  End

function openParkMap(webRoot, attname) {
		popup(webRoot + 'general/popup?name=ExplorerParkMapPage&showplace=' + attname,'parkmapwin','width=720,height=652,toolbar=no,scrollbars=no,menubar=no,status=no,location=yes,resizable=no');   	
}

function openwindow(openURL) {
	popup(openURL,'newwin','width=800,height=600,toolbar=yes,scrollbars=yes,menubar=yes,status=yes,location=yes,resizable=yes');   	
}

function changebackwin(url) {
	if (opener && !opener.closed) {
		opener.location.href = url;
		opener.focus();
	}
	else {
		popup(url,'homewin','top=0, left=0,width=800,height=600,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes');  
	}
	return;
}

// IE 6 flickering background fix
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}