
// JavaScript Document

//Define Disney YUI functions and extensions here.
//Wald Disney World User Interface Scripts

YAHOO.namespace("dsny");
YAHOO.namespace("dsny.promoCarousel");


/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'mycarousel'.) See the
 * HTML code below.
 **/

YAHOO.dsny.promoCarousel = function() {
	//constructor expects 1st argument to be the div id of the DOM element to receive the carousel
	var carouselDiv = document.getElementById("mycarousel");
		//alert(carouselDivId);
	//calculate the length of default items contained in the carousel div.
	var initialSize = (YAHOO.util.Dom.getElementsBy(function(o) {return true;},'li',carouselDiv)).length;
	var ulArray = YAHOO.util.Dom.getElementsBy(function(o) {return true;}, 'ul',carouselDiv);
	var ulWidth = initialSize*200;
	ulWidth = ulWidth + "px";
	var ulPromo = ulArray[0];
	YAHOO.util.Dom.setStyle(ulPromo, "width", ulWidth);
	this.instance = new YAHOO.extension.Carousel(carouselDiv.id, 
        {
            numVisible:        2,
            animationSpeed:    0.12,
            scrollInc:         1,
            navMargin:         60,
	    	animationCompleteHandler:  this.animComplete,
            prevElement:     "prev-arrow",
            nextElement:     "next-arrow",
            size:              initialSize,
			wrap: 				true
        });
	//auto play method set expects numerical argument in milliseconds
	this.instance.startAutoPlay(20000);
	//Below are API examples to dynamicaly retrieve and set the carousel length
	//this.instance.setProperty('size', initialSize, 1);
	//this.instance.getProperty('size');
	this.animComplete = function() {
		instance.stopAutoPlay();
		var currentFirstVisible = instance.getFirstVisible();
		//alert('current Visible = ' + currentFirstVisible);
		//alert('animation complete');
		var relativeLeft = YAHOO.util.Dom.getStyle(ulPromo,'left');
		var trueLeftOffset = -200*(currentFirstVisible-1) + 'px';
		//alert(relativeLeft);
		//alert('trueLeftOffset = '+trueLeftOffset);
		YAHOO.util.Dom.setStyle(ulPromo,'left',trueLeftOffset);
		instance.startAutoPlay(20000);
	}
};

YAHOO.util.Event.addListener(window, 'load', YAHOO.dsny.promoCarousel);
//when page load event occurs the carousel is constructed and bound to the scope of the window.

YAHOO.dsny.promoCarousel.show = function() {
			instance.show(); 	
			instance.startAutoPlay(20000);			
			YAHOO.util.Dom.setStyle('one-stop-module','display','none');
			YAHOO.util.Dom.setStyle(['childage1_os','childage2_os','childage3_os','childage4_os','childage5_os','childage6_os'],'display','none');
			YAHOO.util.Dom.setStyle('one-stop-form-date-range-label','color','#ffffff');
			YAHOO.util.Dom.setStyle('one-stop-form-party-mix-label','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage6_os','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage5_os','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage4_os','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage3_os','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage2_os','color','#ffffff');
			YAHOO.util.Dom.setStyle('childage1_os','color','#ffffff');
			};
			
YAHOO.dsny.promoCarousel.hide =	function() {
			instance.stopAutoPlay();
			instance.hide();
			YAHOO.util.Dom.setStyle('one-stop-module','display','block');
			};