//**********************************************************************
// This script is used to manipulate the data content which appears
// on promotion pages.  Any page which uses this script must also 
// include AEVCommons.js.
//**********************************************************************

var pr_promoImagePath = "/images/promotions/";



$(function() {
	
	$("#hideErrorBox").click(
        function(event){
        	$("#errorBox").toggle();        	      
    });
	
		
	
	$("#tabs .tabImage").mouseover(
        function(){            
        	if (! $(this).is(".navSelected")) {
                $(this).attr("src", pr_promoImagePath + "aev_ppr_tab_" + $(this).attr("id").substring(0, $(this).attr("id").length-3) + "_o.gif");
            }            
        }).mouseout(
        function(){
            if (! $(this).is(".navSelected")) {
                $(this).attr("src", pr_promoImagePath + "aev_ppr_tab_" + $(this).attr("id").substring(0, $(this).attr("id").length-3) + "_b.gif");
            }            
    });
    
    
    
    $("#tabs .tabImage").click(
        function(event){        	
        	if (! $(this).is(".navSelected")) {                
                var prevSelection = $("#tabs .navSelected");
                var prevIDPrefix = $(prevSelection).attr("id").substring(0, $(prevSelection).attr("id").length-3);
                var newIDPrefix = $(this).attr("id").substring(0, $(this).attr("id").length-3);
                                
                $(prevSelection).attr("src", pr_promoImagePath + "aev_ppr_tab_" + prevIDPrefix + "_b.gif");
                $(prevSelection).removeClass("navSelected");      
                $(this).addClass("navSelected");
                
                $("#" + prevIDPrefix).toggle();
                $("#" + newIDPrefix).toggle();
                
                if (prevIDPrefix == "promotiondetails") {
                    hidePromoView();
                }
                else if (newIDPrefix == "promotiondetails") {
                	showPromoView();
                }
            }            
    });
    
    
    
    $(".hotelRatingImg").click(
        function(event){                  
        	popUp("/aev/pages/static/Ratings.html",600,450,"hotelRating","menubar=no,toolbar=no,resizable=0");
    });
})



function scaleImages(imageArray, maxWidth) {	
	$(imageArray).each(
		function(i) {
			if ($(this).width() > maxWidth) {                
				var imgSrc = $(this).attr("src");
				var imgWrapper= $(this).closest(".scalableImageWrapper");	
				imgWrapper.attr("style", "width:" + maxWidth +  "px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "',sizingMethod='scale');");
				$(this).attr("style", "filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);");
				$(this).width(maxWidth);
			}
    });
}



function showPromoView() {
	//Images can only be manipulated if they are visible on the screen
	scaleImages($("#promoImageBox #promoImage"), 300);
    scaleImages($("#promoLogos .scalableImage"), 100);
    scaleImages($("#extraPromoImages .scalableImage"), 320);
    
	$("#termsConditions").show();
    $("#bottomCorners").removeClass("dataFrameBottom");
    $("#bottomCorners").addClass("dataFrameBottomGray"); 
}



function hidePromoView() {
	$("#termsConditions").hide();
    $("#bottomCorners").removeClass("dataFrameBottomGray");
    $("#bottomCorners").addClass("dataFrameBottom"); 
}