//////////////////////////////////////////////
//chrome and footer Start
var chromeColor = "#1b1b1b";
var chromeWidth = 797;
var legalFooterColor = "#FFFFFF";
//chrome and footer End
//////////////////////////////////////////////

///////////////////////////////////////////
var globalMediaRoot = "http://adisneyworldsports.disney.go.com/media/dwws_v0222/en_US/";

// WDPRO  Start
WDPRO_LOADER.require("dom"); 
WDPRO_LOADER.require("event"); 

//hide elements that are supposed to be hidden when js is allowed
WDPRO_LOADER.addCallback( 
	function() {
		var $D = YAHOO.util.Dom; 
		
		$D.replaceClass($D.getElementsByClassName('hiddenByJS', '', 'core'),
			'hiddenByJS', 'hide');
	}//end function
); // End WDPRO_LOADER.addCallback 


//audio SWFObject
WDPRO_LOADER.addCallback( 
	function() {
		var $D = YAHOO.util.Dom; 
		
		//call audio flash only if main flash exist
		if ( !$D.inDocument('mainMedia') ) return;
		if ( $D.get('mainMedia').nodeName.toLowerCase()  != 'object' ) return;
		var afos = $D.getElementsByClassName('audioFO');
		if ( !afos || afos.length == 0 ) return;

		//create this element
		//	<span id="audioFO">
		//		<a href="http://www.adobe.com/go/getflashplayer">
		//			<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
		//		</a>
		//	</span>
		if ( !$D.inDocument('audioFO') ) {
			var img = document.createElement('img');
			img.src = 'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif';
			img.alt = 'Get Adobe Flash player';
			var a = document.createElement('a');
			a.href = 'http://www.adobe.com/go/getflashplayer';
			a.appendChild(img);
			var span = document.createElement('span');
			span.id = 'audioFO';
			span.appendChild(a);
			afos[0].appendChild(span);
		}//end if
		
		var flashvars = {};
		var params = {quality:"high", menu:"false", allowScriptAccess:"always", wmode:"transparent"};
		var attributes = {};
		swfobject.embedSWF(globalMediaRoot + "media/_global/audio.swf", "audioFO", "78", "21", "9.0.0", false, flashvars, params, attributes);
	}//end function
); // End WDPRO_LOADER.addCallback 


//carousel
WDPRO_LOADER.addCallback( 
	function() {
		var $D = YAHOO.util.Dom; 
		
		//call audio flash only if main flash exist
		if ( !$D.inDocument('carousel') ) return;
		if ( $D.get('carousel').nodeName.toLowerCase()  != 'object' ) return;
		
		$D.setStyle($D.getElementsByClassName('mainMedia'), 'marginBottom', '0');
	}//end function
); // End WDPRO_LOADER.addCallback 


//menu
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		var nav1s = $D.getElementsByClassName('nav1', '', 'menu');
		var nav1as = $D.getElementsByClassName('tab', '', 'menu');

		//subnav on/off
		toggleSubnav = function(e, state)  {
			var li; // .nav1
			//this is either .tab  or the li which contains .tab and .subnavMenu 
			switch (this.nodeName.toLowerCase()) {
				case 'li' :
					li = this;
					break;
				case 'a' :
					li = $D.getAncestorByTagName(this, 'li');
					break;
			}// end switch

			var subnavMenu = $D.getElementsByClassName('subnavMenu', '', li);

			switch (state) {
				case 'over' :
					//turn current on, turn others off
					$D.batch(nav1s,
						function(ll) {
							var subnav = $D.getElementsByClassName('subnavMenu', '', ll);
							if (ll == li) $D.setStyle(subnav, 'left', '0');  //subnav on
							else $D.setStyle(subnav, 'left', '-10000px');  //subnav off
						}
					);//end batch
					break;
				case 'out' :
					$D.setStyle(subnavMenu, 'left', '-10000px');  //subnav off
					break;
			}//end switch (state)
		}//end toggleSubnav

		//tab on/off
		toggleTab = function(e, state)  {
			var tab; //.tab
			//this is either .tab  or the li which contains .tab and .subnavMenu 
			switch (this.nodeName.toLowerCase()) {
				case 'li' :
					tab = $D.getElementsByClassName('tab', '', this)[0];
					break;
				case 'a' :
					tab = this;
					break;
			}// end switch

			//tab roll over/out
			switch (state) {
				case 'over' :
					//turn current on, turn others off
					$D.batch(nav1as,
						function(t) {
							var img = t.getElementsByTagName('img')[0];
							if (t == tab) img.src = img.src.replace('/off/', '/on/'); //tab image on
							else if (!$D.hasClass(t, 'on')) img.src = img.src.replace('/on/', '/off/');   // if not default on, tab image off
						}
					);//end batch
					break;
				case 'out' :
					if ( !$D.hasClass(tab, 'on') ) {  // if not default on
						var img = tab.getElementsByTagName('img')[0];
						img.src = img.src.replace('/on/', '/off/'); //tab image off
					}
					break;
			}//end switch (state)
		}//end toggleSubnav

		//thumbnail on/off
		toggleThumbImage = function(e, state) {
			var li; // .nav2Item
			//this is either an anchor  or the li which contains it
			switch (this.nodeName.toLowerCase()) {
				case 'li' :
					li = this;
					break;
				case 'a' :
					li = $D.getAncestorByTagName(this, 'li');
					break;
			}// end switch
			
			if ($D.hasClass(li, 'on')) return;  //don't toggle default image
			
			var thumb = $D.getElementsByClassName('pic', '', li);
			switch (state) {
				case 'over' :
					$D.setStyle(thumb, 'display', 'block');
					break;
				case 'out' :
					$D.setStyle(thumb, 'display', 'none');
					break;
			}//end switch (state)
		}

		$D.batch($D.getElementsByClassName('nav1', '', 'menu'),
			function(li) { // .nav1
				var tab = $D.getElementsByClassName('tab', '', li)[0];  // .tab
				
				$E.on(li, 'mouseover', toggleSubnav, 'over');
				$E.on(li, 'mouseout',  toggleSubnav, 'out');
				
				$E.on(li, 'mouseover', toggleTab, 'over');
				$E.on(li, 'mouseout',  toggleTab, 'out');
				
				$E.on(tab, 'focus', toggleSubnav, 'over');
				$E.on(tab, 'blur',  toggleSubnav, 'out');
				
				$E.on(tab, 'focus', toggleTab, 'over');
				$E.on(tab, 'blur',  toggleTab, 'out');
				

				$D.batch($D.getElementsByClassName('nav2Item', '', li),
					function(li2) {  // .nav2Item
						var a = li2.getElementsByTagName('a')[0];
						//on events, toggle subnav in the context of tab, that is, the 'this' in toggleSubnav is tab
						$E.on(a, 'focus', function() {toggleSubnav.call(li, null, 'over')});
						$E.on(a, 'blur',  function() {toggleSubnav.call(li, null, 'out')});
						
						$E.on(a, 'focus', function() {toggleTab.call(li, null, 'over')});
						$E.on(a, 'blur',  function() {toggleTab.call(li, null, 'out')});
						
						//toggle thumbnails
						$E.on(li2, 'mouseover', toggleThumbImage, 'over');
						$E.on(li2, 'mouseout',  toggleThumbImage, 'out');

						$E.on(a, 'focus', toggleThumbImage, 'over');
						$E.on(a, 'blur',  toggleThumbImage, 'out');
					}
				);//end batch
			}
		);//end batch
		
	function dynIframe(id){
		mediaRoot = 'adisneyworldsports.disney.go.com/media/dwws_v0222/en_US/_global';
		if (location.protocol.indexOf("https")!= -1) {
			mediaRoot = 'secure-dwws.disney.go.com/media/dwws_v0222/en_US/_global';
		}
		var style='position:absolute;display:block;visibility:visible;z-index:1;top:0;left:0;width:0;height:0;overflow:hidden;';
		var ifstr=(YAHOO.env.ua.ie > 0)?'<iframe style="position:relative; width:100%;height:100%; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" src="'+location.protocol+'//'+mediaRoot+'/b.html" frameborder="0" scrolling="no"></iframe>':'<iframe src="'+location.protocol+'//'+location.host+'/b.html" style="position:relative; width:100%;height:100%;" frameborder="0" scrolling="no"></iframe>';
		var str='<div id="'+id+'" style="'+style+'">'+ifstr+'</div>';
		return (str);
	}

	//generate iframe for IE6
	function genIframe(id){
	    var e = document.getElementById(id);
	    if(!e) return;
		e.innerHTML=dynIframe('ifr_'+id)+e.innerHTML;
		var ifr=e.getElementsByTagName('iframe')[0];
		if(ifr){ ifr.onfocus=null; }
	}

	function showIFrame(tab){
		iframe = document.getElementById('ifr_iframePlaceHolder');
		el = $D.getElementsByClassName('subnavMenu', '', tab)[0];
		iframe.style.top = $D.getY(el) + "px";
		iframe.style.left = $D.getX(tab) + "px";
		iframe.style.width = el.offsetWidth+"px";
		iframe.style.height = el.offsetHeight+"px";
	}

	function hideIFrame(){
		iframe = document.getElementById('ifr_iframePlaceHolder');
		iframe.style.top = 0;
		iframe.style.left = 0;
		iframe.style.width = 0;
		iframe.style.height = 0;
	}

	//IE 6 or before
	if(YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie<=6){
	    var d = document.createElement('div');
		d.id = 'iframePlaceHolder';
		$D.insertBefore(d, $D.getFirstChild('menu'));
		genIframe("iframePlaceHolder");
    	$D.getElementsByClassName('nav1', '', 'menu', 
			function (n1) {
				n1.onmouseover = function(){ showIFrame(n1); };
				n1.onmouseout = function(){ hideIFrame(); };
			}
		);
	}
	
	
	
	}//end function
); // End WDPRO_LOADER.addCallback 

  
//chrome fix
//clip vertical and horizontal borders
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		var chrome = $D.get('chrome');
		if (!chrome) return;
		var tds = chrome.getElementsByTagName('td');
		if (!tds || tds.length == 0) return;
		//use my style to avoid vertical borders
		$D.addClass(tds[0], 'cellFirst');
		$D.addClass(tds[tds.length-1], 'cellLast');
	}//end function
); // End WDPRO_LOADER.addCallback 


//popup 
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 

		// chnage HTML target new windows to js popup
		$D.batch($D.getElementsByClassName('popupLink'),
			function (a) {
				var width = 600;
				var height = 700;
				var left = Math.round(0.5 * (window.screen.width - width));
				var top = Math.round(0.5 * (window.screen.height - height)) - 40; //40: for browser's menus
				
				var windowAttributes='width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=yes,location=no';
				popfun=function(){window.open(this.href,'disneySportsPopup',windowAttributes);return false;};
				a.onclick=popfun;
			}
		);//end batch
		
		//add close button to popup pages
		$D.batch($D.getElementsByClassName('popupClose'),
			function (div) {
				div.innerHTML = '<a href="#." onclick="window.close(); return false;">Close<img src="' + globalMediaRoot + 'images/_global/popupClose.gif" alt=""/></a>';
			}
		)//end batch
	}//end function
); // End WDPRO_LOADER.addCallback 


//print page 
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom;

		if (window.location.search.match('print=Y') != null) {
			var oLink = document.createElement("link");
			oLink.href = globalMediaRoot + "styles/printCoreContent.css";
			oLink.type = 'text/css';
			oLink.rel = 'stylesheet';
			document.getElementsByTagName("head")[0].appendChild(oLink);

			var oLink2 = document.createElement("link");
			oLink2.href = globalMediaRoot + "styles/print.css";
			oLink2.type = 'text/css';
			oLink2.rel = 'stylesheet';
			document.getElementsByTagName("head")[0].appendChild(oLink2);
			
			window.print();
		}//end if


		var pp = $D.get('printPage');
		if (pp == null) return;
		
		var a = document.createElement('a');
		a.appendChild(document.createTextNode('Print Page'));
		a.href = '#.';
		
		var loc = window.location;
		var connector = (loc.search == '') ? '?' : '&';
		var loc = loc + connector + 'print=Y';

		var width = 840;
		var height = 800;
		var left = Math.round(0.5 * (window.screen.width - width));
		var top = Math.round(0.5 * (window.screen.height - height)) - 40; //40: for browser's menus
		var windowAttributes='width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=yes,location=no';
		//var windowAttributes='width=840,height=800,left=0,top=0,scrollbars=yes,location=no';
		popfun=function(){window.open(loc,'disneySportsPopup',windowAttributes);return false;};
		a.onclick=popfun;
		pp.appendChild(a);
	}//end function
); // End WDPRO_LOADER.addCallback 



//text field hint text events
WDPRO_LOADER.addCallback( 
	function() { 
		////////////// config start
		//
		//an array of ids of textboxes which needs focus/blur on/off of hint input
		var textBoxIds = ['searchText', 'signUpEmail', 'birthdayYear'];
		//
		////////////// config end

		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		//initiation
		$D.batch(textBoxIds,
			function(bxId) {
				var textboxEl = $D.get(bxId);  //text box element
				if (!textboxEl) return;
				textboxEl.setAttribute('initValue', textboxEl.value);
				$E.on(textboxEl, 'focus', 
					function() {
						if (this.initValue == null) this.initValue = this.value;	//init value
						if (this.value == this.initValue) this.value = '';
					}				
				);
				$E.on(textboxEl, 'blur', 
					function () {
						if ( (this.value == '') && (this.initValue != null) ) this.value = this.initValue;
					}
				);
			}
		);//end batch
		
	}//end function
); // End WDPRO_LOADER.addCallback 


//init horizontal scroll
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		var w = $D.getViewportWidth();
		var menu = $D.get('menu');
		if (!menu) return;
		var scrollX = 0;
		if(w<1000) scrollX = $D.getX(menu);	//scroll X to align window's left with logo's left
		window.scroll(scrollX, 0);
	}//end function
); // End WDPRO_LOADER.addCallback 


///////////////////////////////////////////////////////////////////////////////
//page specific Start

//promo rotate
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 

		makeRotateButton = function() {
			var btnContainer = document.getElementById('promoRotateContainer');
			var btn = document.createElement('img');
			btn.id = 'promoRotate';
			btn.alt = '';
			btn.src = globalMediaRoot + "images/_global/promoRotate.jpg";
			$E.on(btn, 'click', rotatePromo);
			btnContainer.appendChild(btn);
		}

		rotatePromo = function() {
			var list = document.getElementById('promoBanners');
			var banners = list.getElementsByTagName('li');
			if(!list || !banners) return;
			var oldFirst = banners[0];
			var oldLast = banners[banners.length-1];
			//removes first item, and append it after the last item.
			list.removeChild(oldFirst);
			$D.insertAfter(oldFirst, oldLast);
		}

		$E.onAvailable('insideSports', function() {$D.addClass('promoBanners', 'oneRow');} );
		$E.onContentReady('promoRotateContainer', makeRotateButton);
		
	}//end function
); // End WDPRO_LOADER.addCallback 


//flyout
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		//returns the number of px flyout should move along Y
		// @ ps	an ordered array of paneItems
		getFlyoutTop = function(ps) {
			var dy = 0;
			var y0 = $D.getY(ps[2]);
			if ( ps[1] == null ) { //first item
				dy = -1;  //dy = height of current items
			} else 	if ( ps[3] == null ) { //last item
				if ( ps[0] == null ) { // when there are fewer than 3 items, this is the second item in a list of two.
					dy = $D.getY(ps[1]) - y0 - 1;  //dy = height of current and prev items  1px for the border
				} else {
					dy = $D.getY(ps[0]) - y0 - 1;  //dy = height of current, prev and prev prev items  1px for the border
				}
			} else {  //item in the middle
				dy = $D.getY(ps[1]) - y0 - 1;  //dy = height of current and prev items.  2px for the border
			}
			return dy;
		}

		//returns the calculated height of flyout
		// @ ps	an ordered array of paneItems
		getFlyoutHeight = function(ps) {
			// adjustment, because flyout's bottom does not align with next paneItem with this calculated height
			var dy = -30;
			var covered = getPanesCovered(ps);  //some items are null when there are fewer than 3 items
			var first = covered[0];
			var last = covered[2];
			//when there are fewer than 3 items, don't calculate height and let flyout use height defined in css
			if ( (first == null) || (last == null) ) return 0;
			else { 
				//css height = real height - top and bottom paddings
				return (
					Math.floor($D.getRegion(last).bottom - $D.getRegion(first).top)
					+ dy
				);
			}
		}

		//returns an element and its 2-order siblings on both sides
		// @ p	an element
		get2OrderSiblings = function(el) {
			var sibs = [null, null, el, null, null];
			//sibs is an ordered Array of elements which are siblings.
			//sibs =  << < me > >>
			//sibs[n], where n=
			//0  previous previous item  <<
			//1  previous item  <
			//2  this item = me
			//3  next item  >
			//4  next next item  >>
			sibs[2] = el;
			sibs[1] = $D.getPreviousSibling(el);
			sibs[0] = $D.getPreviousSibling(sibs[1]);
			sibs[3] = $D.getNextSibling(el);
			sibs[4] = $D.getNextSibling(sibs[3]);
			return sibs;
		}

		//returns the panes covered by flyout
		// @ ps	an ordered array of paneItems
		getPanesCovered = function(ps) {
			//ps =  << < me > >>
			if ( ps[1] == null ) { return [ps[2], ps[3], ps[4]]; } //first item.  x x me 3 4
			else if ( ps[3] == null ) { return [ps[0], ps[1], ps[2]]; }  // last item.  0 1 me x x
			else { return [ps[1], ps[2], ps[3]]; } //item in the middle.  # 1 me 3 #
		}

		//callback on events on paneItem
		togglePane = function(e, state)  {
			var p = this;  // a paneItem
			var nextSib = $D.getNextSibling(p);
			switch(state) {
				case 'on':
					$D.addClass(p, 'on');
					$D.addClass(nextSib, 'noBorderTop');  //no need to check if nextSib exists
					break;
				case 'off':
					$D.removeClass(p, 'on');
					$D.removeClass(nextSib, 'noBorderTop');
					break;
			}
		}

		//initially hide flyouts
		$D.batch($D.getElementsByClassName('flyoutInit', '', 'core'),
			function(f) {//a flyout
				$D.replaceClass(f, 'flyoutInit', 'flyout');
			}//end function(f)
		);//end batch

		$D.batch($D.getElementsByClassName('flyout', '', 'core'),
			function(f) {//a flyout
				var pane = $D.getAncestorByClassName(f, 'paneItem');
				var sibs = get2OrderSiblings(pane);
				var summary = $D.getElementsByClassName('summary', '', pane)[0];
				//move flyout's y-position
				//this must be run before tab pane intiation; otherwise no top positioni in hidden panes can be found.
				$D.setStyle(f, 'top', getFlyoutTop(sibs) + 'px');
				
				var h = getFlyoutHeight(sibs);
				//if (h != 0) $D.setStyle(f, 'height', h + 'px');

				// if last item, some adjustments of height for it's flyout
				if (pane == getPanesCovered(sibs)[2]) $D.addClass(f, 'flyoutLast');
				
				$E.on(pane, 'mouseover', togglePane, 'on');
				$E.on(pane, 'focus', togglePane, 'on');
				$E.on(pane, 'mouseout', togglePane, 'off');
				$E.on(pane, 'blur', togglePane, 'off');
			}//end function(f)
		);//end batch

	}//end function
); // End WDPRO_LOADER.addCallback 



//tab pane
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 

		switchTab = function() {
			//switch tabs on/off 
			var a = this;
			
			//do not switch tab if current tab is triggered.  Return false to void change of URL
			if ( $D.hasClass($D.getAncestorByTagName(a, 'li'), 'on') ) return false;
			
			$D.batch(tabs,  //this works on extra things when more than one .tabPaneSmall is in .core
				function(t) {  //a tab
					//if this tab has className tab1 or tab2
					if (t.className.match(a.className.match(/tab\d+/)[0])) $D.removeClass(t, 'hide');  //show it
					else $D.addClass(t, 'hide');  //hide it
				}
			);//end batch
			
			//switch bkgd image under tab labels, which has a shadow to match tab labels' on/off states
			var tabBkgdCtnr = $D.getAncestorByClassName(a, 'tabPaneAllInner');  //tabBkgdCtnr = tag background container
			if ($D.hasClass(tabBkgdCtnr, 'tab2On')) $D.removeClass(tabBkgdCtnr, 'tab2On');
			else $D.addClass(tabBkgdCtnr, 'tab2On');
			
			//switch tab label font color
			var list = $D.getAncestorByTagName(a, 'ul');
			$D.batch($D.getChildren(list),  //all tabs (siblings) of this tab
				function(li) {//an <li> element
					if ($D.hasClass(li, 'on')) $D.removeClass(li, 'on');
					else $D.addClass(li, 'on');
				}
			);//end batch
			
			return false;  //avoid change of URL.  IE needs this
		}//end switchTab

		//activate tab pane border and tab labels
		$D.replaceClass($D.getElementsByClassName('tabPaneSmallNoJS', '', 'core'),
			'tabPaneSmallNoJS', 'tabPaneSmall');
		
		$D.replaceClass($D.getElementsByClassName('tabOneNoJS', '', 'core'),
			'tabOneNoJS', 'tabOne');

		//get all tab elements once and for all
		var tabs = $D.getElementsByClassName('tab', '', 'core'); 

		//init tabs
		$D.batch(tabs,
			function(t) {//a tab
				if (!$D.hasClass(t, 'on'))  $D.addClass(t, 'hide');	//hide all tabs except current one
			}
		);

		//work on anchors in tab labels
		$D.batch($D.getElementsByClassName('tabLabelList', '', 'core'),
			function(list) {//a list of tab labels
				$D.batch(list.getElementsByTagName('a'),
					function(a) { //an anchor in a tab label
						a.setAttribute('onclick', 'return false');  //avoid change of URL.  Firefox needs this
						$E.on(a, 'click', switchTab);
					}
				);//end batch
			}
		);//end batch
		
	}//end function
); // End WDPRO_LOADER.addCallback 


//event expand list
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		var exps = $D.getElementsByClassName('expandList', '', 'core');
		if (!exps || exps.length == 0) return;
		
		$D.batch(exps,
			function(p) {
				expandItemOn = function() {
					var li; // .nav1
					//this is either an anchor or the li which contains the anchor
					switch (this.nodeName.toLowerCase()) {
						case 'li' :
							li = this;
							break;
						case 'a' :
							li = $D.getAncestorByClassName(this, 'vevent');
							break;
					}// end switch		
				
					$D.batch(eItems, 
						function(ei) {
							var ds = $D.getElementsByClassName('details', '', ei);	//all detail panes
							if (ei == li) {	//show the item being triggered
								$D.addClass(ei, 'on');
								$D.removeClass(ds, 'outOfSight');
							}				
							else {	//hide all others
								$D.removeClass(ei, 'on'); 
								$D.addClass(ds, 'outOfSight');
							}
						}
					);
				}//end expandItemOn


				var eItems = $D.getElementsByClassName('vevent', '', p); //all items under expandList

				$D.batch(eItems,
					function(ei) {
						//init hide details
						$D.addClass($D.getElementsByClassName('details', '', ei), 'outOfSight');

						//add events to each  expand item
						if ( $D.hasClass(p, 'expandOnClick') ) {
							$E.on(eItems, 'click', expandItemOn);
						} else {
							$E.on(eItems, 'mouseover', expandItemOn);
						}//end if
						$E.on(ei.getElementsByTagName('a'), 'focus', expandItemOn);
					}
				);

				
				var exps = $D.getElementsByClassName('expandAll', '', 'core');
				var cols = $D.getElementsByClassName('collapseAll', '', 'core');
				var ds = $D.getElementsByClassName('details', '', 'core');
				
				$D.batch(exps.concat(cols),
					function(i) {
						i.setAttribute('onclick', 'return false');  //avoid change of URL.  Firefox needs this
					}
				);

				$E.on(exps, 'click', 
					function() {
						//expand all eItems
						$D.addClass(eItems, 'on');
						$D.removeClass(ds, 'outOfSight');
						
						/*
						//remove listeners on eIteme
						$D.batch(eItems,
							function(ei) {
								$D.batch($E.getListeners(ei),
									function(listener) {
										$E.removeListener(ei, listener.type, listener.fn)
									}
								);//end batch
								
								$D.batch(ei.getElementsByTagName('a'),
									function(a) {
										$D.batch($E.getListeners(a),
											function(listener) {
												$E.removeListener(a, listener.type, listener.fn)
											}
										);//end batch
									}
								);//end batch
							}
						);//end batch
						*/
						
						$D.addClass(exps, 'outOfSight');  //hide 
						$D.removeClass(cols, 'outOfSight');  //show

						return false;  //avoid change of URL.  IE needs this
					}
				);//end $E.on

				//collapse all
				$E.on(cols, 'click', 
					function() {
						//collapse all eItems
						$D.removeClass(eItems, 'on');
						$D.addClass(ds, 'outOfSight');
						
						$D.removeClass(exps, 'outOfSight');  //hide
						$D.addClass(cols, 'outOfSight');  //show

						return false;  //avoid change of URL.  IE needs this
					}
				);//end $E.on
			}
		)// end $D.batch(exps,
		}//end function
); // End WDPRO_LOADER.addCallback 


//scroll pane
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		if ($D.get('scrollPaneSet') == null) return;

		var loader = new YAHOO.util.YUILoader({  
	        require: ['slider'], // what components?  
	        onSuccess: function() { makeSlider(); }
	    });  
	 
	    // Calculate the dependency and insert the required scripts and css resources into the document  
		loader.insert();
		
        var makeSlider = function () {
			var slider;

		    // The slider can move 0 pixels up
		    var topConstraint = 0;

		    // The slider can move 114 pixels down
		    var bottomConstraint = 114;

		    // The amount the slider moves when the value is changed with the arrow keys
		    var keyIncrement = 20;

			//remove browser's scroll bar
			$D.addClass('scrollPaneSet', 'trans'); /* add temporary class to parent for IE6 */
			setTimeout(function () { $D.addClass('scrollPaneClip', 'active'); $D.removeClass('scrollPaneSet', 'trans'); }, 0);

			//this must run after //remove browser's scroll bar, or the region got is wrong
			var r = $D.getRegion('scrollPane');
			var s = $D.getRegion('scrollPaneClip');
			// Custom scale factor for converting the pixel offset into a real value
			var scaleFactor = ((r.bottom - r.top) - (s.bottom - s.top)) / (bottomConstraint - topConstraint);
			
			//if area is long enough for content, no need to scroll
			if (scaleFactor < 0) {
				return;
			}
			

			// write customed slider bar Start
			//
			//
			//
			//	write this out
			//	<div id="sliderBkgd">
			//	    <div id="sliderThumb"><img src="../media/events/sliderThumb.gif"  /></div>
			//	</div>
			var  thumbImg = document.createElement('img');
			thumbImg.setAttribute('src', globalMediaRoot + "media/events/sliderThumb.gif");
			
			var  sliderThumb = document.createElement('div');
			sliderThumb.setAttribute('id', 'sliderThumb');
			sliderThumb.appendChild(thumbImg);
			
			var  sliderBkgd = document.createElement('div');
			sliderBkgd.setAttribute('id', 'sliderBkgd');
			sliderBkgd.appendChild(sliderThumb);
			
			$D.insertAfter(sliderBkgd, 'scrollPaneClip');
			//
			//
			// write customed slider bar End


			//init slider
			slider = YAHOO.widget.Slider.getVertSlider(sliderBkgd, 
							 sliderThumb, topConstraint, bottomConstraint);

			slider.getRealValue = function() {
				return Math.round(this.getValue() * scaleFactor);
			}

			slider.subscribe("change", function(offsetFromStart) {
				// scroll it
				$D.get('scrollPaneClip').scrollTop = slider.getRealValue();
			});
		}//end function
		
	}//end function
); // End WDPRO_LOADER.addCallback 


//event overview page switch
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		pipSwitchPage = function(pageId) {
			for (var i=0; i<pips.length; i++) {
				if (pips[i].id==pageId) {  //show the current page
					$D.removeClass(pips[i], 'hide');
				} else {  //hide all others
					$D.addClass(pips[i], 'hide');
				}
			}
			return false;  //avoid change of URL.  IE needs this
		}//end pipSwitchPage
		
		//this function is needed only when links on menu left does not go to another page
		toogleAnchor = function() {
			var currentA = this;
			$D.batch(as,
				function(a) {
					if (a == currentA) $D.addClass(a, 'on');
					else $D.removeClass(a, 'on');
				}
			);
		}//end toogleMenuLeft		
		
		toogleSubMenu = function() {
			var currentA = this;
			var subms = $D.getElementsByClassName('menuLeftSubmenu', '', currentA.parentNode);
			var mySubm = (subms == null) ? null : subms[0];
			$D.batch($D.getElementsByClassName('menuLeftSubmenu', '', ml),
				function (m) {
					if ($D.isAncestor(m, currentA)) {  //a is in submenu
						$D.removeClass(m, 'hide'); //show it
					} else if ( (m == mySubm) && $D.hasClass(m, 'hide') ) {  //a has submenu
						$D.removeClass(m, 'hide'); //show it
					} else {
						$D.addClass(m, 'hide'); //hide it
					}
				}
			);//end batch			
		}//end toogleSubMenu

		var setBannerLeftTop = function () {
			var dy = $D.getRegion('menuLeft').bottom - 406;  // gives a margin of 17px between menuLeft and bannersLeft
			$D.setStyle('bannersLeft', 'marginTop', Math.max(dy, 0) + 'px');
		}
		
		var pips = $D.getElementsByClassName('pageInPage', '', 'core');
		if ( (pips == null) || (0 == pips.length) ) return;
		
		var ml = $D.get('menuLeftList');
		if (ml == null) return;
		var as = ml.getElementsByTagName('a');

		/*
		//init pip pages, hide all but one
		for (var i=0; i<pips.length; i++) {
			//if left menu item has class 'on', hide the corresponding pageInPage.
			if ( !$D.hasClass(as[i], 'on') ) $D.addClass(pips[i], 'hide');
			
			/*
			//hide the pageInPage which initially has class 'on'
			$D.removeClass(pips[i], 'on');
			$D.addClass(pips[i], 'hide');
			
			
			//if left menu item has class 'on', unhide the corresponding pageInPage.
			if ( $D.hasClass(as[i], 'on') ) {
				$D.removeClass(pips[i], 'hide');
				$D.addClass(pips[i], 'on');
			}
			*
		}*/
			
		
		//remove #menuLeft's hieght restriction
		$D.removeClass('menuLeft', 'init')

		//init submenus on .menuLeft, fold them
		$D.batch($D.getElementsByClassName('menuLeftSubmenu', '', ml),
			function (m) {
				//if current menu item is not in submenu, hide it
				if (0 == $D.getElementsByClassName('on', '', m).length) $D.addClass(m, 'hide');
			}
		);//end batch
		
		setBannerLeftTop();
		
		//init links on #menuLeft
		for (var i=0; i<as.length; i++) {
			as[i].setAttribute('onclick', 'return false');  //avoid change of URL.  Firefox needs this
		}
		
		//init links on #menuLeft
		$E.on(as, 'click', 
			function () {
				var pageId = this.getAttribute('href');
				pageId = pageId.substring(pageId.indexOf('#') + 1);
				pipSwitchPage(pageId);
				toogleAnchor.call(this);
				toogleSubMenu.call(this);
				setBannerLeftTop();
				return false;  //avoid change of URL.  IE needs this
			}
		);//end $E.on

	}//end function
); // End WDPRO_LOADER.addCallback 


//form initiation
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		//registraion 2  = template 0.6B
		var showDivisionByCountrySelected = function(isUS) {
			if (isUS) {
				//show US, hide other
				$D.removeClass('divisionUS', 'hide');
				$D.addClass('divisionOther', 'hide');
			} else {
				//hide US, show other
				$D.addClass('divisionUS', 'hide');
				$D.removeClass('divisionOther', 'hide');
			}
		}//end showDivisionByCountrySelected
		
		var c = $D.get('country');  //country select box
		if (c == null) return;
		if( !$D.isAncestor('formRegis2', c) ) return;

		/*
		*	temporarily disabled
		*
		$E.on(c, 'change', 
			function() {
				switch(this.value) {
					case ('') : 
						break;
					case ('US') : 
						showDivisionByCountrySelected(true);
						break;
					default : 
						showDivisionByCountrySelected(false);
						break;
				}
			}
		);//end $E.on
		*/

	}//end function
); // End WDPRO_LOADER.addCallback 


//form validation
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		
		$D.batch($D.getElementsByClassName('validate', 'form', 'core'),
			function(f) { //a form which needs validation
				var validFunc;
				switch(f.id) {
					case ('formContactUs') :  // contact us
						validFunc = validateformContactUs;
						break;
					case ('formCredentials') :
						validFunc = validateformCredentials;
						break;
					case ('formSearch') :  // search bar in search results
						validFunc = validateformSearch;
						break;
					case ('formRegis1') :
						validFunc = validateformRegis1;
						break;
					case ('formRegis2') :
						validFunc = validateformRegis2;
						break;
					case ('formRegis2Less13') :
						validFunc = validateformRegis2Less13;
						break;
					case ('formUpdateLess13') :
						validFunc = validateformUpdateLess13;
						break;
					case ('formLogin') :
						validFunc = validateformLogin;
						break;
					case ('formForgotPassword') :
						validFunc = validateformForgotPassword;
						break;
					case ('formUploadPhotos') :
						validFunc = validateformUploadPhotos;
						break;
					case ('formGateSubmissions') :
						validFunc = validateformGateSubmissions;
						break;
				}//end switch
				f.onsubmit = function() {return validFunc.call(f);}
			}
		);//end batch
	}//end function
); // End WDPRO_LOADER.addCallback 


//calendar
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		if ($D.get('showCal') == null) return;
		if ($D.get('cal') == null) return;

		var loader = new YAHOO.util.YUILoader({  
	        require: ['calendar', 'container'], // what components?  
	        onSuccess: function() { makeCalendar(); }
	    });
	 
	    // Calculate the dependency and insert the required scripts and css resources into the document  
		loader.insert();
		
		var makeCalendar = function () {
	        var dialog, calendar;

	        calendar = new YAHOO.widget.Calendar("cal", {
	            iframe:false,          // Turn iframe off, since container has iframe support.
	            hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
	        });

	        function okHandler() {
	            if (calendar.getSelectedDates().length > 0) {

	                var selDate = calendar.getSelectedDates()[0];

				    var year = selDate.getFullYear(),
					    month = selDate.getMonth()+1, 
					    day = selDate.getDate(); 
					if (month < 10) month = "0" + month;
					if (day < 10) day = "0" + day;

					YAHOO.util.Dom.get("dateRequested").value =  month + "/" + day + "/" + year;
	            } else {
	                YAHOO.util.Dom.get("dateRequested").value = "";
	            }
	            this.hide();
	        }
	        
	        function cancelHandler() {
	            this.hide();
	        }

	        dialog = new YAHOO.widget.Dialog("container", {
	            context:["showCal", "tl", "bl"],
	            width:"16em",  // Sam Skin dialog needs to have a width defined (7*2em + 2*1em = 16em).
	            draggable:false,
	            close:true
	        });
	        calendar.render();
	        dialog.render();

	        // Using dialog.hide() instead of visible:false is a workaround for an IE6/7 container known issue with border-collapse:collapse.
	        dialog.hide();

	        calendar.renderEvent.subscribe(function() {
	            // Tell Dialog it's contents have changed, Currently used by container for IE6/Safari2 to sync underlay size
	            dialog.fireEvent("changeContent");
	        });
			
			calendar.selectEvent.subscribe(function () {okHandler.call(dialog)}, calendar, true);

	        YAHOO.util.Event.on("showCal", "click", function() {
	            dialog.show();
	            if (YAHOO.env.ua.opera && document.documentElement) {
	                // Opera needs to force a repaint
	                document.documentElement.style += "";
	            } 
	        });
		}//end function

	}//end function
); // End WDPRO_LOADER.addCallback 


//calendarEndDate
WDPRO_LOADER.addCallback( 
	function() { 
		var $D = YAHOO.util.Dom; 
		var $E = YAHOO.util.Event; 
		
		if ($D.get('showCalEndDate') == null) return;
		if ($D.get('cal') == null) return;

		var loader = new YAHOO.util.YUILoader({  
	        require: ['calendar', 'container'], // what components?  
	        onSuccess: function() { makeCalendar(); }
	    });
	 
	    // Calculate the dependency and insert the required scripts and css resources into the document  
		loader.insert();
		
		var makeCalendar = function () {
	        var dialog, calendar;

	        calendar = new YAHOO.widget.Calendar("calEndDate", {
	            iframe:false,          // Turn iframe off, since container has iframe support.
	            hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
	        });

	        function okHandler() {
	            if (calendar.getSelectedDates().length > 0) {

	                var selDate = calendar.getSelectedDates()[0];

				    var year = selDate.getFullYear(),
					    month = selDate.getMonth()+1, 
					    day = selDate.getDate(); 
					if (month < 10) month = "0" + month;
					if (day < 10) day = "0" + day;

					YAHOO.util.Dom.get("dateRequestedEndDate").value =  month + "/" + day + "/" + year;
	            } else {
	                YAHOO.util.Dom.get("dateRequestedEndDate").value = "";
	            }
	            this.hide();
	        }
	        
	        function cancelHandler() {
	            this.hide();
	        }

	        dialog = new YAHOO.widget.Dialog("containerEndDate", {
	            context:["showCalEndDate", "tl", "bl"],
	            width:"16em",  // Sam Skin dialog needs to have a width defined (7*2em + 2*1em = 16em).
	            draggable:false,
	            close:true
	        });
	        calendar.render();
	        dialog.render();

	        // Using dialog.hide() instead of visible:false is a workaround for an IE6/7 container known issue with border-collapse:collapse.
	        dialog.hide();

	        calendar.renderEvent.subscribe(function() {
	            // Tell Dialog it's contents have changed, Currently used by container for IE6/Safari2 to sync underlay size
	            dialog.fireEvent("changeContent");
	        });
			
			calendar.selectEvent.subscribe(function () {okHandler.call(dialog)}, calendar, true);

	        YAHOO.util.Event.on("showCalEndDate", "click", function() {
	            dialog.show();
	            if (YAHOO.env.ua.opera && document.documentElement) {
	                // Opera needs to force a repaint
	                document.documentElement.style += "";
	            } 
	        });
		}//end function

	}//end function
); // End WDPRO_LOADER.addCallback 

//page specific End
///////////////////////////////////////////////////////////////////////////////


var montharray = new Array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );

function countdown(yr,m,d){
	theyear = yr;
	themonth = m;
	theday = d;

	var today = new Date();
	var todayy = today.getYear();
	if (todayy < 1000) {
		todayy += 1900;
	}
	var todaym = today.getMonth();
	var todayd = today.getDate();
	var todayh = today.getHours();
	var todaymin = today.getMinutes();
	var todaysec = today.getSeconds();

	if ( yr == todayy && m == todaym+1 && d  ==  todayd ){
		checkVisible( false );
	} else {
		if( yr < todayy || ( yr == todayy && m < todaym+1 ) || ( yr == todayy && m == todaym+1 && d < todayd ) ){
			checkVisible( false );
		} else {
			var todaystring = montharray[ todaym ] + ' ' + todayd + ', ' + todayy + ' ' + todayh + ':' + todaymin + ':' + todaysec;
			futurestring = montharray[ m-1 ] + ' ' + d + ', ' + yr;

			dd = Date.parse( futurestring ) - Date.parse( todaystring );
			dday = Math.floor( dd / ( 60 * 60 * 1000 * 24 )*1 );
			dhour = Math.floor( ( dd % ( 60 * 60 * 1000 * 24 ) ) / ( 60 * 60 * 1000 ) * 1 );
			dmin = Math.floor( ( ( dd % ( 60 * 60 * 1000 * 24 ) ) % ( 60 * 60 * 1000 ) ) / ( 60 * 1000 ) * 1 );
			dsec = Math.floor( ( ( ( dd % ( 60 * 60 * 1000 * 24 ) ) % ( 60 * 60 * 1000 ) ) % ( 60 * 1000 ) ) / 1000 * 1 );

			strDayPad = padding(dday);
			strHourPad = padding(dhour);
			strMinPad = padding(dmin);
			strSecPad = padding(dsec);
    		document.getElementById( 'box1' ).innerHTML = strDayPad + dday + ' : ';
	    	document.getElementById( 'box2' ).innerHTML = strHourPad + dhour + ' : ';
		    document.getElementById( 'box3' ).innerHTML = strMinPad + dmin + ' : ';
		    document.getElementById( 'box4' ).innerHTML = strSecPad + dsec;

			setTimeout( 'countdown( theyear, themonth, theday)', 1000 );
		}
	}
}
function padding(count){
    if(count < 10){
        return "0";
    }
    else{
        return "";
    }
}

function checkVisible( val ) {
	if( val ){
		document.getElementById( 'countdownModule' ).style.display  =  'inline';
	}
	else {
		document.getElementById( 'countdownModule' ).style.display  =  'none';
	}
}



