// JavaScript Document
var siteid = 'SITE_110613_12185636_LLX10';
//Rosewood - Mayakoba - Synxis utm_Linker code for reservations
function postForm(oForm){
	var qs = "";
	qs = qs + "?Chain="		+ 	oForm.Chain.value;
	qs = qs + "&hotel="		+ 	oForm.hotel.value;
	qs = qs + "&Arrive="	+ 	oForm.Arrive.value;
	_gaq.push(function() {
        	var tracker = _gat._getTrackerByName(); 
			window.open(tracker._getLinkerUrl('https://gc.synxis.com/rez.aspx' + qs));
     	 });
	 return false;
	}
var convertCFQuery = function(original){
	var data = [];
	for(var i=0;i<original.DATA.length;i++){
		var item = {};
		for(var j=0;j<original.COLUMNS.length;j++){
			item[original.COLUMNS[j]]=original.DATA[i][j];
		}
		data.push(item);
	}
	return data;
};
				
	// Retrieve the User Agent of the browser
	var agent = navigator.userAgent.toLowerCase(),
	// Check if the UA is a mobile one (iphone, ipod, android, blackberry)
	isUAMobile =!!(agent.match(/(iphone|iPhone|iPod|blackberry|android|htc|lg|midp|mmp|mobile|nokia|opera mini|palm|pocket|psp|sgh|smartphone|symbian|treo mini|Playstation Portable|SonyEricsson|Samsung|MobileExplorer|PalmSource|Benq|Windows Phone|Windows Mobile|IEMobile|Windows CE|Nintendo Wii)/i));
	
        if(agent.match(/ipad/ig))isUAMobile=false;

	if(!isUAMobile){
		$('link:eq(1)').removeAttr('media');
		$('link:eq(0),link:eq(2)').remove();
	}
	
	
$(function() {




	/******************************/
	/* PNG Fix for Header Image */
	/******************************/
	$('#header').pngFix();

	$('#res a').click(function(){
		/*var $t = $(this).closest('#res');
		if($t.hasClass('active')){
			$t.find('span').show();
			$t.removeClass('active');
			$t.stop(true).animate({width:200},600);
		}else{
			$t.find('span').hide();
			$t.addClass('active');
			$t.stop(true).animate({width:410},600);
		}*/
		return false;
	}).css('cursor','default');

//calendar code

		$("#Arrival").datepicker({
			minDate:0,
			showAnim: "fadeIn"
		});
		jQuery.support.placeholder = (function(){
		    var i = document.createElement('input');
		    return 'placeholder' in i;
		})();
		if(!$.support.placeholder){
			$('#Arrival').val('Select Arrival Date').css({color:'#999'}).bind('focus',function(){
				if($(this).val()=='Select Arrival Date')
					$(this).val('')
				$(this).css({color:''})
			}).bind('blur',function(){
				if($(this).val()==''){
					$(this).val('Select Arrival Date').css({color:'#999'})
				}
			})
		}
 /*$("#Arrival").datepicker('setDate',addDays(new Date(),1));
		$("#Depart").datepicker({
			minDate:1,
			showAnim: "fadeIn",
			showOn: 'both',
			buttonText: 'Select Check Out Date',
			buttonImage: '/en/i/'+siteid+'/templates/cal_icon.png',
			buttonImageOnly: true,
			defaultDate: +1,
			gotoCurrent: true
		});



 $("#Depart").datepicker('setDate',addDays(new Date(),2));*/
/*for related jQuery calendars*/
function addDays(myDate,days) {
//myDate = starting	date, days = no. days to add.
	var temp_date = new Date();
	var i = 0;
	var days_to_add = 0;
	while (i < (days)){
		temp_date = new Date(myDate.getTime() +	(days_to_add*24*60*60*1000));
			i+=1;
		days_to_add += 1;
	}
	return new Date(myDate.getTime() + days_to_add*24*60*60*1000);
}
function comparedate(date1str,date2str){
	var date1 = new Date(date1str);
	var date2 = new Date(date2str);
	if (date1 > date2){
		return true;
	}else if (date1 < date2){
		return false;
	}else{
		return true;
	}
}


	$.fn.sidePhotos = function(center) {
		var centerWidth = $(center).width();

		return this.each(function() {
			var $this = $(this);
			var $image = $this.find('img');
			$(window).load(function() {
				$(window).resize(function() {
					centerWidth = $(center).width();
					var imageWidth = $image.width();
					var newWidth = ($(window).width()-centerWidth)/2;
					var leftMargin = (newWidth-imageWidth)/2;

					$this.width(newWidth);
					$image.css({
						'margin-left' : leftMargin
					});
					
					if( newWidth <= 0 ) {
						$this.hide();
						$this.data('isHidden',true);
					} else if ( $this.data('isHidden') ) {
						$this.show();
						$this.data('isHidden',false);
					}

				}).resize();

			});
			if( centerWidth < $(window).width() )
				$this.fadeIn();

		});
	}

	$('#subleft,#subright').sidePhotos('#sub #section1');


	$.fn.scaleMe = function() {
		return this.each(function() {
			var $this = $(this);
			$(window).load(function() {
				var originalWidth = $this.width();
				var originalHeight = $this.height();
				var divHeight = $this.closest('div').height();

				$(window).resize(function() {
					var divWidth = $this.closest('div').width();
					var newWidth = divWidth;
					var newHeight = (divWidth/originalWidth)*originalHeight;

					if( newHeight < divHeight ) {
						newHeight = divHeight;
						newWidth = originalWidth*(newHeight/originalHeight);
					}

					var topMargin = (divHeight-newHeight)/2;
					var leftMargin = (divWidth-newWidth)/2;

					$this.height(newHeight)
					.width(newWidth)
					.css({
						'margin-top' : topMargin,
						'margin-left' : leftMargin
					});

				}).resize();

				$this.fadeIn();

			});
		});
	};

	$('#homephoto1 img,#homephoto2 img,#homephoto3 img,.top .img1 img,.toptt .img1 img,.toppr .img1 img,.topl .img1 img').scaleMe();


	$.fn.shrinkMe = function() {
		return this.each(function() {
			var $this = $(this);
			$(window).load(function() {
				var originalWidth = $this.width();
				var originalHeight = $this.height();

				$(window).resize(function() {
					var divWidth = $this.parent().width();
					var newWidth;
					var newHeight;

					if( originalWidth > divWidth ) {
						newWidth = divWidth;
						newHeight = originalHeight*(newWidth/originalWidth);
					}else{
						newHeight = originalHeight;
						newWidth = originalWidth;
					}
					$this.height(newHeight).width(newWidth);

				}).resize();

				$this.fadeIn();

			});
		});
	};

	$('#home #section2 div img,#sub #section1 .photo img').shrinkMe();
});




function popPIO(file,x,y,name,domain)
	{
		var dum = Math.random() * 10000
		if(document.all)
    		  var xMax = screen.width, yMax = screen.height;
	    else if(document.layers)
		      var xMax = window.outerWidth, yMax = window.outerHeight;
	    else
		      var xMax=800, yMax=600;	
		
		xOffset = (xMax - x) / 2;
	    yOffset = 50;  
		var pageLocation = location.pathname + location.search;
		var completeURL = file+"?domain="+domain 
		newwindow = window.open(completeURL,name,'scrollbars=yes,toolbar=no,directories=no,menubar=yes,resizable=no,status=yes,width='+x+',height='+y+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}




var attachMobileGalleryEvents = function(){


	$('.thumbs').each(function(){
		$is = $(this).find('.thumb');
		/* Only if it's a regular photo gallery and only if the window is small on load */
		if(!$is.length || !isUAMobile) return;
		
		/* Non Regular Photo Galleries *//*[RSG} Removing this as we always want to proceed if we are mobile*/
		/*if(!$is.attr('label')){
			$(window).load(function(){
				var $img = $('.image1 img');
				var h = $img.height();
				var h2 = $img.parent().height();
				$img.css({
					marginTop: Math.ceil((h2-h)/2)
				});
			});
			return;
		}*/

		$(this).remove();
		$('.title').before('<table cellpadding="0" cellspacing="0" width="100%"><tr><td width="25"><img src="/en/i/arrow_left.gif" id="leftArrow"></td><td><div class="galleryTitle"></div></td><td width="25"><img src="/en/i/arrow_right.gif" id="rightArrow"></td></tr></table><div class="gallery"><div class="galleryWide"></div></div><div class="galleryButtons"></div><div class="galleryImages"></div>');
		$('.images,.title').remove();

		var dataArray = [];
		var g = $('.gallery');
		var gW = $('.galleryWide');
		var gT = $('.galleryTitle');
		
		$is.each(function(){
			dataArray.push({img:$(this).find('img').attr('src').replace(/\/([^\/]*)_c/,'/mobile/$1'),imgcaption:$(this).attr('label')});
		});
		for(var i in dataArray){
			gW.append('<table height="320" cellpadding="0" cellspacing="0"><tr><td align="center"><img src="'+dataArray[i].img+'"></td></tr></table>');
			//$('.galleryButtons').append('<div class="button" />');
		}
		var iW = 360;
		var iH = 320;
		var w = $(window);
		var lockedPos = -20;
		var curI = 0;
		
		/* Move the first pic to be centered in the current window */
		$('.button:eq(0)').addClass('active');
		gT.html(dataArray[0].imgcaption);
		
		w.resize(function(){
			changePhoto();
		});
		
		/* And here is where we will start handling touch events on g */
		var originalCoord = { x: 0, y: 0 }
		var finalCoord = { x: 0, y: 0 }
		var lockedY = true;
		var sT = $(window).scrollTop();
		
		function touchStart(event) {
			event.preventDefault();
			originalCoord.x = event.targetTouches[0].pageX;
			originalCoord.y = event.targetTouches[0].pageY;
			lockedY = true;
			sT = $(window).scrollTop();
		}
		function touchMove(event) {
			event.preventDefault();
			finalCoord.x = event.targetTouches[0].pageX; // Updated X,Y coordinates
			finalCoord.y = event.targetTouches[0].pageY;
			
			var changeX = originalCoord.x - finalCoord.x;
			var changeY = originalCoord.y - finalCoord.y;
			
			if(changeY>100||changeY<-100)
				lockedY = false;
			
			if(lockedY){
				gW.css({'-webkit-transform':'translateX('+(lockedPos-changeX)+'px)'});
			}else{
				//$('#body').scrollTo(0,sT+changeY);
				$('#content').css({'-webkit-transform':'translateY('+(-changeY)+'px)'});
			}
			
		}
		function touchEnd(event) {
			event.preventDefault();
			var changeY = originalCoord.y - finalCoord.y;
			var changeX = originalCoord.x - finalCoord.x;
			lockedPos = lockedPos-changeX;
			
			
			/* If we moved far enough vertically, scroll instead of changing images */
			if(lockedY){
				if(changeX > 20 && (curI+1) < dataArray.length)
					curI++;
				if(changeX < -20 && (curI-1) >= 0)
					curI--;
			}else{
				$('#content').css({'-webkit-transform':'translateY(0px)'});
				window.scrollTo(0,sT+changeY);
			}
				
			changePhoto();
		}
		var changePhoto = function(){
			
			//$('.button.active').removeClass('active');
			//$('.button:eq('+curI+')').addClass('active');
			
			if(dataArray[curI].imgcaption!='')
				gT.html(dataArray[curI].imgcaption);
			else
				gT.html(' ');
			prevLockedPos = lockedPos;
			lockedPos = 0;
			for(var i=0; i<curI; i++){
				lockedPos = lockedPos - $('.galleryWide table:eq('+i+')').width() - 40;
			}
			lockedPos = lockedPos - 20;
			lockedPos = lockedPos + ((w.width()-$('.galleryWide table:eq('+curI+')').width())/2);
			for(var i=0;i<=300;i=i+15){
				setTimeout(function(i2){
					gW.css({'-webkit-transform':'translateX('+(parseInt(prevLockedPos-(prevLockedPos-lockedPos)*(i2/300)))+'px)'});
				},i,i);
			}
		};
		gW.find('img:first').load(function(){
			changePhoto();
		});
		$('#leftArrow').click(function(){				
			if((curI-1) >= 0)
				curI--;
			changePhoto();
		});
		$('#rightArrow').click(function(){				
			if((curI+1) < dataArray.length)
				curI++;
			changePhoto();
		});
		// Add gestures to all swipable areas
		if(g[0]){
			g[0].addEventListener("touchstart", touchStart, false);
			g[0].addEventListener("touchmove", touchMove, false);
			g[0].addEventListener("touchend", touchEnd, false);}

		});
	
};



var buffer = false;
var loaded = false;
var thumbnails = true;
var aG = [];
function loadGallery(){
aG.push({
	totalW: totalW,
	totalH: totalH,
	path: path
});

$(function(){
	if(loaded) return false;
	loaded = true;
	for(var p in aG){
		var gSlideshow = $('div.images:eq('+p+')')
		gSlideshow.data('mP',p);
		gSlideshow.height(aG[p].totalH);
			$.ajax({
				url: aG[p].path+'myimages.xml',
				dataType: 'xml',
				context: gSlideshow,
				success: function(data){
					var images = $(this);
					var mP = images.data('mP');
					var dataArray = [];
					$(data).find('data').each(function(){
						dataArray.push({img:$(this).attr('img'),imgcaption:$(this).attr('imgcaption'),thumb:$(this).attr('thumb'),link:$(this).attr('imgLink')});
					});
					//console.log(dataArray.length)
					for(var i=0;i < dataArray.length;i++){
						images.append(
							'<img src="'+path
							+dataArray[i].img
							+'" imagelabel="'
							+dataArray[i].imgcaption
							+'"><br /><br /><br /><br /><br /><br /><br />'
						);
					};
					var arrowContainer = $('<div class="new-arrow-container"></div>');
					images.after(arrowContainer);
					arrowContainer.append('<div class="new-arrow-left"></div>');
					arrowContainer.append('<div class="new-arrow-right"></div>');
					
					var titleBox = $('<div class="title">'+dataArray[0].imgcaption+'</div>');
					arrowContainer.after(titleBox);
					
					var thumbBox = '<table cellpadding="0" cellspacing="0"><tr><td align="left" width="30" valign="middle">'
					thumbBox += '<a href="#" class="arrowLeft">back</a>'
					thumbBox += '</td><td><div class="thumbs"><div class="wide">'
								
					thumbBox += '</div></div></td><td align="right" width="30" valign="middle"><a href="#" class="arrowRight">more</a></td></tr></table>'
					
					titleBox.after(thumbBox);
					
					for(var i=0;i < dataArray.length;i++){
						$('div.wide').append(
							'<div class="thumb" link="'+dataArray[i].img+'" label="'+dataArray[i].imgcaption+'"><img src="'+path+dataArray[i].thumb+'" imagelabel="'+dataArray[i].imgcaption+'"></div>'
						);
					};
					attachMobileGalleryEvents();



					/***************************************
					 *
					 * Bind Events for Main Gallery Type
					 *
					 *****************************************/
					$(document).ready(function(){
						var i = $('.images');
						var title = $('.title');
						var w = $('.wide');
						$('.thumb').hover(
							function(){
								$(this).addClass('hover');
							},
							function(){
								$(this).removeClass('hover');
							}
						).click(function(){
							var t = $(this);
							$('.thumb.active').removeClass('active');
							t.addClass('active');
									
							i.html('<div class="white"></div><img src="'+path+t.attr('link')+'">');
							title.html(t.attr('label'));
							var img = i.find('img');
							img.load(function(){
								setTimeout(function(){
									img.css({marginTop:(i.height() - img.height())/2});
								},0)
							});
								$('.white').stop(true,true).fadeOut({duration:1500,easing:'swing',complete:function(){
							}});
						});
						var hideShowArrows = function(){
							var wid = parseInt(w.css('marginLeft'));
							if(wid+''=='NaN')wid = 0;
							var n = wid-630;
							if(n<-w.width())
								$('.arrowRight').hide();
							else
								$('.arrowRight').show();	
							
							var wid = parseInt(w.css('marginLeft'));
							if(wid+''=='NaN')wid = 0;
							var n = wid- -630;
							if(n>0)
								$('.arrowLeft').hide();	
							else
								$('.arrowLeft').show();	
							
						}
						$('.arrowRight').click(function(){
					    	$('.thumbs').css({'text-align':'left'});
							var wid = parseInt(w.css('marginLeft'));
							if(wid+''=='NaN')wid = 0;
							var n = wid-630;
							if(n>-w.width())
							w.animate({marginLeft:n},{duration:800,easing:'swing',complete:hideShowArrows});
							return false;
						});
						$('.arrowLeft').click(function(){
							var wid = parseInt(w.css('marginLeft'));
							if(wid+''=='NaN')wid = 0;
							var n = wid- -630;
							if(n<=0)
							w.animate({marginLeft:n},{duration:800,easing:'swing',complete:hideShowArrows});
							return false;
						});
						$('.new-arrow-right').click(function(){
								var n = $('.active').next('.thumb');
								if(n.length==0)
									n = $('.thumb:first');
								n.click();
						});
						$('.new-arrow-left').click(function(){
								var n = $('.active').prev('.thumb');
								if(n.length==0)
									n = $('.thumb:last');
								n.click();
						});
						$('.thumb:first').addClass('active');
						$('.thumb:last img').load(function(){
							if(w.width()>$('.thumbs').width()){
								hideShowArrows();
							}
						}).each(function(){
							if(this.complete)
								$(this).trigger('load');
						});
						$('.images').swipe({
							swipeLeft: function() {
								var n = $('.active').next('.thumb');
								if(n.length==0)
									n = $('.thumb:first');
								n.click();
							},
							swipeRight: function() {
								var n = $('.active').prev('.thumb');
								if(n.length==0)
									n = $('.thumb:last');
								n.click();
							},
							swipeUp: function(){
							},
							swipeDown: function(){
							}
						});
					});
					
				}
			});
		}
	});

}

/*sub gallery load*/

function subGalleryLoad(){
aG.push({
	totalW: totalW,
	totalH: totalH,
	path: path
});

$(function(){
	if(loaded) return false;
	loaded = true;
	for(var p in aG){
		var gSlideshow = $('div.images:eq('+p+')')
		gSlideshow.data('mP',p);
		gSlideshow.height(aG[p].totalH);
			$.ajax({
				url: aG[p].path+'myimages.xml',
				dataType: 'xml',
				context: gSlideshow,
				success: function(data){
					var images = $(this);
					var mP = images.data('mP');
					var dataArray = [];
					$(data).find('data').each(function(){
						dataArray.push({img:$(this).attr('img'),imgcaption:$(this).attr('imgcaption'),thumb:$(this).attr('thumb'),link:$(this).attr('imgLink')});
					});
					//console.log(dataArray.length)
					images.append('<div class="image1"></div><div class="image2"></div><div class="shadow1"></div><div class="shadow2"></div><div class="title1"></div><div class="title2"></div>')

					var arrowContainer = $('<div class="new-arrow-container_sub"></div>');
					images.after(arrowContainer);
					arrowContainer.append('<div class="new-arrow-left"></div>');
					arrowContainer.append('<div class="new-arrow-right"></div>');
					
					var titleBox = $('<div class="title"></div>');
					arrowContainer.after(titleBox);
					
					var thumbBox = '<table cellpadding="0" cellspacing="0"><tr><td align="left" width="30" valign="middle">'
					thumbBox += '<a href="#" class="arrowLeft">back</a>'
					thumbBox += '</td><td><div class="thumbs"><div class="wide">'
								
					thumbBox += '</div></div></td><td align="right" width="30" valign="middle"><a href="#" class="arrowRight">more</a></td></tr></table>'
					
					titleBox.append(thumbBox);
					
					for(var i=0;i < dataArray.length;i++){
						$('div.wide').append(
							'<div class="thumb" link="'+dataArray[i].img+'" label="'+dataArray[i].imgcaption+'"><img src="'+path+dataArray[i].thumb+'" imagelabel="'+dataArray[i].imgcaption+'"></div>'
						);
					};
					attachMobileGalleryEvents();

					$('.galleryTitle').css({'height':'35px','visibility':'hidden'});
					$('#leftArrow').css({'position':'relative','left':'15px'});
					


					/*******************************
					 *
					 * Bind Events for Sub Gallery Type
					 *
					 *********************************/
					 $('.images').css('text-align','left');
					var w = $('.images .wide');
					$('.thumb').hover(
						function(){
							$(this).addClass('hover');
						},
						function(){
							$(this).removeClass('hover');
						}
					).click(function(){
						var t = $(this);
						var t2 = t.next('.thumb');
						if(t2.length==0)t2 = $('.thumb:first');
						$('.thumb.active').removeClass('active');
						t.addClass('active');
						
						$('.image1').html('<img src="'+path+t.attr('link')+'">');
						$('.image2').html('<img src="'+path+t2.attr('link')+'">');
				        $('.title1').html(t.attr('label'));
				        $('.title2').html(t2.attr('label'));
						$('.image1,.image2').stop(true,true).hide().fadeIn({duration:1500,easing:'swing'});
				        
				        
					});
					$('.new-arrow-right').click(function(){
							var n = $('.active').next();
							if(n.length==0)
								n = $('.thumb:first');
							n.click();
					});
					$('.new-arrow-left').click(function(){
							var n = $('.active').prev();
							if(n.length==0)
								n = $('.thumb:last');
							n.click();
					});
					
					$('.arrowRight').click(function(){
				    	$('.thumbs').css({'text-align':'left'});
						$('.thumbs .wide').animate({marginLeft:-505},{duration:800,easing:'swing'});
						return false;
					});
					$('.arrowLeft').click(function(){
						$('.thumbs .wide').animate({marginLeft:0},{duration:800,easing:'swing'});
						return false;
					});
					$('.thumb:first').click();
					$('.thumb:last img').load(function(){
				        if($('.thumbs .wide').width()>$('.thumbs').width()){
				            $('.arrowRight,.arrowLeft').fadeIn();
				        }
					}).each(function(){
						if(this.complete)
							$(this).trigger('load');
					});
				    
					$('.images').swipe({
						swipeLeft: function() {
							var n = $('.active').next();
							if(n.length==0)
								n = $('.thumb:first');
							n.click();
						},
						swipeRight: function() {
							var n = $('.active').prev();
							if(n.length==0)
								n = $('.thumb:last');
							n.click();
						},
						swipeUp: function(){
						},
						swipeDown: function(){
						}
					});
					
					if($('.thumb').length>2)
						$('.new-arrow-right,.new-arrow-left').fadeIn();
					
				}
			});
		}
	});

}




(function($) {
	$.fn.swipe = function(options) {
		
		// Default thresholds & swipe functions
		var defaults = {
			LRthreshold: {
				x: 150,
				y: 75
			},
			UDthreshold: {
				x: 75,
				y: 150
			},
			swipeLeft: function() { },
			swipeRight: function() { },
			swipeUp: function() { },
			swipeDown: function() { }
		};
		
		var options = $.extend(defaults, options);
		
		if (!this) return false;
		
		return this.each(function() {
			
			var me = $(this)
			
			// Private variables for each element
			var originalCoord = { x: 0, y: 0 }
			var finalCoord = { x: 0, y: 0 }
			
			// Screen touched, store the original coordinate
			function touchStart(event) {
				console.log('Starting swipe gesture...')
				originalCoord.x = event.targetTouches[0].pageX
				originalCoord.y = event.targetTouches[0].pageY
			}
			
			// Store coordinates as finger is swiping
			function touchMove(event) {
			    event.preventDefault();
				finalCoord.x = event.targetTouches[0].pageX // Updated X,Y coordinates
				finalCoord.y = event.targetTouches[0].pageY
			}
			
			// Done Swiping
			// Swipe should only be on X axis, ignore if swipe on Y axis
			// Calculate if the swipe was left or right
			function touchEnd(event) {
				console.log('Ending swipe gesture...')
				var changeY = originalCoord.y - finalCoord.y
				var changeX = originalCoord.x - finalCoord.x
				if(changeY < defaults.LRthreshold.y && changeY > (defaults.LRthreshold.y*-1)) {
					
					if(changeX > defaults.LRthreshold.x) {
						defaults.swipeLeft();
						return false;
					}
					if(changeX < (defaults.LRthreshold.x*-1)) {
						defaults.swipeRight();
						return false;
					}
				}
				if(changeX < defaults.UDthreshold.x && changeX > (defaults.UDthreshold.x*-1)) {
					
					if(changeY > defaults.UDthreshold.y) {
						defaults.swipeUp();
						return false;
					}
					if(changeY < (defaults.UDthreshold.y*-1)) {
						defaults.swipeDown();
						return false;
					}
				}
			}
			
			// Swipe was canceled
			function touchCancel(event) { 
				console.log('Canceling swipe gesture...')
			}
			
			// Add gestures to all swipable areas
			if(this.addEventListener){
				this.addEventListener("touchstart", touchStart, false);
				this.addEventListener("touchmove", touchMove, false);
				this.addEventListener("touchend", touchEnd, false);
				this.addEventListener("touchcancel", touchCancel, false);
			}
				
		});
	};
})(jQuery);




/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);

/****************************************
 * 
 * Title:	Sitemap Generator v0.1
 * Author:	Derek Bredensteiner
 * Date: 	07/21/2011
 * 
 * Description:
 * 			- Based on the sitemap.json that's now standardly published across all sites
 * 			- Generates a table styled like the old sitemap tables
 * 			- Was originally written for rosewood, caneel bay
 *
 * Usage/HTML:
 *
 *		<!--- Provide a target element, and trigger the function --->
 *		<div id="sitemap"></div>
 *		<script>loadSiteMap();</script>
 *
 ****************************************/
function loadSitemap(){
  $(function(){
	$.ajax({
		url: '/en/i/'+siteid+'/sitemap.json?'+new Date()+Math.random(),
		datatype: 'jsonp',
		cache: false,
		success:function(pages){

			var getByParent = function(id){
				for(var i in pages){
					if(pages[i].PARENTID==id) return pages[i];
				} return false;
			}
			var getById = function(id){
				for(var i in pages){
					if(pages[i].PAGEID==id) return pages[i];
				} return false;
			}
			String.prototype.repeat = function( num )
			{
			    return new Array( num + 1 ).join( this );
			}


			
			var level = -1;
			var addChildren = function(id){
				level++;
				for(var i in pages){
					if(pages[i].PARENTID==id){
						
						if(document.location.href.match(/\?task\=builder&pageid=/i))
							pages[i].HREF = '?task=builder&pageid='+pages[i].PAGEID;
						

						var $tr =
							(level==0
								?'<tr class="cell-light">'
								:'<tr class="cell-dark">')
								+'<td>'
									+' '.repeat(level*4)
									+'<a href="'+pages[i].HREF+'">'
										+(level==0
											?pages[i].NAV_LABEL.toUpperCase()
											:pages[i].NAV_LABEL)
									+'</a>'
								+'</td>'
							+'</tr>'

						$table.append($tr);

						addChildren(pages[i].PAGEID,$table);

					}
				}
				level--;
			}
			var $table = $('<table width="100%" cellpadding="3"></table>');
			$('#sitemap').append($table);

			addChildren(getByParent('').PAGEID,$table)

		}
	});
  });
}

$(document).ready(function(){
    $('a[href^="https://gc.synxis.com/rez.aspx"],a[href^="http://gc.synxis.com/rez.aspx"]').click(function (event) {
		if(!isUAMobile){
			SynLink($(this).attr('href'));
		}else{
			SynMobile($(this).attr('href'));
		}
        event.preventDefault();
    });
});

function SynLink(theSpecialsUrl){
    _gaq.push(function() {
            var tracker = _gat._getTrackerByName(); 
            window.open(tracker._getLinkerUrl(theSpecialsUrl));
         });
     }
function SynMobile(theSpecialsUrl){
	var urlArray = theSpecialsUrl.split('?')
	var newURL = 'https://m.synxis.com/18150/?' + urlArray[1];
    _gaq.push(function() {
            var tracker = _gat._getTrackerByName(); 
            window.open(tracker._getLinkerUrl(newURL));
         });
     }
/* Make PDF links without new windows, have new windows */ 
$(function(){$('a[href$=pdf][target!=_blank]').attr('target','_blank')})

/****************** Google Maps ******************/

function loadMap() 
			{
				var propName = "Rosewood Mayakoba";
				var propAddress = "Carretera Federal Cancun-Playa del Carmen km 298 77710 Solidaridad, Quintana Roo, Mexico";
				var propPhone = "52.984.875.8000";
				var propLat = "20.690126";
				var propLng = "-87.023077";
				var propZoom = 9;
				
				var rwICON = '/en/mayakoba/i/SITE_110613_12185636_LLX10/templates/RosewoodMarker.png';
				
				//var myMapHolder		=	document.getElementsByClassName('map');
				var myMapLink		=	document.getElementById('mapLink');
				var myMapHolder		=	document.getElementById('GoogleMap');
				//create an lat/lng pair to center the map on
				var myLatlng = new google.maps.LatLng(propLat, propLng);
				//establish the map params
				var myOptions = {
					zoom: propZoom,
					center: myLatlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				}
				
				//load the HTML contentpropLat + ',' + propLng
				var contentString = '<div id="content"><strong>' + propName + '</strong><br/>' + propAddress + '<br/>' + '<a tel="' + propPhone + '">' + propPhone + '</a>' + '<hr>' + '<a href="http://maps.google.com/maps?daddr=' + propAddress +'" target="_blank">Directions</a>' + '</div>';
				//load up the info window
				var infowindow = new google.maps.InfoWindow({
					content: contentString
				});
			
				//declare the map var and apply it to the HTML doc
				var map = new google.maps.Map(myMapHolder, myOptions);
				
				var marker = new google.maps.Marker({
					position: myLatlng,
					map: map,
					title: propName,
					icon: rwICON
				});
				
				google.maps.event.addListener(marker, 'click', function() {
     				infowindow.open(map,marker);
    			});
				// load the map link
				if($('#mapLink'))
					{
						var tempLink = 'http://maps.google.com/maps?q=' + propAddress;
						$('#mapLink').attr('href',tempLink);
					}
			}
$(document).ready(function(){
if($('#GoogleMap').length > 0)
	{
		loadMap();
	}
});
