$(function() {
	//Documentation located in special.docs.js
	
	// Calculating the offset amount for the navigation dropdowns
	$('#nav-primary > *').not('.last').each(function(){
		if($(this).children('ul').length) {
			var subnav = $(this).children('ul');
			var offset = Math.round(((subnav.width()) - ($(this).width())) / 2);
			offset = offset * -1;
			subnav.css("margin-left",offset);
		}
	});
	
	// Booking console - Check availability promo code click button
	$("form#reservations-console").each(function(){
		var x = $(this);
		$("a#promo-click", x).click(function(){
			$("#dropdown-fields",x).show();
			return false;
		});
		$("#extra-fields-close").click(function() {
			$("#dropdown-fields",x).hide();
			return false;
		});
	});
	$("#promo-done-btn").click(function(){
		$("#dropdown-fields").hide();
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$("#promo-click").addClass("selected-promo-click");
		} else {
			$("#promo-click").removeClass("selected-promo-click");
		}
		return false;
	});
	
	//add class last to the last push item
	$('.side-push:last').addClass("last");
	
	//accommodations rooms listing images lightbox and misc
	$('.room-listing:last').css("border","none");
	  
	  
	  
	  
	  
	 //this is a custom open and close, it resets the image to the loading gif to prevent old images sticking visually and calculates the absolute positon for the modal	  
	var openFn=function(hash){
		hash.w.show();
		var leftPos = ($(window).width()-$('#modal-room-photo').width())/2;
		var topPos = $(window).scrollTop();
		$('#modal-room-photo').css({left:leftPos,top:topPos});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('#room-photo-large').attr("src", "/images/loadingAnimation.gif");
	};  

	$('#modal-room-photo').jqm({onShow: openFn, onHide: hideFn});	
	$('.enlarge-photo-toggle').click(function(){
		var imgName = $(this).attr('href').replace("#","");
		var imgPath = "/images/accommodations/large/" + imgName + ".jpg";
		$('#room-photo-large').attr("src", imgPath);
		$('#modal-room-photo').jqmShow();
	});
	
	
});

// resizing flash sign up on expand/collapse
function resizeSwf(size) {
	if ( size == 46 ) {
		$("div#console-sign-up").css("height","30px");
	} else {
		$("div#console-sign-up").css("height","269px");
	}
}

