//**********************************************************************
// This script is used to manipulate the appearance of aggregated hotel
// data which has been pulled from Vignette and other sources.  Any page
// which uses this script must also include AEVCommons.js and
// jquery.aev.js.
//**********************************************************************

var hi_layoutImagePath = "/images/layout/";
var hi_hotelImagePath = "/images/hotel/";
var hi_photoToolTip = null;



$(function() {
    
    //Load Trip Advisor
	loadTripAdvisor(hi_destHotelCode);
				

	//Load Google map
	if (hi_mapCoordinates != null && hi_mapCoordinates != undefined && hi_mapCoordinates != "") {
		loadHotelMap("googleMap", hi_mapCoordinates, 320, 320);
	}
	else {
		$("#googleMap").html("<span style='font-weight:bold; color:#FF6600;'>We're sorry!  No map is available for this property.</span>");
	}
    
	
    //Load photo gallery
	if (hi_photoGallery != null && hi_photoGallery != undefined) {
		loadPhotoGallery();
	}
	
		
	$(".ratingImg").click(
        function(event){                  
        	popUp("/aev/pages/static/Ratings.html",600,450,"hotelRating","menubar=no,toolbar=no,resizable=0");
    });
      
    
    
	$("#photos .thumbImage").hover(
    	function(){    		
    		var idx = $(this).attr('id');
			$('#srcPhoto').attr('src', hi_layoutImagePath + 'mt.gif');
			$('#photoSpan').html('Loading...');
			
			if (hi_photoGallery && hi_photoGallery[idx]) {
				$('#srcPhoto').attr('src', hi_photoGallery[idx].src);
				$('#srcPhoto').attr('width', hi_photoGallery[idx].width);
				$('#srcPhoto').attr('height', hi_photoGallery[idx].height);
				
				hi_photoToolTip = new AEVToolTip('photoFrame',{
					width: $('#srcPhoto').attr('width'),
					height: $('#srcPhoto').attr('height'),
					offsetX: 0,
					offsetY: -$("#photos").height(),
					//offsetY: 0,
					alwaysVisible: true
					});
				hi_photoToolTip.show();
				
				$('#photoSpan').html($('#pCaption'+idx).html());				
			}
		},
		function(){			
			if (hi_photoToolTip != null) {
				hi_photoToolTip.hide();
			}
			hi_photoToolTip = null;
	});
    
});



function loadTripAdvisor(destHotelCode) {    
    var taContent = '<iframe src="' + TRIP_ADVISOR_URL + destHotelCode + '" width="240" height="320" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
    $("#tripAdvisor").html(taContent);
}



function loadPhotoGallery() {
	var imgList = new Array();
	
	if (hi_photoGallery) {
		for (var i=0; i<hi_photoGallery.length; i++) {
			var newImg = new Image();
			newImg.src = hi_photoGallery[i];
			imgList[imgList.length] = newImg;
		}
	}
	
	hi_photoGallery = imgList;
}