//home carousel animation
//usage: home-page carousel
function homeCarousel(totalSlideCount, currentImageNum) {
    $("#carousel").cycle({ 
		fx: 'fade',
        timeout: 5000, 
		speed: 1500,
        before: onBefore 
    }); 

    function onBefore(curr, next, opts) { 
        // on the first pass, addSlide is undefined (plugin hasn't yet created the fn); 
        // when we're finshed adding slides we'll null it out again 
        if (!opts.addSlide) 
            return; 
 
        // on Before arguments: 
        //  curr == DOM element for the slide that is currently being displayed 
        //  next == DOM element for the slide that is about to be displayed 
        //  opts == slideshow options 
             
//	        var currentImageNum = parseInt(next.src.match(/_HOLDING_carousel-(\d)/)[1]); 

       	currentImageNum++;  
             
        if (currentImageNum == totalSlideCount) { 
            // final slide in our slide slideshow is about to be displayed 
            // so there are no more to fetch 
            opts.addSlide = null; 
            return; 
        } 
         
        // add our next slide 
        opts.addSlide("<img src=\"/uploadedimages/Maybourne/images/homeimage_732x789/" + homeImgs[currentImageNum] + "\" width=\"732\" height=\"789\" alt=\"\" />");
    }; 
}

//image carousel animation
//usage: any sub-page carousel
function imageCarousel(slideLayer, slideHeight) {
	$("#"+ slideLayer + "").innerfade({ 
		speed: 1500, 
		timeout: 5000, 
		type: "random_start", 
		containerheight: slideHeight 
	});
}

//calendar initialization
function interactiveCalendar(elementID) {
	$("#" + elementID).datepicker({
		showOn: "both", 
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		altField: "#" + elementID,
		altFormat: "dd/mm/yy", 
		prevText: "&laquo;&laquo;", 
		nextText: "&raquo;&raquo;"
	});
}

//animated overlay on homepage
function homeBox() { 
	$("#overlay-opacity").css({"marginTop" : "0px", "height" : "33px"});
	$("#overlay-content").hide();
	$("A#overlay-show").toggle(function(){
		$("A#overlay-show").hide();
		$("#overlay-opacity").animate({marginTop: "-163px", height: "197px" }, {queue: false,duration:500});
		setTimeout('$("DIV#overlay A#overlay-show").removeClass("off").addClass("on");', 500);
		setTimeout('$("DIV#overlay").removeClass("off-overlay").addClass("on-overlay");', 500);
		setTimeout('$("A#overlay-show").show();', 500);
		setTimeout('$("#overlay-content").show();', 500);
	}, function() {
		$("A#overlay-show").hide();
		$("#overlay-content").hide();
		$("#overlay-opacity").animate({marginTop: "0px", height: "33px" }, {queue: false,duration:500});
		setTimeout('$("#overlay-opacity").show();', 500);
		setTimeout('$("DIV#overlay").removeClass("on-overlay").addClass("off-overlay");', 500);
		setTimeout('$("A#overlay-show").removeClass("on").addClass("off");', 500);
		setTimeout('$("A#overlay-show").show();', 500);
	});	
}

//calendar slide-in - all pages except homepage
function launchBookingEngine() { 
	$("A#launch-booking").attr({"href" : "#"});
	$("A#launch-booking").toggle(function(){
		$("#check-availability").animate({marginTop: "0px" },{queue: false,duration:400});
		if ($.browser.msie && $.browser.version == 6) {
			$("#tblBE TBODY TR TD SELECT").fadeIn("fast");
		}
		setTimeout('$("#booking-engine").css({"backgroundColor" : "#c8c6b7"});', 400);
		setTimeout('$("#booking-engine-table").fadeIn("fast");', 400);
	}, function() {
		if ($.browser.msie && $.browser.version == 6) {
			$("#tblBE TBODY TR TD SELECT").fadeOut("fast");
		}
		$("#booking-engine-table").fadeOut("slow");
		setTimeout('$("#booking-engine").css({"backgroundColor" : "transparent"});', 500);
		setTimeout('$("#check-availability").animate({marginTop: "183px" },{queue: false,duration:1500});', 500);
	});	
}

/*
//show refinement options for careers section
function careerRefine() { 
	$("#search-refine DIV P A").click(function(){
		$("#refine-hotel-cta-options").hide();
		$("#refine-aow-cta-options").hide();
		$("#" + this.id + "-options").show();
	});	
}

//animated overlay on homepage
function OLD_homeBox() { 
	$("A#overlay-show").toggle(function(){
		$("A#overlay-show").hide();
		$("#overlay-opacity").removeClass("off").addClass("on");
		$("#overlay").show("slide", { direction: "down" }, 1500);
		$("#overlay-opacity").show("slide", { direction: "down" }, 1500);
		setTimeout('$("A#overlay-show").removeClass("off").addClass("on");', 1500);
		setTimeout('$("A#overlay-show").show();', 1500);
		setTimeout('$("#overlay-content").show();', 1500);
		setTimeout('$("#overlay").removeClass("off").addClass("on");', 1500);
	}, function() {
		$("A#overlay-show").hide();
		$("A#overlay-show").removeClass("on").addClass("off");
		$("#overlay-content").hide();
		$("#overlay").removeClass("on").addClass("off");
		$("#overlay-opacity").hide("slide", { direction: "down" }, 1500);
		setTimeout('$("#overlay-opacity").removeClass("on").addClass("off");', 1500);
		setTimeout('$("#overlay-opacity").show();', 1500);
		setTimeout('$("A#overlay-show").show();', 1500);
	});	
}
*/

/*
//remove iframe scrollbars in Safari, Opera & Chrome that are inherited from HTML styles in layout.css
//usage: used in any page loaded in iframe NOT page containing iframe
function hideIframeScrollbars() {
	$("HTML").css("overflow-y", "hidden");
	$("HTML").css("overflow-x", "hidden");
}

function iFrameResize() {
	$(document).ready(function(){
		var frameHeight = $(document).height();
		frameHeight = parseInt(frameHeight) + parseInt(20);
//		alert("doc height: " + frameHeight);
		$("IFRAME#careers-frame",top.document).attr({"height" : frameHeight});
//		alert("re-calc size: " + frameHeight);
//		$("INPUT#frameHeightMaster",top.document).val(frameHeight);
//	    var mainHeight = $("INPUT#frameHeightMaster",top.document).val();
//		alert(parseInt(mainHeight));
//		alert(parseInt(mainHeight));
		hideIframeScrollbars();
	});
}

//Three functions for careers section iFrame integration START
//get height of iframe body and populate hidden input in parent loader
//usage: used in any page loaded in iframe NOT page containing iframe
function getFrameHeight() {
	$(document).ready(function(){
		var frameHeight = $(document).height();
		alert(frameHeight);
		$("INPUT#frameHeightMaster",top.document).val(frameHeight);
	});
}

//retrieves height for iframe from hidden input and sets iframe height on-the-fly
//usage: used in careers section to auto-adjust height of iframed content/pages. 
//usage: used with a 1 second Timeout to give server-side code chance to process + render in iframe
function callIframe() {
    var mainHeight = $("INPUT#frameHeightMaster",top.document).val();
//	alert(parseInt(mainHeight));
	mainHeight = parseInt(mainHeight) + parseInt(20);
//	alert(parseInt(mainHeight));
	$("IFRAME#careers-frame",top.document).attr({"height" : mainHeight});
}
*/


