var imagePath = "";
var activeAXIS = "";
var scrollBars = "";

// == FOLDER STRUCTURE ==
var folder = {
	JS: '/js/',
	XML: '/content/xml/',
	FLASH: '/content/flash/',
	IMAGES: '/content/images/'
};

// ===== Remove default value text from input[type="text"] fields ===============================================
window.addEvent('domready',function(){
	$$('input.text').addEvents({
		'focus':function(e){ if (this.value == this.defaultValue) this.value = "" },
		'blur':function(e){ if (this.value == "") this.value = this.defaultValue }
	});
});

window.addEvent('domready',function(){
	// ===== FLASH: WinStar Header Module ================================================
	if($('WinStarHeader')){
		var so = new SWFObject(folder.FLASH + 'Winstar_Header.swf', 'oeWinStarHeaderModule', '100%', '100%', '8');
		if(so.installedVer.major >= 7){
			so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addParam('wmode','transparent');
			so.addVariable('dataFile',folder.XML + 'destinations.xml');
			so.write($('WinStarHeader'));
		} else {
			$('WinStarHeader').set('html','<h1>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a><br /> to experience this site to its fullest.</h1>');	
		}
	}
	
	// ===== FLASH: WinStar Banner Module ================================================
	if($('WinStarBanner')){
		var so = new SWFObject(folder.FLASH + 'bLoader06_morello.swf', 'oeWinStarBannerModule', '100%', '100%', '8');
		if(so.installedVer.major >= 7){
			so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addVariable('listFile',folder.FLASH + 'bLoader06_morello.swf?view=XML');
			so.write($('WinStarBanner'));
		} else {
			$('WinStarBanner').set('html','<h1>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a><br /> to experience this site to its fullest.</h1>');	
		}
	}


	// ===== FLASH: WinStar Concierge - Index ================================================

        if($('AskModule')){
		var so = new SWFObject(folder.FLASH + 'visitVideoConcierge.swf', 'oeWinStarAskModule', '209', '222', '8');

        	if(so.installedVer.major >= 7){
                        so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addVariable('conciergeHref','/concierge');
			so.write($('AskModule'));
                } else {
			$('AskModule').set('html','<h1>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a><br /> to experience this site to its fullest.</h1>');    

                }

        }

        

        // ===== FLASH: WinStar Concierge - Subpages ================================================

        if($('AskConciergeModule')){
		var so = new SWFObject(folder.FLASH + 'visitVideoConciergeSub.swf', 'oeWinStarAskConciergeModule', '366', '224', '8');

                if(so.installedVer.major >= 7){
			so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addParam('wmode','transparent');
			so.addVariable('conciergeHref','/concierge');
			so.write($('AskConciergeModule'));
                } else {

                        $('AskConciergeModule').set('html','<h1>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a><br /> to experience this site to its fullest.</h1>');      

                }

        }
	
	// ===== FLASH: Interactive Map ================================================
	if($('int-map')){
		var so = new SWFObject(folder.FLASH + 'interactive_map.swf', 'oeInteractiveMap', '797px', '325px', '8', '#EBE1B6');
		if(so.installedVer.major >= 7){
			so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addParam('wmode','transparent');
			so.addParam('allowScriptAccess','always');
			so.addVariable('xmlDataFile',folder.XML + 'interactiveMapZoomify.xml');
			so.write($('int-map'));
		} else {
			$('int-map').set('html','<h5>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a> to experience this site to its fullest.</h5>');	
		}
		buildBubbleDialog();
	}

	// ===== FLASH: Video Concierge ================================================
	if($('videoConcierge')){
		var so = new SWFObject(folder.FLASH + 'videoConcierge.swf', 'oeVideoConcierge', '800px', '360px', '8', '#F3EBC4');
		if(so.installedVer.major >= 7){
			so.useExpressInstall(folder.FLASH + 'expressinstall.swf');
			so.addParam('wmode','transparent');
			so.addVariable("FAQ_URL","/about-us/faqs");
			so.write($('videoConcierge'));
		} else {
			$('videoConcierge').addClass('noFlash').set('html','<div class="bkgd"><h2>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a> to experience this site to its fullest.</h2></div>');	
		}
	}
	

	
});
window.addEvent('load',function(){
	// Activate HTML Links to communicate with flash;
	$$('.int-legend .moveToLocale').addEvent('click',function(e){
		new Event(e).stop();
		// ===== If flash is available, call moveToLocation() inside SWF =====
		if (document.getElementById("oeInteractiveMap")){
			document.getElementById("oeInteractiveMap").toFlashMoveToLocation(this.get('name'));
		}
	});								
	// ===== Enable Map Key Filtering =====
	$$('.map-key li a').setStyle('opacity',0.5).addEvent('click',function(e){
		new Event(e).stop();
		// ===== If flash is available, call filterMarker(icon) inside SWF =====
		if (document.getElementById("oeInteractiveMap")){
			document.getElementById("oeInteractiveMap").toFlashFilterMarker(this.get('rel'));
		}
		if(this.getStyle('opacity') > 0.5){
			this.setStyle('opacity', 0.5);	
		} else {
			this.setStyle('opacity', 1.0);
		}
	});
});
// ========== FAQ: Enable Multi-level Accordion ===============================================================================
var nMainCat = null;
var nSubCat = null;
var openItem = false;
var mainCategory = [];
var subCategory = [];

window.addEvent('domready', function(){
	if(!$E('ul#FAQ')) return; // no FAQ list
	mainCategory = ['General','Hotel','Gaming','TableGames','PlayersClub','Dining','Amenities', 'Entertainment'];
	// ===== Add Accordion Events to Main List ====================================================
	var accordion = new Accordion('div.toggle', 'dl.list', {
		opacity: true, alwaysHide: true, display: -1, wait: false, transition:Fx.Transitions.Circ.easeInOut,
		onActive: function(toggler, element){
			toggler.getParent().setStyle('height','auto');
			toggler.removeClass('arrow_horz').addClass('arrow_vert');
			nMainCat = toggler.getProperty('rel');
			activeCategory = toggler;
		},
		onBackground: function(toggler, element){
			element.setStyle('height',element.offsetHeight);
			toggler.removeClass('arrow_vert').addClass('arrow_horz');
		},
		onComplete: function(){
			if(openItem && nSubCat !== null && $(subCategory[nMainCat]).getElements('dt').length > nSubCat){
				$(subCategory[nMainCat]).getElements('dt')[nSubCat].fireEvent('click');
			};
			openItem = false;
		}
	}, $E('ul#FAQ'));
	$$('div.toggle').each(function(div,idx){ div.setProperty('rel',idx)});
	// ===== Add Accordion Events to All Subsets ==================================================
	var subAccordion = [];
	subCategory = ['faq_general','faq_Hotel','faq_Gaming','faq_TableGames','faq_PlayersClub','faq_Dining','faq_Amenities', 'faq_Entertainment'];
	subCategory.each(function(element,index){
		subAccordion[index] = new Accordion($(element).getElements('dt'), $(element).getElements('dd'), {
			opacity: true, alwaysHide: true, display: -1, wait: false, transition:Fx.Transitions.Circ.easeInOut,
			onActive: function(toggler, element){
				toggler.getParent().setStyle('height','auto');
				toggler.removeClass('arrow_horz').addClass('arrow_vert');
				nSubCat = index;
			},
			onBackground: function(toggler, element){
				element.setStyle('height',element.offsetHeight);
				toggler.removeClass('arrow_vert').addClass('arrow_horz');
			}
		}, $(element));
	});
	// ===== If URL has hash(#), parse then open FAQ ==============================================
	if(window.location.hash.contains('#')){
		$$('div.toggle').each(function(link, index){
			var urlHash = window.location.hash;
			var hash = (urlHash.contains('#'))? urlHash.replace('#',''):null;
			if(hash && hash.contains(':')){ 
				// ===== Match List ID then set nSubCat to index found =====
				nSubID = hash.split(':')[1];
				hash = hash.split(':')[0];
				nMainCat = mainCategory.indexOf(hash);
				var question = $(subCategory[nMainCat]).getElements('dt');
				question.each(function(dt,n){ if(dt.getProperty('id') == nSubID) nSubCat = n });
			};
			if(link.getNext().getProperty('id').indexOf(hash)>-1){
				nMainCat = index;
				openItem = true;
				link.fireEvent('click');
			};
		});
	};
});

// ========== LightBox: Picture Tour opens photo gallery  =====================================================================
window.addEvent('domready',function(){
	
	if(!$('btnPictureTour')) return;
	new Asset.javascript(folder.JS + 'pictureTour.js');
	
	$('btnPictureTour').addEvent('click',function(e){
		new Event(e).stop();
		pictureTour.open();
	});
	
});

// ========== Toggle Tab Items ================================================================================================
window.addEvent('domready',function(){
	if(!$E('.inlineTabs')) return;
	var tabBtns = $$('a.tab');
	var tabItem = $$('.inlineTabs .tabItem');
	
	tabBtns.each(function(tab, i){
		tab.addEvent('click',function(e){
			new Event(e).stop();
			tabItem.each(function(item){ item.addClass('hide') });
			tabBtns.removeClass('selected');
			var num = tab.getProperty('rel').replace(/\D/g,'');
			tab.addClass('selected');
			tabItem[num].removeClass('hide');
		}).setProperty('rel','tab'+i);
		if(tab.hasClass('selected')){
			tabItem[i].removeClass('hide');
		}
	});
	
});

// ========== event-calendar random casino images ================================================================================================
window.addEvent('domready',function(){
	// ===== TEMP: Replace Calendar of Events with temporary graphic =====
	if($E('.calendar-events') && !$E('.entertainment')){
		var casino = [
			{name:'Beijing', href:'/casinos/beijing'},
			{name:'London', href:'/casinos/london'},
			{name:'Madrid', href:'/casinos/madrid'},
			{name:'Paris', href:'/casinos/paris'},
			{name:'Rome', href:'/casinos/rome'}
		];
		var theCasino = casino[Math.floor(Math.random()*casino.length)];
		$E('.calendar-events').empty().setStyle('border-width',0).adopt(
			new Element('a',{'href':theCasino.href}).adopt(new Element('img',{'src':folder.IMAGES + 'promo_Casino_'+theCasino.name+'.jpg'}))															
		);
	};
	
});

// ========== Calendar: Expand/Collapse Details ===============================================================================
window.addEvent('domready',function(){
	$$('table.calendar td.details').each(function(details){
		if(details.getElement('div').getStyle('height').toInt() > 48 /* three lines */){
			details.addClass('plus').addEvent('click',function(e){
				new Event(e).stop();
				this.toggleClass('plus').toggleClass('minus');
			});
		};
	});
});

// ===== Interactive Map: Balloon Dialog ====================================================================================
Element.implement({
	alignTo: function(target, location, offset) {
		target = $(target);
		var positionTarget = {
			x: target.getPosition((Browser.Engine.trident)? '' : target.getParent()).x,
			y: target.getPosition((Browser.Engine.trident)? '' : target.getParent()).y
		};
		this.setStyles({
			left: (positionTarget.x + location.x) + offset.x + 'px',
			top: (positionTarget.y + location.y) + offset.y + 'px'
		});
	}
});
function buildBubbleDialog(){
	var dialog = new Element('div', {id:'dialog'}).adopt(
		new Element('div',{'class':'top'}),
		new Element('div',{'class':'mid'}).adopt(
			new Element('div',{'class':'contents'}).adopt(
				new Element('div',{id:'btnCloseDialog','events': {
					'click': function(){ hideBubbleDialog(); }
				}}).adopt(new Element('img',{'src':folder.IMAGES+'balloon/btn_close.gif'})),
				new Element('h3'),
				new Element('span'),
				new Element('div',{'class':'clear'})
			)
		),
		new Element('div',{'class':'btm'})
	);
	$E('.special-content').adopt(dialog.setStyle('display','none'));
};

function showBubbleDialog(location,info){
	// ===== Update Dialog Content =====
	$E('#dialog h3').set('text',info.title);
	$E('#dialog span').empty().set('html',info.description+'<br /><br />').adopt(
		new Element('a',{
			'class': 'more',
			'href': info.href,
    		'html': 'Go to '+ info.title +' page'
		})																	
	);
	
	// ===== Position the Dialog =====
	$('dialog').setStyle('display','block');
	var offset = { x: -20, y: $('dialog').getCoordinates().height * -1 };
	$('dialog').alignTo('int-map', location, offset);
};

function hideBubbleDialog(){
	$('dialog').setStyle('display','none');
};

// ============================================================================================================================
String.extend({
	trim: function(){
		return this.replace(/^\s*|\s*$/g, "");
	}
});
function $E(selector, filter){
	return ($(filter) || document).getElement(selector);
};