(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	if ( $.browser.msie && parseInt($.browser.version) === 6 ) {
		s = $.extend({
			top     : 'auto',
			left    : 'auto',
			width   : 'auto',
			height  : 'auto',
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};
})(jQuery);

var first_load=0;
var hotel_html= new Array();
var hotel_lng= new Array();
var hotel_lat= new Array();

var nbcity_html= new Array();
var nbcity_lng= new Array();
var nbcity_lat= new Array();

var nbair_html= new Array();
var nbair_lng= new Array();
var nbair_lat= new Array();

    function initialize() {
      if (GBrowserIsCompatible()) {
		  
		var cnt_pos=$("div#gog_city_center").html();

		var cnt_name=$("#gog_city_name").html();
		var cnt_icon="_greenC";
		var gog_city_center=cnt_pos.split("^");
        var map2 = new GMap2(document.getElementById("map_canvas_2"));
        map2.setCenter(new GLatLng(gog_city_center[1], gog_city_center[0]), 11);
        map2.addControl(new GSmallMapControl());
        map2.addControl(new GMapTypeControl());

 		var point = new GLatLng(gog_city_center[1], gog_city_center[0]);
 		map2.addOverlay(new GMarker(point));
		

      }
    }

	
function mapsLoaded(){
	var map = new GMap2(document.getElementById("map_canvas"));
  	map.setUIToDefault();
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	function createMarker(point, type, html) {
		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "http://www.google.com/mapfiles/marker"+type+".png";
		markerOptions = { icon:letteredIcon };
		var marker = new GMarker(point, markerOptions);
			if (html!="null"){
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("<div class='gog_bub'>"+html+"</div>");
			});
		}
		return marker;
	}
	if ($("div#gog_hosp_center").html()){
		var cnt_pos=$("div#gog_hosp_center").html();
		var cnt_name=$("#gog_hosp_name").html();
		var cnt_icon="_greenH";
	}
	else if ($("div#gog_city_center").html()){
		var cnt_pos=$("div#gog_city_center").html();
		var cnt_name=$("#gog_city_name").html();
		var cnt_icon="_greenC";
	}
	else if ($("div#gog_lmark_center").html()){
		var cnt_pos=$("div#gog_lmark_center").html();
		var cnt_name=$("#gog_lmark_name").html();
		var cnt_icon="L";
	}
	else if ($("div#gog_air_center").html()){
		var cnt_pos=$("div#gog_air_center").html();
		var cnt_name=$("#gog_air_name").html();
		var cnt_icon="_purpleA";
	}
	//SET CENTER and ZOOM
	var gog_city_center=cnt_pos.split("^");
	map.setCenter(new GLatLng(gog_city_center[1], gog_city_center[0]), 11);




	//SET NEARBY CITY MARKERS
	for ( var i=nbcity_lat.length-1; i>=0; --i ){
		var point = new GLatLng(nbcity_lat[i], nbcity_lng[i]);
		map.addOverlay(createMarker(point, "_greenC", nbcity_html[i]));
	}
	//SET NEARBY AIRPORT MARKERS
	for ( var i=nbair_lat.length-1; i>=0; --i ){
		var point = new GLatLng(nbair_lat[i], nbair_lng[i]);
		map.addOverlay(createMarker(point, "_purpleA", nbair_html[i]));
	}

	//SET CITY MARKER
	var gog_city_name="<h4>"+cnt_name+"</h4>";
	var point = new GLatLng(gog_city_center[1], gog_city_center[0]);
	map.addOverlay(createMarker(point, cnt_icon, gog_city_name));

	//SET HOTEL MARKERS
	for ( var i=hotel_lat.length-1; i>=0; --i ){
		var point = new GLatLng(hotel_lat[i], hotel_lng[i]);
		map.addOverlay(createMarker(point, "_orangeH", hotel_html[i]));
	}
}

function litebox_vscroll(){
	return (document.documentElement&&document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
}
function cloak(div_rel){
	litebox_position(div_rel);
	$("div#cloak").bgiframe().css({
		opacity: 0,
		display: "block",
		top: (litebox_vscroll()-600)+"px",
		height: ($(window).height()+1200)+"px"
	}).css({width: $(window).width()+"px"}).stop().animate({opacity: 0.70}, 'fast');
	$(window).scroll(function() {$("div#cloak").css({top: (litebox_vscroll()-600)+"px"});});
	$(window).resize(function() {
		$("div#cloak").bgiframe().css({
			top: (litebox_vscroll()-600)+"px", height: ($(window).height()+1200)+"px"
		}).css({width: $(window).width()+"px"});
	});
}
function litebox_position(div_rel){
	var window_h = ($(window).height()/2)-($("div#litebox").height()/2);
	if ($("div#litebox").height()>$(window).height()){
		window_h=0;
		$("div#litebox").css({'margin-top':'12px'});
	} else $("div#litebox").css({'margin-top':'0px'});
	$("div#litebox").css({
		display: "block",
		top: (litebox_vscroll()+window_h)+"px",
		left: (div_rel) ? (document.getElementsByTagName("div")[div_rel].offsetLeft)+($("#"+div_rel).width()/2-$("div#litebox").width()/2)+"px" : ($(window).width()/2-$("div#litebox").width()/2)+"px"
	});
}









$(document).ready(function() {

	var litebox_width=$("div#litebox").width();
	function litebox_close(){
		$("div#litebox").css({width: litebox_width+"px", display: "none"});
		$("div#cloak").stop().animate({opacity: 0}, 'fast', function() {$("div#cloak").css({display: "none"})});
	}
	$('div#cloak, .litebox_close').click(function() {litebox_close(); return false});
	
	
	$('.env_audit').click(function(){
		$(".mapdiv").html('');							   
		$('.mapdiv').removeClass('wd627');	
		$('.mapdiv').removeClass('ht310');
		
		$('.ht_nav_env').addClass('ht_nav_env2');	
		$('.ht_nav_env').removeClass('ht_nav_env1');
		$('.ht_nav_ovr').addClass('ht_nav_mid1');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid2');
		$('.ht_nav_rev').addClass('ht_nav_mid1');	
		$('.ht_nav_rev').removeClass('ht_nav_mid2');
		$('.ht_nav_pho').addClass('ht_nav_mid1');	
		$('.ht_nav_pho').removeClass('ht_nav_mid2');
		$('.ht_nav_map').addClass('ht_nav_end1');	
		$('.ht_nav_map').removeClass('ht_nav_end2');
		$('.ht_nav_tips').addClass('ht_nav_end1');	
		$('.ht_nav_tips').removeClass('ht_nav_end2');
									
 		$('.overview').removeClass('ht_nav1');
		$('.overview').removeClass('b');
        $('.overview').addClass('ht_nav2');	
 		$('.reviews').removeClass('ht_nav1');
		$('.reviews').removeClass('b');
        $('.reviews').addClass('ht_nav2');	
 		$('.photos').removeClass('ht_nav1');
		$('.photos').removeClass('b');
        $('.photos').addClass('ht_nav2');	
 		$('.map').removeClass('ht_nav1');
		$('.map').removeClass('b');
        $('.map').addClass('ht_nav2');	
 		$('.tips').removeClass('ht_nav1');
		$('.tips').removeClass('b');
        $('.tips').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
		
		$('#env_audit').fadeIn();
		$('#overview').fadeOut();
		$('#reviews').fadeOut();
		$('#photos').fadeOut();
		//$('#map').fadeOut();
		$('#tips').fadeOut();
		
	});

	$('.overview').click(function(){
		$(".mapdiv").html('');							  
		$('.mapdiv').removeClass('wd627');	
		$('.mapdiv').removeClass('ht310');
		
		$('.ht_nav_env').addClass('ht_nav_env1');	
		$('.ht_nav_env').removeClass('ht_nav_env2');
		$('.ht_nav_ovr').addClass('ht_nav_mid2');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid1');
		$('.ht_nav_rev').addClass('ht_nav_mid1');	
		$('.ht_nav_rev').removeClass('ht_nav_mid2');
		$('.ht_nav_pho').addClass('ht_nav_mid1');	
		$('.ht_nav_pho').removeClass('ht_nav_mid2');
		$('.ht_nav_map').addClass('ht_nav_end1');	
		$('.ht_nav_map').removeClass('ht_nav_end2');
		$('.ht_nav_tips').addClass('ht_nav_end1');	
		$('.ht_nav_tips').removeClass('ht_nav_end2');
					
 		$('.env_audit').removeClass('ht_nav1');
		$('.env_audit').removeClass('b');
        $('.env_audit').addClass('ht_nav2');	
 		$('.reviews').removeClass('ht_nav1');
		$('.reviews').removeClass('b');
        $('.reviews').addClass('ht_nav2');	
 		$('.photos').removeClass('ht_nav1');
		$('.photos').removeClass('b');
        $('.photos').addClass('ht_nav2');	
 		$('.map').removeClass('ht_nav1');
		$('.map').removeClass('b');
        $('.map').addClass('ht_nav2');	
 		$('.tips').removeClass('ht_nav1');
		$('.tips').removeClass('b');
        $('.tips').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
		
		$('#overview').fadeIn();
		$('#env_audit').fadeOut();
		$('#reviews').fadeOut();
		$('#photos').fadeOut();
		//$('#map').fadeOut();
		$('#tips').fadeOut();
	});
	$('.reviews').click(function(){
		$(".mapdiv").html('');	
		$('.mapdiv').removeClass('wd627');	
		$('.mapdiv').removeClass('ht310');
		
		$('.ht_nav_env').addClass('ht_nav_env1');	
		$('.ht_nav_env').removeClass('ht_nav_env2');
		$('.ht_nav_ovr').addClass('ht_nav_mid1');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid2');
		$('.ht_nav_rev').addClass('ht_nav_mid2');	
		$('.ht_nav_rev').removeClass('ht_nav_mid1');
		$('.ht_nav_pho').addClass('ht_nav_mid1');	
		$('.ht_nav_pho').removeClass('ht_nav_mid2');
		$('.ht_nav_map').addClass('ht_nav_end1');	
		$('.ht_nav_map').removeClass('ht_nav_end2');
		$('.ht_nav_tips').addClass('ht_nav_end1');	
		$('.ht_nav_tips').removeClass('ht_nav_end2');
					
 		$('.env_audit').removeClass('ht_nav1');
		$('.env_audit').removeClass('b');
        $('.env_audit').addClass('ht_nav2');	
 		$('.overview').removeClass('ht_nav1');
		$('.overview').removeClass('b');
        $('.overview').addClass('ht_nav2');	
 		$('.photos').removeClass('ht_nav1');
		$('.photos').removeClass('b');
        $('.photos').addClass('ht_nav2');	
 		$('.map').removeClass('ht_nav1');
		$('.map').removeClass('b');
        $('.map').addClass('ht_nav2');	
 		$('.tips').removeClass('ht_nav1');
		$('.tips').removeClass('b');
        $('.tips').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
		
		$('#reviews').fadeIn();
		$('#overview').fadeOut();
		$('#env_audit').fadeOut();
		$('#photos').fadeOut();
		//$('#map').fadeOut();
		$('#tips').fadeOut();
	});
	$('.photos').click(function(){
		$(".mapdiv").html('');						
		$('.mapdiv').removeClass('wd627');	
		$('.mapdiv').removeClass('ht310');
		
		$('.ht_nav_env').addClass('ht_nav_env1');	
		$('.ht_nav_env').removeClass('ht_nav_env2');
		$('.ht_nav_ovr').addClass('ht_nav_mid1');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid2');
		$('.ht_nav_rev').addClass('ht_nav_mid1');	
		$('.ht_nav_rev').removeClass('ht_nav_mid2');
		$('.ht_nav_pho').addClass('ht_nav_mid2');	
		$('.ht_nav_pho').removeClass('ht_nav_mid1');
		$('.ht_nav_map').addClass('ht_nav_end1');	
		$('.ht_nav_map').removeClass('ht_nav_end2');
		$('.ht_nav_tips').addClass('ht_nav_end1');	
		$('.ht_nav_tips').removeClass('ht_nav_end2');
					
 		$('.env_audit').removeClass('ht_nav1');
		$('.env_audit').removeClass('b');
        $('.env_audit').addClass('ht_nav2');
 		$('.overview').removeClass('ht_nav1');
		$('.overview').removeClass('b');
        $('.overview').addClass('ht_nav2');	
 		$('.reviews').removeClass('ht_nav1');
		$('.reviews').removeClass('b');
        $('.reviews').addClass('ht_nav2');	
 		$('.map').removeClass('ht_nav1');
		$('.map').removeClass('b');
        $('.map').addClass('ht_nav2');	
 		$('.tips').removeClass('ht_nav1');
		$('.tips').removeClass('b');
        $('.tips').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
		
		$('#photos').fadeIn();
		$('#overview').fadeOut();
		$('#reviews').fadeOut();
		$('#env_audit').fadeOut();
		//$('#map').fadeOut();
		$('#tips').fadeOut();
	});
	$('.map').click(function(){
		//initialize();
		//<div id="map_canvas_2" class="rgt" style="width: 627px; height: 315px"></div>
		//wd627 ht310 
		$('.mapdiv').addClass('wd627');	
		$('.mapdiv').addClass('ht310');
		$(".mapdiv").html('<div id="map_canvas_2" class="rgt"></div>');
		initialize();
		
		$('.ht_nav_env').addClass('ht_nav_env1');	
		$('.ht_nav_env').removeClass('ht_nav_env2');
		$('.ht_nav_ovr').addClass('ht_nav_mid1');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid2');
		$('.ht_nav_rev').addClass('ht_nav_mid1');	
		$('.ht_nav_rev').removeClass('ht_nav_mid2');
		$('.ht_nav_pho').addClass('ht_nav_mid1');	
		$('.ht_nav_pho').removeClass('ht_nav_mid2');
		$('.ht_nav_map').addClass('ht_nav_end2');	
		$('.ht_nav_map').removeClass('ht_nav_end1');
		$('.ht_nav_tips').addClass('ht_nav_end1');	
		$('.ht_nav_tips').removeClass('ht_nav_end2');
				
 		$('.env_audit').removeClass('ht_nav1');
		$('.env_audit').removeClass('b');
        $('.env_audit').addClass('ht_nav2');
 		$('.overview').removeClass('ht_nav1');
		$('.overview').removeClass('b');
        $('.overview').addClass('ht_nav2');	
 		$('.reviews').removeClass('ht_nav1');
		$('.reviews').removeClass('b');
        $('.reviews').addClass('ht_nav2');	
 		$('.photos').removeClass('ht_nav1');
		$('.photos').removeClass('b');
        $('.photos').addClass('ht_nav2');	
 		$('.tips').removeClass('ht_nav1');
		$('.tips').removeClass('b');
        $('.tips').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
		
		$('#map').fadeIn();
		$('#overview').fadeOut();
		$('#reviews').fadeOut();
		$('#photos').fadeOut();
		$('#env_audit').fadeOut();
		$('#tips').fadeOut();
	});
	$('.tips').click(function(){
$(".mapdiv").html('');						  
		$('.mapdiv').removeClass('wd627');	
		$('.mapdiv').removeClass('ht310');					  
		$('.ht_nav_env').addClass('ht_nav_env1');	
		$('.ht_nav_env').removeClass('ht_nav_env2');
		$('.ht_nav_ovr').addClass('ht_nav_mid1');	
		$('.ht_nav_ovr').removeClass('ht_nav_mid2');
		$('.ht_nav_rev').addClass('ht_nav_mid1');	
		$('.ht_nav_rev').removeClass('ht_nav_mid2');
		$('.ht_nav_pho').addClass('ht_nav_mid1');	
		$('.ht_nav_pho').removeClass('ht_nav_mid2');
		$('.ht_nav_map').addClass('ht_nav_end1');	
		$('.ht_nav_map').removeClass('ht_nav_end2');
		$('.ht_nav_tips').addClass('ht_nav_end2');	
		$('.ht_nav_tips').removeClass('ht_nav_end1');
			
 		$('.env_audit').removeClass('ht_nav1');
		$('.env_audit').removeClass('b');
        $('.env_audit').addClass('ht_nav2');
 		$('.overview').removeClass('ht_nav1');
		$('.overview').removeClass('b');
        $('.overview').addClass('ht_nav2');	
 		$('.reviews').removeClass('ht_nav1');
		$('.reviews').removeClass('b');
        $('.reviews').addClass('ht_nav2');	
 		$('.photos').removeClass('ht_nav1');
		$('.photos').removeClass('b');
        $('.photos').addClass('ht_nav2');	
 		$('.map').removeClass('ht_nav1');
		$('.map').removeClass('b');
        $('.map').addClass('ht_nav2');	
		
 		$(this).removeClass('ht_nav2');
        $(this).addClass('ht_nav1');
		$(this).addClass('b');
							  
		$('#tips').fadeIn();
		$('#overview').fadeOut();
		$('#reviews').fadeOut();
		$('#photos').fadeOut();
		//$('#map').fadeOut();
		$('#env_audit').fadeOut();
	});
	
	$('a#gog_map_link').click(function() {				   
		var test_content=$('div#litebox_content').html().indexOf('map_canvas');
		if (first_load==0 || test_content<0){
			first_load=1;
	
			$('div#litebox_content').html('<div id="map_canvas"><div id="map_canvas2">Loading</div></div>');
			var x=0;
			$('div.gog_pos').each(function() {
				if ($(this).html()!="null"){
					var tmp_pos=$(this).html().split("^");
					//$('a#gog_name_'+x).html();
					//$('a#gog_link_'+x).html();
					//$('a#gog_img_'+x).html();
					//$('a#gog_address_'+x).html()
					hotel_html[x] = '<div class="lft gog_bub_img"><a href="'+document.getElementById('gog_name_'+x).href+'"><img src="'+$('div#gog_img_'+x).html()+'" /></a></div><div class="lft gog_bub_content"><h4><a href="'+document.getElementById('gog_name_'+x).href+'">'+$('a#gog_name_'+x).html()+'</a></h4><p class="gog_address">'+$('div#gog_address_'+x).html()+'</p><p class="gog_price">'+$('div#gog_price_'+x).html()+'</p></div></div><div class="clear"></div>';
					hotel_lng[x] = tmp_pos[0];
					hotel_lat[x] = tmp_pos[1];
					x=x+1;
				}
			});
			var x=0;
			$('div.gog_city').each(function() {
				if ($(this).html()!="null"){
					var tmp_pos=$(this).html().split("^");
					nbcity_html[x] = '<div><h4><a href="'+document.getElementById('gog_city_name_'+x).href+'">'+$('a#gog_city_name_'+x).html()+'</a></h4><p class="gog_address">'+$('div#gog_citydistance_'+x).html()+'</p><div><a class="gog_link" href="'+document.getElementById('gog_city_name_'+x).href+'">'+$('a#gog_citycount_'+x).html()+'</a><div class="clear"></div></div></div>';
					nbcity_lng[x] = tmp_pos[0];
					nbcity_lat[x] = tmp_pos[1];
					x=x+1;
				}
			});
			var x=0;
			$('div.gog_airport').each(function() {
				if ($(this).html()!="null"){
					var tmp_pos=$(this).html().split("^");
					nbair_html[x] = '<div><h4><a href="'+document.getElementById('gog_airport_name_'+x).href+'">'+$('a#gog_airport_name_'+x).html()+'</a></h4><p class="gog_address">'+$('div#gog_airdistance_'+x).html()+'</p><div><a class="gog_link" href="'+document.getElementById('gog_airport_name_'+x).href+'">'+$('a#gog_aircount_'+x).html()+'</a><div class="clear"></div></div></div>';
					nbair_lng[x] = tmp_pos[0];
					nbair_lat[x] = tmp_pos[1];
					x=x+1;
				}
			});
	
	
			
			google.load("maps","2", {"callback" : mapsLoaded});
			
		}
	
		$("div#litebox").css("width", "800px");
		cloak();
		return false;
	});
});

