// Default JS Content - Do Not Delete

//new booking mask
	
$(document).ready(function(){
//dialog init
 	$('.headerlink').load('/i/SITE_110425_10020784_QJHP1/tagLine.cfm', function(e) {
		$('#tagLines').cycle({ 
    		fx:    'scrollRight', 
    		delay: -1100 
		});
	});

	$('.formSubmit').val('Submit');
					
	$("#pressDialog").dialog({
              bgiframe: true,
	      modal: true,
	      autoOpen: false,
	      height:600,
	      width:650,
	      show: "fold",
	      position:"center",
	      buttons: {"Thank You": function() {$(this).dialog("close");}}
         });


	$("#dialog").dialog({
	     bgiframe: true,
	     modal: true,
	     autoOpen: false,
 	     height:160,
	     width:350,
	     show: "fold",
	     position:"center",
	     close: function(){$('#'+$('#putFocus').val()).focus();},
 	     buttons: {"Thank You": function() {$(this).dialog("close");}}
	});
			 
	$('a.pressDetails').click(function(e) {
	     $('#pressDialog').load('/i/SITE_110425_10020784_QJHP1/pressDetails.cfm?prID='+$(this).attr("id")+'',function() {
		$("#pressDialog").dialog('open');
	     });
	return false;
        });
//calendar code

		$("#Arrival").datepicker({
			minDate:0,
			showAnim: "fadeIn",
			showOn: 'both',
			buttonText: 'Select Check In Date',
			buttonImage: '/i/SITE_110425_10020784_QJHP1/templates/cal.gif',
			buttonImageOnly: true,
			onSelect:function(theDate) {
				$("#Depart").datepicker('option','minDate',addDays(new Date(theDate),1))
				if(($("#Depart").datepicker( 'getDate' )===null)||(trim($("#Depart").datepicker( 'getDate' ))=="")||(comparedate($("#Arrival").datepicker( 'getDate' ),$("#Depart").datepicker( 'getDate' )))){
					$("#Depart").datepicker('setDate' ,addDays(new Date(theDate),1))
				}
			}
		});
 $("#Arrival").datepicker('setDate',addDays(new Date(),1));
		$("#Depart").datepicker({
			minDate:1,
			showAnim: "fadeIn",
			showOn: 'both',
			buttonText: 'Select Check Out Date',
			buttonImage: '/i/SITE_110425_10020784_QJHP1/templates/cal.gif',
			buttonImageOnly: true,
			defaultDate: +1,
			gotoCurrent: true
		});
 $("#Depart").datepicker('setDate',addDays(new Date(),2));
//homepage mouseovers
	//homepage mouseovers set up
              $('.homeHover').each(function(i) {
	//console.log($(this).find(".photoBtn img").attr('src'));
	$(this).css({
			'backgroundImage':'url('+$(this).find(".photoBtn img").attr('src')+')',
			'height':'150px',
			'width':'275px'
	});
	$(this).children('.photoLbl').wrapAll('<a href='+$(this).children(".photoBtn").children("a").attr("href")+' class="hook"></a>');
	$(this).before('<div class="dropShadow"></div>');
        $(this).find('.photoBtn img').remove();
	if(i == $('.homeHover').length -1){
	      $(this).after("<div class='clearButtons'></div>")	
	}
});
$('a.hook').css({'display': 'none'});
//homepage mouseovers
       $('.homeHover').hoverIntent(function() {	
		$(this).children('.hook').stop(true,true).fadeIn('slow');
       },function(){
		$(this).children('.hook').stop(true,true).fadeOut('slow');
       });
	
       $('a.hook').live('mouse',function(){
	   //$(this).remove();
        });
//----------	
//subpage mouseovers
	$('.subHover').each(function(i) {
		$(this).css({
				'backgroundImage':'url('+$(this).find(".subphotoBtn img").attr('src')+')',
				'height':'97px',
				'width':'178px'
		});
		$(this).children('.subphotoLbl').wrapAll('<a href='+$(this).children(".subphotoBtn").children("a").attr("href")+' class="subhook"></a>');
		$(this).before('<div class="dropShadow"></div>');
                $(this).find('.subphotoBtn img').remove();
		if(i == $('.subHover').length -1){
			$(this).after("<div class='clearButtons'></div>")	
		}
	});
$('a.subhook').css({'display': 'none'});
//homepage mouseovers
	$('.subHover').hoverIntent(function() {
		$(this).children('.subhook').fadeIn('slow');
		//$(this).children('.subhook').stop().animate({opacity:'1'},{queue:false,duration:250}); 
	},function(){
		$(this).children('.subhook').fadeOut('slow');
		//$(this).children('.subhook').stop().animate({opacity:'0'},{queue:false,duration:250});
	});//----------
//load weather
	$('#weather').load('/weather.cfm');

});
/*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;
	}
}
function trim(stringToTrim) {
	return stringToTrim.toString().replace(/^\s+|\s+$/g,"");
}



/*validate home email form*/
function validateEmail(oForm) {
        if(!isEmailAddr(trim(oForm.form1_1003.value))){
	     $('#dialog').html("<input type='hidden' id='putFocus' value='form1_1003' /><div style='padding:10px 3px; color:#3E703B;'>Please enter a valid email address before proceeding</div>");
	     $('#dialog').dialog("open");
	     return false;
	}
	return true;
}


function isEmailAddr(str) {
    var re  = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9-])+(\.[a-zA-Z0-9_-]+)+$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}




var buffer = false;
var loaded = false;
var thumbnails = true;
var aG = [];
function loadGallery(usethumbs){
	if(usethumbs == 'false') {
		thumbnails = false;	
	}
aG.push({
	totalW: totalW,
	totalH: totalH,
	path: path
});
$(function(){
	if(loaded) return false;
	loaded = true;
	for(var p in aG){
		var gSlideshow = $('div.slideshow: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 slideshow = $(this);
				var mP = slideshow.data('mP');
				var dataArray = [];
				$(data).find('data').each(function(){
					dataArray.push({img:$(this).attr('img'),imgcaption:$(this).attr('imgcaption'),thumb:$(this).attr('thumb')});
				});
				slideshow.append(
					'<img src="'+aG[mP].path
					+dataArray[0].img
					+'" imagelabel="'
					+dataArray[0].imgcaption
					+'" style="position: absolute;display: none; ">'
				);
				if(thumbnails){
					var thumbs = $('<div class="thumbnails"></div>');
					slideshow.after(thumbs);
					thumbs.append(
						'<img src="'+aG[mP].path
						+dataArray[0].thumb.replace(/_c/,'_bw')
						+'">'
					);
					var nt = $('.thumbnails img');
					nt.addClass('active').attr('src',nt.attr('src').replace(/(_bw|_b|_c)\./,'_c.'));;
					thumbs.before('<div class="descriptionText"></div>');
				}
				var loaded = false;
				dataArray.shift();
				/* As soon as the first image is loaded, we may begin */
				slideshow.find('img:first').load(function(){
					if(loaded) return false;
					loaded = true;
$(window).resize();
					for(var i in dataArray){
						slideshow.append(
							'<img sr'+'c="'+aG[mP].path
							+dataArray[i].img
							+'" imagelabel="'
							+dataArray[i].imgcaption
							+'" style="position: absolute;display: none; ">'
						);
						if(thumbnails){
							thumbs.append(
								'<img src="'+aG[mP].path
								+dataArray[i].thumb.replace(/_c/,'_bw')
								+'">'
							);
						}
					}
					
					if(thumbs){
						thumbs.append('<br style="clear:both;" />');
						$('.thumbnails img').hover(function(){
							var $t = $(this);
							$t.attr('src',$t.attr('src').replace(/(_bw|_b|_c)\./,'_b.'));
						},function(){
							var $t = $(this);
							if($t.hasClass('active'))
								$t.attr('src',$t.attr('src').replace(/(_bw|_b|_c)\./,'_c.'));
							else
								$t.attr('src',$t.attr('src').replace(/(_bw|_b|_c)\./,'_bw.'));
						}).click(function(){
							var $t = $(this);
							if($t.hasClass('active'))
								return false;
							var i = $t.prevAll('img').length;
							pause();
							nextSlide('.slideshow img:eq('+i+')');
						});
					}
					
					/* Variables */
					var transitionTime = 4200;
					
					/* Show First Image / Gallery / Hide Play Button */
					var n = slideshow.find('img:first');
					$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
					n.show();
					if(buffer){
						$('.buffer').css({
							'height':n.height(),
							'width':n.width(),
							'margin-left' : (aG[mP].totalW-n.width())/2,
							'margin-top' : (aG[mP].totalH-n.height())/2
						}).fadeOut(1000,function(){
							n.css('z-index','5');
							$('.buffer').show();
						});
						n.css({
							position : 'absolute',
							'margin-left' : (aG[mP].totalW-$(this).width())/2,
							'margin-top' : (aG[mP].totalH-$(this).height())/2
						});
					}
					
					$('.play').hide();
					var nextSlide = function(next){
						var f = slideshow.find('img:visible');
						if(next){
							var n = $(next);
						}else{
							var n = slideshow.find('img:visible').next('img');
							if(n.length==0) n = slideshow.find('img:first');
						}
						/* Make sure the next image is loaded before proceeding (don't worry, the loop event will re-fire) 
						if(!n[0].complete) return false;*/
						
						if(thumbs){
							var i = n.prevAll('img').length;
							var nt = $('.thumbnails img:eq('+i+')');
							var pt = $('.thumbnails img.active');
							pt.removeClass('active').attr('src',pt.attr('src').replace(/(_bw|_b|_c)\./,'_bw.'));
							nt.addClass('active').attr('src',nt.attr('src').replace(/(_bw|_b|_c)\./,'_c.'));;
						}
						
						/* Buffered Animation */
						if(buffer){
							$('.buffer').css({
								'z-index':'4',
								'height':f.height(),
								'width':f.width(),
								'margin-left' : (aG[mP].totalW-f.width())/2,
								'margin-top' : (aG[mP].totalH-f.height())/2
							});
							f.css('z-index','5').fadeOut(600,function(){
								$('.buffer').animate({
									'height':n.height(),
									'width':n.width(),
									'margin-left' : (aG[mP].totalW-n.width())/2,
									'margin-top' : (aG[mP].totalH-n.height())/2
								},300,'swing',function(){
									n.css({
										position : 'absolute',
										'margin-left' : (aG[mP].totalW-$(this).width())/2,
										'margin-top' : (aG[mP].totalH-$(this).height())/2,
										'z-index' : 3
									}).show();
									/* Alter Text */
									$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
									
									$('.buffer').fadeOut(1000,function(){
										n.css('z-index','5');
										$('.buffer').show();
									});
								});
							});
						}else{
							/* Non Buffered Animation */
							f.css('z-index',5);
							n.css('z-index',4).show();
								f.fadeOut(800,function(){
									$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
								},'swing');
						}
					};
					var looping=true;
					var t = setTimeout(function(){beginLoop();},transitionTime);
					var beginLoop = function(){
						nextSlide();
						t = setTimeout(function(){beginLoop();},transitionTime- -800);
					};
					var play = function(){
						clearTimeout(t);
						$('.play').hide();
						$('.pause').show();
						beginLoop();
					};
					var pause = function(){
						clearTimeout(t);
						$('.play').show();
						$('.pause').hide();
						slideshow.find('img').stop(true,true);
					};
					$('.play').click(play);
					$('.pause').click(pause);
					$('.next').click(function(){nextSlide();play();});
				/* If the image is loaded from cache, the load event doesn't fire, this checks if it's already loaded and the load event missed */
				}).each(function(){
					if(this.complete) $(this).trigger("load");
				});
			}
		});
	}
});
}


$(document).ready(function(){
	$('a[href^="https://booking.ihotelier.com/istay/istay.jsp"]').click(function (event) {
		IHLink($(this).attr('href'));
		event.preventDefault();
	});
});

function IHLink(theURL){
	_gaq.push(function() {
        	var tracker = _gat._getTrackerByName(); 
        	window.open(tracker._getLinkerUrl(theURL));
     	 });
}

function postForm(oForm){
var qs = "";
	qs = qs + "?hotelid="	+ oForm.hotelid.value;
	qs = qs + "&datein=" 	+ oForm.dateIn.value;
        qs = qs + "&dateout=" 	+ oForm.dateOut.value;
	qs = qs + "&Adults=" 	+ oForm.adults.value;
	qs = qs + "&Children=" 	+ oForm.children.value;
	 _gaq.push(function() {
        	var tracker = _gat._getTrackerByName(); 
			window.open(tracker._getLinkerUrl('https://booking.ihotelier.com/istay/istay.jsp' + qs));
     	 });
	 return false;
	}



