window.addEvent('domready', function() {//---START PRIMARY FUNCTION---required for all mootools js frameworks
									 
/*=Accordions
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
if($chk( $('accordion') )) {
	var myAccordion = new Accordion($$('div.accordions h3.toggler'), $$('div.accordions div.element'), {
		opacity: false,
		alwaysHide: true
	});
	
	$$('.areas').each(function(item){						
		var elAcc = item.getElement('.accordions');
		var elBg = item.getElement('.bgAlpha');
		var FxAcc = new Fx.Morph(elAcc);
		var FxBg = new Fx.Morph(elBg);
		
		FxBg.set({opacity: 0});
		item.addEvent('mouseenter', function(){
			FxAcc.set({opacity: 1});
			FxBg.set({opacity: .95});
		});
		
		item.addEvent('mouseleave', function(){
			FxAcc.set({opacity: 0});
			FxBg.set({opacity: 0});
		});
	});
}
/*----------------------------------------------
-------------FUNCTIONS--------------------------
-----------------------------------------------*/

//---MAKE GLOBAL NAV UL'S SAME HEIGHT---
if ($chk($('global-nav'))) {
	var navHeight = $('global-nav').getStyle('height').toInt(); //GET HEIGHT OF FIRST UL (LONGEST ONE)
	$$('.global-nav-items').setStyle('height', navHeight);
}
/*=Menu Function
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
$$('a.hotelinfo').each(function(e,index) {
	var eLink = e.getProperty('href');
	e.addEvent('click', function() {
		return hs.htmlExpand(e, {src:eLink, preserveContent: true, wrapperClassName: 'highslide-hotel', objectType: 'iframe' } );
	});
});

$$('a.toggle').each(function(e,index) {
	//Set Variables						 
	var toggle = new Array(); //Array used to determine if mouse is over a menu
	var menuPrefix = "global-";//First part of the menu id
	var navMenu = menuPrefix+e.get('name'); //Name of the menu that we want to control
	//Since we set the css to display:none in the css we change it here to display:block so that we have access to its opacity properties
	$(navMenu).setStyle('display', 'block');
	//Now that the menu is visible we need to set the opacity to 0 so that it remains invisible initially
	var myFx = new Fx.Morph(navMenu, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	myFx.set({opacity: 0});
	//Set up functions to handle fade-in and fade-out
	function fadeout() {
		if(toggle[index] != 1) {
			myFx.start({opacity: 0}).chain(
				function(){$(navMenu).setStyle('display', 'none');}			   
			);
		}
	}
	function fadein() {
		$(navMenu).setStyle('display', 'block');
		myFx.start({opacity: 1});
	}
	//Add events to the toggle links
	e.addEvent('click',function(event) {
		fadein();
		return false;
	});
	e.addEvent('mouseleave',function(event) {
		toggle[index] = 0;
		fadeout.delay(300,e);
	});
	//Add events to the Menus
	$(navMenu).addEvent('mouseenter',function(event) {
		toggle[index] = 1; //This keeps the menu from disappearing if the mouse is on it
		return false;
	});
	$(navMenu).addEvent('mouseleave',function(event) {
		toggle[index] = 0;									  								  
		fadeout();
		toggle[index] = 1; //We set this back to 1 in order to keep the menus from disappearing as soon as you click on them
		return false;
	});
});

//---------SLIDE TRANSITIONS----------
if($chk( $('member-form') )) {
	var loginSlide = new Fx.Slide('member-form');
	loginSlide.hide();
	$('member-form').setStyle('display', 'block');
	$('member-form').setStyle('visibility', 'visible');
	$('toggle-member-form').addEvent('click', function(){
		loginSlide.toggle();
	});
}

if($chk($('news-more-slide'))) {
	var newsSlide = new Fx.Slide('news-more-slide');
	$('news-more-slide').setStyle('visibility', 'visible');
	newsSlide.hide();
	$('toggle-news').addEvent('click', function(){
		newsSlide.toggle();
	});
}

/*
$$('a.openlogin').each(function(e,index) {
	var showLogin = new Fx.Slide('div.login-area').hide();
	$(e).addEvent('click',function() {
		alert(1);
		showLogin.toggle();
	});
});
*/
if ($chk($('login-area'))) {
	$('login-area').setStyle('display', 'block');
	var showLogin = new Fx.Slide('login-area').hide();
};
$$('a.openlogin').addEvent('click',function() {
	//var showLogin = new Fx.Slide('login-area').hide();
	showLogin.toggle();
});

/*=News
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
if ($chk($('latest-news'))) {
	news_items = $('latest-news').getChildren('div');
	current_el = $('latest-news').getFirst('div');
	//hide all news articles
	news_items.setStyle('display', 'none');
	//show the first article
	current_el.setStyle('display', 'inline');
	current_el.set('morph', {
		duration: 250
	});
	current_el.morph({
		'opacity': 1
	});
	//function to infinitely switch out news articles
	function fadeNewsOut(){
		news_items.set('morph', {
			duration: 500
		});
		news_items.morph({
			'opacity': 0
		});
		
		function fadeNewsIn(){
			news_items.setStyle('display', 'none');
			
			current_el = current_el.getNext('div');
			if (current_el.hasClass('last')) {
				current_el = $('latest-news').getFirst('div');
			}
			current_el.setStyle('display', 'inline');
			current_el.set('morph', {
				duration: 500
			});
			current_el.morph({
				'opacity': 1
			});
		}
		fadeNewsIn.delay(500);
	}
	fadeNewsOut.periodical(5000);
}

//store titles and text  
$$('a.leaderTips').each(function(element,index) {  
	var content = element.get('title').split('::');  
	element.store('tip:title', content[0]);  
	element.store('tip:text', content[1]);  
});
//create tips
var leaderTips = new Tips('.leaderTips',{
	className: 'leadertips',
	hideDelay: 250
});
});
// =========================== 
//
// ===========================
function comboItemSelected(oList1,oList2,cType) {
	if (oList2!=null){
 	    alert('oList2 Not Null and need to clear it out');
		clearComboOrList(oList2);
       if (oList1.selectedIndex==-1){
         oList2.options[oList2.options.length] = new Option('SELECT','');
       } else {
	  // fillCombobox(oList2,cType + '=' + oList1.options[oList1.selectedIndex].value);
	   fillCombobox(oList2,cType + oList1.options[oList1.selectedIndex].value);
	   }
	}
}

function clearComboOrList(oList) {
   for (var i = oList.options.length-1; i>=0 ; i--) {
	   oList.options[i]=null;
   }
   oList.selectedIndex = -1;
   if (oList.onchange) oList.onchange();
}

function fillCombobox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   oList.options[0] = new Option('SELECT','');
		   var arrX = assocArray[vValue];
           for ( var i = 0; i<arrX.length ; i = i+2 ){
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);
           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }
   }
}

function listboxItemSelected(oList1,oList2,cType) {
   if (oList2!=null) {
	   clearComboOrList(oList2);
      if (oList1.selectedIndex==-1) {
         oList2.options[oList2.options.length] = new Option('SELECT','');
      } else {
		 fillListbox(oList2,cType + oList1.options[oList1.selectedIndex].value)
		 // fillListbox(oList2,oList1.name + '=' + oList1.options[oList1.selectedIndex].value)
	  }
   }
   else {

   }
}


function fillListbox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   var arrX = assocArray[vValue];
		   for ( var i = 0; i<arrX.length ; i = i+2 ){
			   
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);

           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
 
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }

   }
   else {
     	
   }
 
}//-----------END PRIMARY FUNCTION---