window.addEvent('domready',function(){				
 // ===== FLASH: Index Text Rotator ==================================================				
 if($('flash-piece')){				
  var so = new SWFObject('/style library/flash/trailer.swf', 'oeTrailer', '670', '291', '8');				
  if(so.installedVer.major >= 7){				
   so.useExpressInstall('/style library/flash/expressinstall.swf');				
   so.addParam('allowScriptAccess','samedomain');				
   so.addParam('allowFullScreen','false');				
   so.addParam('quality','high');				
   so.addParam('bgcolor','#0a5ab9');				
   so.write("flash-piece");				
  } else {				
   $('flash-piece').innerHTML = '<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>';				
  }				
 }				
 // ===== FLASH: Index Video Module ======================================================				
 if($('indexVideo')){				
  var so = new SWFObject('/style library/flash/indexVideoModule.swf', 'oeVideoModule', '210', '340', '8');				
  if(so.installedVer.major >= 7){				
   so.useExpressInstall('/style library/flash/expressinstall.swf');				
   so.addParam('wmode','transparent');				
   so.addParam('allowScriptAccess','always');				
   so.addVariable('dataFile','/_layouts/GetMediaGalleryXML.aspx?');				
   so.addVariable('mediaPageURL','/ForTravelers/InRoomEntertainment/Pages/MediaPlayer.aspx');				
   so.addVariable('userGuid',userGuid);				
   so.addVariable('mediaFavoriteService',mediaFavoriteService);				
   so.addVariable('mediaFavoriteAddMethod',mediaFavoriteAddMethod);				
   so.addVariable('isSubPage',($E('div.about-us-right')?'true':'false'));
   so.addVariable('currentPageURL',window.location.href);
   so.write("indexVideo");				
  } else {				
   if(!window.ie) $('indexVideo').innerHTML = '<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>';				
  }				
  				
  //fix ie rendering 				
  if ( document.all ) {				
      var el = document.getElementById('direct-tv');				
      if ( el ) {				
          el.style.margin = "20px 0pt 0pt";				
      }				
  }				
 }				
 // ===== FLASH: Share With Friend Video ID ==============================================				
 if($('indexVideo') || $('videoPlayer')){				
  $E('div.body').adopt(new Element('input',{'type':'hidden','id':'fbVideoID'}));				
 }				
 // ===== FLASH: Solutions Landing Page ==================================================				
 if($('solutionsFlash')){				
     var container = $E('.head-img');				
  var so = new SWFObject('/style library/flash/subpage_LandingModule.swf', 'oeSubPageLanding', '471', '244', '8');				
  if(so.installedVer.major >= 7){				
   so.useExpressInstall('/style library/flash/expressinstall.swf');				
   so.addParam('wmode','transparent');				
   so.addVariable('subPageTitle',container.getElement('span').getText());				
   so.addVariable('overlayPNG','/style library/flash/overlay_subpage_Solutions.png');				
   so.addVariable('bkgdFLV','bkgd_subpage.flv');				
   so.addVariable('bkgdJPG','/style library/flash/bkgd_subpage.jpg');				
   so.write("solutionsFlash");				
  } else {				
   $('solutionsFlash').innerHTML = '<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>';				
  }				
 }				
				
 // ===== FLASH: About Us Landing Page ==================================================				
 if($('aboutusFlash')){				
  var container = $E('.head-img');				
  var so = new SWFObject('/style library/flash/subpage_LandingModule.swf', 'oeSubPageLanding', '471', '244', '8');				
  if(so.installedVer.major >= 7){				
   so.useExpressInstall('/style library/flash/expressinstall.swf');				
   so.addParam('wmode','transparent');				
   so.addVariable('subPageTitle',container.getElement('span').getText());				
   so.addVariable('overlayPNG','/style library/flash/overlay_subpage_AboutUs.png');				
   so.addVariable('bkgdFLV','bkgd_subpage.flv');				
   so.addVariable('bkgdJPG','/style library/flash/bkgd_subpage.jpg');				
   so.write(container);				
  } else {				
   $('aboutusFlash').innerHTML = '<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>';				
  }				
}
    		
 // ===== FLASH: Media Player Page =======================================================				
 if($('videoPlayer')){				
  var so = new SWFObject('/style library/flash/MediaGallery.swf', 'oeMediaGallery', '512', '376', '8');				
  if(so.installedVer.major >= 7){				
   so.useExpressInstall('/style library/flash/expressinstall.swf');				
   so.addParam('wmode','transparent');				
   so.addParam('allowScriptAccess','always');				
   so.addVariable('dataFile','/_layouts/GetMediaGalleryXML.aspx?');				
   so.addVariable('videoID',getQueryString('videoId', ''));				
   so.write('videoPlayer');				
  } else {				
   $('videoPlayer').innerHTML = '<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>';				
  }				
 }				
});

function getQueryString(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)", "i");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 	 			

function openShareVideoDialog(id){
	$('fbVideoID').value = id;
	dialog.activeLink = $E('a[rel=share]');
	dialog.formatPopup();
};
function updateShareVideoID(id){
	$('fbVideoID').value = id;
}
// ========== INDEX: Featured News Slider ===============================================================================

window.addEvent('load',function(){
	var NEWS = $E('.content #featuredNews');
	if($defined(NEWS)){
		var items = NEWS.getElements('li');
		var controls = $E('.content .controls');
		var NEWSList = new FeaturedNews(NEWS.getElement('ul'),{
			pageSize:4,
			items:items,
			minHeight:130,
			display:controls.getElement('.galleryCount'),
			prev:controls.getElement('.btnPrev'),
			next:controls.getElement('.btnNext')
		});
	};
});

var FeaturedNews = new Class({
	initialize: function(container, options) {
		this.setOptions(options);
		this.active = false;
		this.activeCount = 1;
		this.container = container;
		this.aItems = $A(this.options.items);
		this.nDisplay = this.options.display;
		this.pageSize = this.options.pageSize;
		this.itemsTotal = this.aItems.length;
		this.pageTotal = (this.itemsTotal%this.pageSize==0)?this.itemsTotal:(this.pageSize-(this.itemsTotal%this.pageSize)+this.itemsTotal);
		this.totalPages = Math.floor(this.pageTotal / this.pageSize);
		this.nDisplay.setHTML(this.activeCount +" of "+ this.totalPages);
		if(this.totalPages > 1){
			this.prevLink = this.options.prev;
			this.nextLink = this.options.next;
			this.prevLink.addClass('btnDisabled');
			this.nextLink.addClass('btnEnabled');
			this.prevLink.addEvent("click", function(e) {new Event(e).stop(); this.previous()}.bind(this));
			this.nextLink.addEvent("click", function(e) {new Event(e).stop(); this.next()}.bind(this));
		} else { 
			this.options.prev.remove();
			this.options.next.remove();
			this.options.display.remove();
		};
		this.slider = new Fx.Slide(this.container, {
			duration: 750,
			transition:Fx.Transitions.quartInOut,
			onStart: function(){
				// disable both buttons
				this.prevLink.removeClass("btnEnabled");
				this.nextLink.removeClass("btnEnabled");
				this.prevLink.addClass("btnDisabled");
				this.nextLink.addClass("btnDisabled");
				this.active = true;
			}.bind(this),
			onComplete: function(){
				if(this.container.getStyle('margin-top').toInt() < 0){
					this.aItems.each(function(li,i){
						li.addClass('hide');
						li.setStyle('display', 'none');
						if(i >= this.range().min && i <= this.range().max){
							li.removeClass('hide');
							li.setStyle('display', 'block');
						};
					}.bind(this));
					var height = (this.container.getCoordinates().height > this.options.minHeight)? 'auto' : this.options.minHeight+'px';
					this.container.setStyle('height',height);
					this.slider.slideIn();
				} else {
					if(this.activeCount > 1){
						this.prevLink.removeClass("btnDisabled");
						this.prevLink.addClass("btnEnabled");
					}
					if(this.activeCount < this.totalPages){
						this.nextLink.removeClass("btnDisabled");
						this.nextLink.addClass("btnEnabled");
					}
					this.active = false;
				};
			}.bind(this)
		});
	},
	previous: function() {
		if(this.active) return;
		return this.changeImage(this.activeCount-1);
	},
	next: function() {
		if(this.active) return;
		return this.changeImage(this.activeCount+1);
	},
	range: function(){
		var nMin = ((this.activeCount-1)*this.pageSize);
		var nMax = ((this.activeCount*this.pageSize)-1);
		return {min:nMin,max:nMax}
	},
	changeImage: function(n) {
		if((n <= 0) || (n > this.totalPages)) return false;
		var dir = (n > this.activeCount)? -1 : 1;
		this.activeCount = n;
		this.slider.slideOut();
		this.nDisplay.setHTML(this.activeCount +" of "+ this.totalPages);
	}
});
FeaturedNews.implement(new Options);

// ========== POPUP DIALOGs: Login / Forgot Password / What Is This? /  Feedback Form(s) ===============================================================================
var BalloonDialog = new Class({
	initialize: function(options){
        this.options = options;
		this.activeLink = null;
	},
	createPopup: function(){
		var submitBtn = ""; // empty;
		// ===== Create DIV Layout =====
		$E('div.body').adopt(
			new Element('div',{'id':'popup','class':'pLogin','styles':{'display':'none'}})
			.adopt(new Element('div',{'id':'pointer'}))
			.adopt(new Element('div',{'class':'title'})
				.adopt(new Element('img',{'class':'close','src':'/style library/images/lodgenet/popup_btn_close.gif','title':'close popup','events':{'click':function(){$('popup').setStyle('display','none')}}}))
				.adopt(new Element('span'))
			).adopt(new Element('div',{'class':'content'}))
								
		);
		// ===== AddEvents to all elements with 'class=popup' =====
		var anchor = $E('div.body').getElements('.popup');
		anchor.each(function(element){
		    // Changes Feedback to be redirects instead of popups.
		    if(element.getProperty('rel') != 'feedback') {
			    element.addEvent('click',function(e){
				    new Event(e).stop();
				    this.activeLink = element;
				    this.formatPopup();
			    }.bind(this));
			} else {
			    element.addEvent('click', function(e){
			        new Event(e).stop();
			        var contact = element.getElement('img').getProperty('alt');
		            window.location.href = "/ContactUs/Pages/Home.aspx?dept=" + escape(contact);
			    }.bind(this));
			}
		}.bind(this));
	},
	formatPopup: function(){
		var rel = this.activeLink.getProperty('rel');
		
		// ===== Add Classes =====
		var popupClass = (rel == 'whatis')? 'pWhatIs' : (rel == 'feedback')? 'pFeedback' : 'pLogin';
		var pointClass = (rel == 'feedback')? '' : (rel == 'whatis')? 'pointLeft' : 'pointRight';
		$('popup').className = popupClass;
		$('pointer').className = pointClass;
		
		// ===== Add Content =====
		var content = (rel == 'whatis')? this.dialogLayout.WhatIs() : (rel == 'feedback')? this.dialogLayout.Feedback(this.activeLink) : (rel == 'share')? this.dialogLayout.ShareWithFriends() : this.dialogLayout.LogIn();
		$('popup').setStyles({
			'top': '0px',
			'left': '-9000px',
			'display':'block'
		}).addEvent('keydown',function(event){
			if(event.keyCode == 13){ // ENTER key
				new Event(event).stop();
				submitBtn.click();
				return false;
			}
		});
		this.position.delay(100,this);
	},
	position: function(){
		var el = this.activeLink.getCoordinates();
		var rel = this.activeLink.getProperty('rel');
		var div = $E('div.body').getCoordinates();

		var yPos = el.top + ((rel == 'feedback')? -($('popup').getCoordinates().height.toInt()-el.height+12) : el.height);
		var xPos = el.left + ((rel != 'whatis')? -($('popup').getCoordinates().width.toInt()) : 0) + ((rel == 'login' || rel == 'share')? 45 : 0);

		$('popup').setStyles({
			'top': (yPos)+'px',
			'left': (xPos-div.left)+'px'
		});
	},
	dialogLayout : {
		WhatIs : function(){
			// ===== Edit Content =====
			var titleText = "Join the Network";
			var introText = "Welcome to our Website!  Feel free to explore all areas of this site, or click on a link below to go directly to content matching your particular interest.";
			introText += "<br /><br /><b>Click on your profession to proceed:</b><br />";
			var professions = [
				{name:'Investor',url:'/AboutUs/InvestorCenter/Pages/Home.aspx'},
				{name:'Hotelier',url:'/OurSolutions/Pages/Home.aspx'},
				{name:'Press Member',url:'/AboutUs/PressRoom/Pages/Home.aspx'},
				{name:'Vendor',url:'/AboutUs/Pages/CompanyAtAGlance.aspx'},
				{name:'Traveler',url:'/ForTravelers/Pages/Home.aspx'},
				{name:'Healthcare',url:'/Healthcare/Pages/Home.aspx'}
			];
			// ===== Create JobList =====
			var jobList = new Element('ul',{'class':'jobList'});
			professions.each(function(job){
				jobList.adopt(new Element('li').adopt(new Element('a',{'href':job.url}).setText(job.name)));					  
			});
			// ===== Add to Popup =====
			$E('#popup .title span').setText(titleText);
			$E('#popup .content').setHTML(introText).adopt(jobList).adopt(new Element('div',{'class':'clearLeft'}));
		},
		LogIn : function(){
			var url = 'Login.jax';
			var titleText = "Login";
			var form = ''
			+ '<label>Username:<br /><input type="text" class="txt" id="fbUsername" /></label>'
			+ '<label>Password:<br /><input type="password" class="txt" id="fbPassword" /></label>'
			+ '<label id="fbStatus" style="display:none;"></label>'
			var sendLoginBtn = submitBtn = new Element('input',{'type':'submit','value':'SEND','class':'submit',
				'events':{'click':function(e){
					var query = '?contact=login&username='+$('fbUsername').getValue().clean().encodeQueryString()+'&password='+$('fbPassword').getValue().clean().encodeQueryString()+'&remember='+$('fbRemember').getValue();
					new Event(e).stop();
                    var login = new Ajax(url+query, {
                        method: 'get',
                         onComplete:function(text,xml){
                               //alert("Text Returned: " + text);
                               if(text != "failure"){
                                    $('popup').setStyle('display','none');
                                    window.location = text;
                               } else {
                                    if($('fbStatus')){
                                         $('fbStatus').setStyles({'display':'block','color':'#F00'}).setHTML('<b>Login failed.</b>');
                                    }
                               }
                         }
                    });
                    login.request();
				}}
			});
			
			var sendForgotBtn = new Element('input',{'type':'submit','value':'SEND','class':'submit',
				'events':{'click':function(e){
					 var query = '?contact=forgotpassword&username='+$('fbUsername').getValue().clean().encodeQueryString()+'&email='+$('fbEmail').getValue().clean();
					 new Event(e).stop();	
					 new Ajax(url+query, {
						method: 'get',
						onComplete:function(text,xml){
						    // alert("Text Returned: " + text);
                            if(text == "success"){
                                $('popup').setStyle('display','none');
                            } else {
                                if($('fbStatus')){
                                    $('fbStatus').setStyles({'display':'block','color':'#F00'}).setHTML('<b>Unable To Access Information. Please Try Again.</b>');
                                }
                            }
						}
					}).request();
				}}
			});
			var rememberBtn = new Element('label').adopt(new Element('input',{'type':'checkbox','id':'fbRemember'})).appendText(' Remember Me');
			var forgotBtn = new Element('a',{'href':'#','class':'forgot',
				'events':{'click':function(e){
					new Event(e).stop();
					var titleText = "Forgot Password";
					var introText = "Tell us who you are. We'll email you.<br />";
					var form = ''
					+ '<label>Username:<br /><input type="text" class="txt" id="fbUsername" /></label>'
					+ '<label>Email:<br /><input type="text" class="txt" id="fbEmail" /></label>'
					+ '<label id="fbStatus" style="display:none;"></label>'
					// ===== Add to Popup =====
					$E('#popup .title span').setText(titleText);
					$E('#popup .content').setHTML(introText+form).adopt(sendForgotBtn).adopt(new Element('div',{'class':'clearRight'}));
				}}
			}).setText('Forgot Password?');
			// ===== Add to Popup =====
			$E('#popup .title span').setText(titleText);
			$E('#popup .content').setHTML(form).adopt(sendLoginBtn).adopt(rememberBtn).adopt(forgotBtn).adopt(new Element('div',{'class':'clearRight'}))
		},
		Feedback : function(el){
			var url = 'Feedback.jax';
			var contact = el.getElement('img').getProperty('alt');

			// ===== HACK: To prevent a redeployment during the day to change the alt text of an image =====/
			if(contact == "Health Care"){
				contact = "Healthcare";
			}

			var titleText = contact;
			if(titleText != "Traveler Comments"){
				titleText += " Feedback";
			}
			var form = ''
			+ '<label>Subject:<br /><input type="text" class="txt" id="fbSubject" /></label>'
			+ '<div class="hr"><hr /></div>'
			+ '<label>Name:<br /><input type="text" class="txt" id="fbName" /></label>'
			+ '<label>Email:<br /><input type="text" class="txt" id="fbEmail" /></label>'
			+ '<div class="hr"><hr /></div>'
			+ '<label>Message:<br /><textarea id="fbMessage"></textarea></label>';
			var sendBtn = new Element('input',{'type':'submit','value':'SEND','class':'submit',
				'events':{'click':function(e){
					new Event(e).stop();
					var query = '?contact='+contact+'&subject='+$('fbSubject').getValue().clean().encodeQueryString()+'&name='+$('fbName').getValue().clean().encodeQueryString()+'&email='+$('fbEmail').getValue()+'&message='+$('fbMessage').getValue().removeHTML().clean().encodeQueryString();
					 new Ajax(url+query, {
						method: 'get',
						onComplete:function(text,xml){
							$('popup').setStyle('display','none');
						}
					}).request();
				}}
			});
			// ===== Add to Popup =====
			$E('#popup .title span').setText(titleText);
			$E('#popup .content').setHTML(form).adopt(sendBtn).adopt(new Element('div',{'class':'clearRight'}));
		},
		ShareWithFriends : function(){
			var url = 'Share.jax';
			var titleText = "Send this to a friend";
			var form = ''
			+ '<label>Your name:<br /><input type="text" class="txt" id="fbYourName" /></label>'
			+ '<label>Your email:<br /><input type="text" class="txt" id="fbYourEmail" /></label>'
			+ '<div class="hr"><hr /></div>'
			+ '<label>Your friend\'s name:<br /><input type="text" class="txt" id="fbFriendName" /></label>'
			+ '<label>Your friend\'s email:<br /><input type="text" class="txt" id="fbFriendEmail" /></label>'
			+ '<div class="hr"><hr /></div>'
			+ '<label>Comments:<br /><textarea rows="4" cols="20" class="txt" id="fbComments" /></label>'
			var sendBtn = new Element('input',{'type':'submit','value':'SEND','class':'submit',
				'events':{'click':function(){
					
					var query = '?contact=shareWithFriends&subject=LodgeNet%20Share';
					if ( $('fbVideoID') == null )
						query +=                                           '&senderName='+$('fbYourName').getValue().clean().encodeQueryString()+'&senderEmail='+$('fbYourEmail').getValue().clean().encodeQueryString()+'&friendName='+$('fbFriendName').getValue()+'&friendEmail='+$('fbFriendEmail').getValue().clean().encodeQueryString();
					else						
						query += '&videoID=' + $('fbVideoID').getValue() + '&senderName='+$('fbYourName').getValue().clean().encodeQueryString()+'&senderEmail='+$('fbYourEmail').getValue().clean().encodeQueryString()+'&friendName='+$('fbFriendName').getValue()+'&friendEmail='+$('fbFriendEmail').getValue().clean().encodeQueryString();
					 new Ajax(url+query, {
						method: 'get',
						onComplete:function(text,xml){
							$('popup').setStyle('display','none');
						}
					}).request();
				}}
			});
			// ===== Add to Popup =====
			$E('#popup .title span').setText(titleText).adopt(sendBtn).adopt(new Element('div',{'class':'clearRight'}));
			$E('#popup .content').setHTML(form).adopt(sendBtn).adopt(new Element('div',{'class':'clearRight'}));
		}
	}
});

window.addEvent('domready',function(){
	dialog = new BalloonDialog();
	dialog.createPopup();
});
// ==========================================================================================================
String.extend({
    removeHTML: function(){
        return this.replace(/<[^>]*>/g,"");
    },
    encodeQueryString: function(){
        return (encodeURIComponent)? encodeURIComponent(this) : escape(this);
    }
});

// ========== LEFT NAV: KLUDGE - remove errant <LI> tags set with .NET table structure ==================================
/*
window.addEvent('domready',function(){
	$$('.about-us-left .container td a').each(function(link){
		if(link.innerHTML.toString().length){
			// ===== Find container <TD> tag =====
			var pNode = link.getParent();
			while(pNode.getTag() != "td"){
				pNode = pNode.getParent();
			}
			// ===== Get Content within <TD> =====
			if($defined(link.getElement("li"))){
				var content = link.getElement("li").innerHTML.replace("</A>","");
			} else {
				var content = link.innerHTML;
			}
			var aTag = new Element('a').setHTML(content)
				.setProperty('href',link.getProperty('href'))
				.setProperty('accesskey',link.getProperty('accesskey'))
				.setStyle('margin-left',link.getStyle('margin-left'));
			aTag.className = link.className;
			pNode.empty().adopt(aTag);
		}
	});
	if($defined($E('a[href=#zz1_Aspmenu1_SkipLink]'))){
		$E('a[href=#zz1_Aspmenu1_SkipLink]').setStyles({'display':'none','height':0,'overflow':'hidden'});
	}
});
*/
// ===== Sign Out: Append event to signout link if logged in ================================================
window.addEvent('domready', function(){
            if($('signOut')){
                        $('signOut').addEvent('click',function(e){
                                    new Event(e).stop();
                                    var url = "SignOut.jax";
                                    new Ajax(url, {
                                                method: 'get',
                                                onComplete:function(text,xml){
                                                            if(text != "failure"){
                                                                        window.location = text;
                                                            } else {
                                                                        // Do Nothing;
                                                            }
                                                }
                                    }).request();                                                                                              
                        });
            }
});

// ===== Expandable Content ==================================================
window.addEvent('domready', function() {
	$$('td.column-3 div.contain').each(function(el) {
		el.setStyle('display','none');
	});
	$$('td.containBtn').each(function(el) {
		var container = el.getParent().getNext().getElement('div.slideContainer');
		var arrow = el.getElement('img');
		var slyder = new Fx.Slide(container,{
			onComplete: function(){
				if(container.getStyle('margin-top').toInt() == 0){
					arrow.setProperty('src',arrow.getProperty('src').replace('_right.','_down.'));
				} else {
					arrow.setProperty('src',arrow.getProperty('src').replace('_down.','_right.'));
				}
			}
		}).hide();
		el.addEvent('click', function(e) {
			e = new Event(e); 
			slyder.toggle(); 
			/* for IE be explicit */
			if (window.ie){
				container.setStyle('display','block');
			}	
			e.stop();
		}).setStyle('cursor','pointer');
		/* for IE be explicit */
		if (window.ie){
			container.setStyle('display','none');	
		}
	});
	$$('.column-3 .contain').each(function(el) {
		el.setStyle('display','block');
	});
});
