
//bookmark this site
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

//Pop Under
function hbcPop(key, country, state, city, mod) {
if (key==""){key=document.getElementById("rs_city").value;}
if (city==""){city=document.getElementById("rs_city").value;}
var page = "http://www.hotelsbycity.com/hotels/pop_up.php?key="+key+"&country="+country+"&state="+state+"&city="+city+"&mod="+mod;
var windowprops = "resizable=1,scrollbars=1,menubar=1,location=1,toolbar=1,titlebar=1,width=680,height=510, top=50, left=50";
newWindow = window.open(page, '', windowprops);
newWindow.blur();
}

$(document).ready(function()
{
	var selected_hid = "";
	$(".rs_search_submit").click(function()
	{
		$("form#city_search_form").submit();
		return false;
	});
			
	var id = $("div#map_container").find("div").attr("id");
	//var map = init_map(id); 
	$("div.atr_sub").hide();
	$(".atr_main_name").click(function()
	{
		var id = this.id.replace(/main/g, 'sub');
		var tmp = id.split("_");
		
		for(i = 1; i <= 25; i++)
		{
			if(i != tmp[2])
			{
				$("div#atr_sub_" + i).hide();
				$("img#bullet_" + i).attr("src", "/images/bullet.gif");
			}
		}
		
		if(!$("div#" + id).is(":visible"))
		{
			$("div#" + id).show();
			$("img#bullet_" + tmp[2]).attr("src", "/images/bullet_down.gif");
		}
		else
		{
			$("div#" + id).hide();
			$("img#bullet_" + tmp[2]).attr("src", "/images/bullet.gif");
		}
	});
	
	$("a.prop_show_map").click(function()
	{
		selected_hid = this.id.split("_")[1]; 
		cloak();
		$("div#trick").css("width", "830px");
		$("div#trick").html('<div class="popup"><a href="#" class="popup_close"></a><div id="map_canvas" style="width: 810px; height: 400px"><div class="loading_msg">Loading</div></div></div>');
		$("div#trick").bgiframe().css("display", "none").fadeIn("slow");
		position_pop_box("trick", "master");

		pop_map();
		return false;
	});
	
	$("div#map_container").click(function()
	{
		cloak();
		$("div#trick").css("width", "830px");
		$("div#trick").html('<div class="popup"><a href="#" class="popup_close"></a><div id="map_canvas" style="width: 810px; height: 400px"><div class="loading_msg">Loading</div></div></div>');
		$("div#trick").bgiframe().css("display", "none").fadeIn("slow");
		position_pop_box("trick", "master");

		pop_map();
		return false;
	});
		
	function position_pop_box(div, div_rel)
	{
		var vscroll = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		var window_h = ($(window).height()/2)-($("#"+div).height()/2);
		if ($("#"+div).height()>$(window).height()) window_h=0;
		document.getElementById(div).style.top=(vscroll+window_h)+"px";
		document.getElementById(div).style.left=(document.getElementsByTagName("div")[div_rel].offsetLeft)+($("#"+div_rel).width()/2-$("#"+div).width()/2)+"px";
	}
	
	function cloak(size)
	{
		if(size == "small")
		{
			$("div#cloak").style.height="130px";
			$("div#cloak").style.width="440px";
			$("div#cloak").bgiframe().css({opacity: 0, display: "block"});
			$("div#cloak").stop().animate({opacity: 0.60}, 'fast');
			position_pop_box("cloak", "master");
		}
		else
		{
			var vscroll = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : 
			document.body.scrollTop;
			document.getElementById("cloak").style.top=(vscroll-600)+"px";
			document.getElementById("cloak").style.height=($(window).height()+1200)+"px";
			document.getElementById("cloak").style.width=$(window).width()+"px";
			$("div#cloak").bgiframe().css({opacity: 0, display: "block"});
			$("div#cloak").stop().animate({opacity: 0.60}, 'fast');
			$(window).scroll(function() 
			{
				vscroll = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : 
				document.body.scrollTop;
				$("div#cloak").style.top=(vscroll-600)+"px";
			});
			$(window).resize(function()
			{
				vscroll = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : 
				document.body.scrollTop;
				document.getElementById("cloak").style.top=(vscroll-600)+"px";
				document.getElementById("cloak").style.height=($(window).height()+1200)+"px";
				document.getElementById("cloak").style.width=$(window).width()+"px";
			});
		}
	}
	
	function createMarker(point, index, html, icon) 
	{
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.image = icon;
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		markerOptions = {icon:baseIcon};
		
		var marker = new GMarker(point, markerOptions);
		GEvent.addListener(marker, "click", function() 
		{
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}
	
	function pop_map()
	{
		var lat = parseFloat($("a#hotel_lnglat").attr("title").split(",")[0]);
		var lng = parseFloat($("a#hotel_lnglat").attr("title").split(",")[1]);
			
		var _cid = $("div#master").children();
		var cid = $(_cid[0]).attr("id"); 
		var _cityid = cid.split("_");
		var hotels = "";
		
		$.ajax 
		({ 
			type: 	"GET", 
			url: 	"/includes/gmap.php", 
			data: 	"cityid=" + _cityid[0] + "&latitude=" + lat + "&longitude=" + lng + "&limit=20", 
			success: function(response)
			{
				html = response.split("^"); 
				var map = new GMap2(document.getElementById("map_canvas"));
				map.setUIToDefault();
				map.setCenter(new GLatLng(lat, lng), 12);
								
				if(selected_hid.length > 0)
				{
					var regex = new RegExp('rs_hid=' + selected_hid, "gi");
				}
				for(i = 0; i < html.length; i++)
				{
					var _html = html[i].split("~");
					var marker = createMarker(new GLatLng(_html[2], _html[3]), i, _html[0], _html[1]);
					map.addOverlay(marker);
				
					if(selected_hid.length > 0)
					{
						if(_html[0].match(regex))
						{
							GEvent.trigger(marker, "click");
						}
					}
				}
			}
		});
	}
	
	function cloak_close()
	{
			selected_hid = "";
			$("div#cloak").stop().animate({opacity: 0}, 'fast', function() {$("div#cloak").css({display: "none"})}); 
			$("div#trick").css("width", "450px");
	}
			
	$("a.popup_close").live("click", function()
	{
		cloak_close();
		$("div#trick").css("display", "none");
		return false;
	});
	
	$("div#cloak").click(function()
	{
		cloak_close();
		$("div#trick").css("display", "none");
		return false;
	});
});













