var ehotelDe="ABQIAAAAOIXYptRwo3sdbrBCDp9fhBQfuCO7yCRFZu9LFGu3G9VPxxeahhROk_svKtAcbqolb0sp6Z_lgklGMQ";
var ehotelAt="ABQIAAAAWYNp1soO9Bpqj3PYB8XHXxSX3cfu_RpOXxftQBSsF_cn1-qGMBSeeuVy3Eyq9hOPuNn74ag2qPmNCQ";
var ehotelCh="ABQIAAAAWYNp1soO9Bpqj3PYB8XHXxSkmZ87WytF1afrYLhEeNcJkR4wthT4kHnPmVuHKe7IT_Y76gqc_QZjTg";
var ehotelCom="ABQIAAAAWYNp1soO9Bpqj3PYB8XHXxSwDACw91vd7E4WiQqeKuP7j_Lq8RRousEyDeE6_-uWrC5U82RS41U-Wg";

var enableMaps =new Boolean();

domains ={'ehotel.de': ehotelDe,
          'www.ehotel.de': ehotelDe,
          'ehotel.at': ehotelAt,
          'www.ehotel.at': ehotelAt,
          'ehotel.ch': ehotelCh,
          'www.ehotel.ch': ehotelCh,
          'ehotel.com': ehotelCom,
          'www.ehotel.com': ehotelCom,
          'pl.ehotel.com': ehotelCom,
          'bg.ehotel.com': ehotelCom,
          'no.ehotel.com': ehotelCom,
          'ru.ehotel.com': ehotelCom,
          'pt.ehotel.com': ehotelCom,
          'de.ehotel.com': ehotelCom,
          'uk.ehotel.com': ehotelCom,
          'fr.ehotel.com': ehotelCom,
          'es.ehotel.com': ehotelCom,
          'it.ehotel.com': ehotelCom,
          'nl.ehotel.com': ehotelCom,
          'zh.ehotel.com': ehotelCom,
          'cn.ehotel.com': ehotelCom,
          'localhost': ehotelCom
};

if (domains[location.host]){
	
	//console.log("Api Key["+domains[location.host]+"] found for domain=["+location.host+"]");
	
	if(enableMaps==true){
	
		document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+domains[location.host]+'" type="text/javascript"><\/script>');
	
		if (G_INCOMPAT = 'false') {
			document.write('<body onload="load()" onunload="GUnload()">');
		}
	}

}
var hotels = {
	elements : [],
	hotelsObj : function(id, latitude, longitude, name, image, imagexText,
			price, address, stars, desc, lang, hc, bc) {
		this.id = id;
		this.latitude = latitude;
		this.longitude = longitude;
		this.name = name;

		this.image = image;
		this.imagexText = imagexText;
		this.price = price;
		this.address = address;
		this.stars = stars;
		this.desc = desc;
		this.lang = lang;
		this.hc = hc;
		this.bc = bc;

	},
	add : function(id, latitude, longitude, name, image, imagexText, price,
			address, stars, desc, lang, hc, bc) {
		var index = hotels.elements.length;
		hotels.elements[index] = new hotels.hotelsObj(id, latitude, longitude,
				name, image, imagexText, price, address, stars, desc, lang, hc,
				bc);
	},
	get : function(id) {
		return hotels.elements[id];
	},
	getName : function(id) {
		return hotels.elements[id].name;
	},
	getImage : function(id) {
		return hotels.elements[id].image;
	},
	getImagexText : function(id) {
		return hotels.elements[id].imagexText;
	},
	getLatitude : function(id) {
		return hotels.elements[id].latitude;
	},
	getLongitude : function(id) {
		return hotels.elements[id].longitude;
	},
	getPrice : function(id) {
		return hotels.elements[id].price;
	},
	getAddress : function(id) {
		return hotels.elements[id].address;
	},
	getStars : function(id) {
		return hotels.elements[id].stars;
	},
	getDescription : function(id) {
		return hotels.elements[id].desc;
	},
	getLanguage : function(id) {
		return hotels.elements[id].lang;
	},
	getHC : function(id) {
		return hotels.elements[id].hc;
	},
	getBC : function(id) {
		return hotels.elements[id].bc;
	},

	remove : function(id) {
		delete hotels.elements[id];
	},
	removeAll : function() {
		hotels.elements.splice(0, hotels.elements.length);
	}
};

function drawMap() {
	var result;
	for ( var i = 0; i < hotels.elements.length; ++i) {
		if (hotels.getLatitude(i) == 0.0 && hotels.getLongitude(i) == 0.0) {
			result = false;
			//console.log("Hotel: "+ i+" Lat["+hotels.getLatitude(i)+"] Lon["+hotels.getLongitude(i)+"]");
		} else {
			//console.log("Hotel: "+ i+" Lat["+hotels.getLatitude(i)+"] Lon["+hotels.getLongitude(i)+"]");
			result = true;
		}
	}
	return result;
}

var customIcons = [];
var markerGroups ;
var focusHotel="";		
var ThisGmap="";
var ThisHotelInfo="";
var ThisClear="";
var ThisClearParent="";
var ThisToggleStar="";
var enableFullScreen=true;

function load() {

	var div_a = document.getElementById("map");
	var div_b = document.getElementById("hotelInfo");
	var div_c = document.getElementById("toggleStar");
	ThisGmap=div_a;
	ThisHotelInfo=div_b;
	ThisToggleStar=div_c;
	

	
		 				var star1 = new GIcon(G_DEFAULT_ICON);
						      star1.image = "/styles/img/icn/haus1.png";
				              star1.shadow = "/styles/img/icn/haus-shadow.png";
						      star1.iconSize = new GSize(20.0, 24.0);
						      star1.shadowSize = new GSize(33.0, 24.0);
						      star1.iconAnchor = new GPoint(10.0, 12.0);
						      star1.infoWindowAnchor = new GPoint(10.0, 12.0);
				        var star2 = new GIcon(G_DEFAULT_ICON);
						      star2.image = "/styles/img/icn/haus2.png";
				              star2.shadow = "/styles/img/icn/haus-shadow.png";
						      star2.iconSize = new GSize(20.0, 24.0);
						      star2.shadowSize = new GSize(33.0, 24.0);
						      star2.iconAnchor = new GPoint(10.0, 12.0);
						      star2.infoWindowAnchor = new GPoint(10.0, 12.0);
                        var star3 = new GIcon(G_DEFAULT_ICON);
						      star3.image = "/styles/img/icn/haus3.png";
				              star3.shadow = "/styles/img/icn/haus-shadow.png";
						      star3.iconSize = new GSize(20.0, 24.0);
						      star3.shadowSize = new GSize(33.0, 24.0);
						      star3.iconAnchor = new GPoint(10.0, 12.0);
						      star3.infoWindowAnchor = new GPoint(10.0, 12.0);
                        var star4 = new GIcon(G_DEFAULT_ICON);
						      star4.image = "/styles/img/icn/haus4.png";
				              star4.shadow = "/styles/img/icn/haus-shadow.png";
						      star4.iconSize = new GSize(20.0, 24.0);
						      star4.shadowSize = new GSize(33.0, 24.0);
						      star4.iconAnchor = new GPoint(10.0, 12.0);
						      star4.infoWindowAnchor = new GPoint(10.0, 12.0);
                        var star5 = new GIcon(G_DEFAULT_ICON);
						      star5.image = "/styles/img/icn/haus5.png";
				              star5.shadow = "/styles/img/icn/haus-shadow.png";
						      star5.iconSize = new GSize(20.0, 24.0);
						      star5.shadowSize = new GSize(33.0, 24.0);
						      star5.iconAnchor = new GPoint(10.0, 12.0);
						      star5.infoWindowAnchor = new GPoint(10.0, 12.0);
				        var star0 = new GIcon(G_DEFAULT_ICON);
						      star0.image = "/styles/img/icn/haus.png";
				              star0.shadow = "/styles/img/icn/haus-shadow.png";
						      star0.iconSize = new GSize(20.0, 24.0);
						      star0.shadowSize = new GSize(33.0, 24.0);
						      star0.iconAnchor = new GPoint(10.0, 12.0);
						      star0.infoWindowAnchor = new GPoint(10.0, 12.0);
						
						var focusIcon = new GIcon(G_DEFAULT_ICON);
						      focusIcon.image = "/styles/img/icn/haus_focus.png";
						      focusIcon.shadow = "/styles/img/icn/haus-shadow.png";
						      focusIcon.iconSize = new GSize(20.0, 24.0);
						      focusIcon.shadowSize = new GSize(33.0, 24.0);
						      focusIcon.iconAnchor = new GPoint(10.0, 12.0);
						      focusIcon.infoWindowAnchor = new GPoint(10.0, 12.0);
						      
						      focusIcon.iconSize = new GSize(30.0, 34.0);
						      focusIcon.shadowSize = new GSize(43.0, 34.0);
						      focusIcon.iconAnchor = new GPoint(10.0, 12.0);
						      focusIcon.infoWindowAnchor = new GPoint(10.0, 12.0);
						      
			                    customIcons["1"] = star1;
                                customIcons["2"] = star2;
                                customIcons["3"] = star3;
                                customIcons["4"] = star4;
                                customIcons["5"] = star5;
                                customIcons["0"] = star0;
                                customIcons["focusIcon"] = focusIcon;
                              
                                
			markerGroups = { "1": [], "2": [], "3": [], "4": [], "5": [],"0": []};

	
		
	// set it true or to enable googlemaps
	if (drawMap()) {

		if (GBrowserIsCompatible()) {

			var hotelName = "";
			var hotelPic = "";
			var hotelDesc = "";
			var hotelPrice = "";
			var hotelAddress = "";
			var hotelStars = "";
			var hotelDescription = "";
			var language = "";
			var hc = "";
			var bc = "";
			var imgXurl = "";
			var link = "";
			var complete = "";
			var imgXHotelPic = "";
			
			var isSet="";
			var MAX=""
						
			if (hotels.elements.length >= 1) {

				// set visible if elemtens
				
				
				div_a.style.display = 'block';
				div_b.style.display = 'block';
				div_c.style.display = 'block';
				
				if(enableFullScreen)
				{
				createFullScreenButton = document.createElement('a');
				createFullScreenButton.href='javascript:showWin();';
				text = document.createTextNode("Full Screen");
				attr=document.createAttribute('id');
				attr.nodeValue = "FullScreen";
				createFullScreenButton.setAttributeNode(attr);
				createFullScreenButton.appendChild(text);
				createFullScreenButton.style.marginLeft="5px";
				createFullScreenButton.setAttribute("class", "small");
				div_c.appendChild(createFullScreenButton);
				}
				
				var map = new GMap2(document.getElementById("map"));

				map.addControl(new GSmallMapControl());
				// map.addControl(new GLargeMapControl());
				// map.addControl(new GMapTypeControl());

				map.addControl(new GOverviewMapControl(new GSize(150, 90)));

				// centerLat, centerLon is set on CityPage
				if (typeof (centerLat) != "undefined"
						&& typeof (centerLon) != "undefined") {
					var CenterPoint = new GLatLng(centerLat, centerLon);
					map.setCenter(CenterPoint, 13);
				    //console.log("CENTER CITYPAGE");
				}
				// use first Hotel to center Map and use another zoom level as HotelPage
				
				
				
				if (typeof (centerHotel) != "undefined") {
				    focusHotel=centerHotel-1;
					var CenterPoint = new GLatLng(hotels.getLatitude(focusHotel), hotels.getLongitude(focusHotel));
					map.setCenter(CenterPoint, 15);
					//console.log("CENTER HOTELPAGE");
				}
				
				
				if( typeof (centerLat) == "undefined" && typeof (centerHotel) == "undefined" ) {
					var CenterPoint = new GLatLng(hotels.getLatitude(0), hotels
							.getLongitude(0));
					map.setCenter(CenterPoint, 15);
					//console.log("CENTER FIRST HOTEL");
				}
				
				MAX= hotels.elements.length;
			//	MAX=5;

				for ( var i = 0; i < MAX ; ++i) {

								
					var point = new GLatLng(hotels.getLatitude(i), hotels
							.getLongitude(i));

					hotelName = hotels.getName(i);
					hotelPic = hotels.getImage(i);
					hotelDesc = hotels.getDescription(i);
					hotelPrice = hotels.getPrice(i);
					hotelAddress = hotels.getAddress(i);
					hotelStars = hotels.getStars(i);
					language = hotels.getLanguage(i);
					lat = hotels.getLatitude(i);
					lon = hotels.getLongitude(i);
					hc = hotels.getHC(i);
					bc = hotels.getBC(i);
					imgXurl = "<img src='http://www.ehotel.com/ImgX/button?bid=number2&lang="+language+"&text="
							+ hotels.getImagexText(i) + "'/>";
					/*
					link = "http://www.ehotel.com/Direct?" + "lat=" + lat
							+ "&lon=" + lon + "&reqid=SEOX_T&lang=" + language
							+ "&hc=" + hc + "&bc=" + bc + "&hotelName="
							+ hotelName;
					*/
					
					var city=document.getElementById('city').value;
					
					
					var localeForLink=language;
					
					if(language=='en')
					{
						localeForLink='uk';
					}
					if(language=='zh')
					{
						localeForLink='cn';
					}
					
					link = "http://"+localeForLink+".ehotel.com/Direct?reqid=SEOX_T&lang=" + language
					+ "&hc=" + hc+"&city="+city;
			 
					complete = "<a href='" + link + "'>" + imgXurl + "</a>";
					
					if(hotelPic)
					{
						imgXHotelPic = "http://www.ehotel.com/ImgX/image?src="
							+ hotelPic + "&width=162&height=162"
					}
					else
					{
						imgXHotelPic = 'http://maps.google.com/staticmap?center='
							+ lat + ','
							+ lon + '&zoom=15&markers='
							+ lat + ','
							+ lon
							+ ',&size=162x162&key='+domains[location.host];
					}
					
									
                    var overlay=createMarker(point, hotelName, imgXHotelPic,
							hotelDesc, complete, i, hotelPrice, hotelAddress,
							hotelStars, link)
					
					map.addOverlay(overlay);
					
                    /*
						console.log("CreateMarker: "+i);
						console.log("-----------------");
						console.log("Point: "+point);
						console.log("HotelName: "+hotelName);
						console.log("imgXHotelPic: "+imgXHotelPic);
						console.log("HotelDesc: "+hotelDesc);
						console.log("Link to: "+complete);
						console.log("HotelPrice: "+hotelPrice);
						console.log("HotelAddress: "+hotelAddress);
						console.log("HotelStars: "+hotelStars);
						console.log("LinkIBE: "+link);
					 */
				}
			}

		}

	}
	ThisClear=document.getElementById("clear");
	ThisClearParent=document.getElementById("middleColumn_two");
}



function createMarker(point, hotelName, imgXHotelPic,
							hotelDesc, complete, i, hotelPrice, hotelAddress,
							hotelStars, link) {
    
    var div_a = document.getElementById("map");
	var div_b = document.getElementById("hotelInfo");
	
	var marker;
						// init info div for one hotel
						if (( typeof (centerHotel) != "undefined" && i==focusHotel ) || (i==0)) {
							div_b.style.display = 'block';
							tmp = '<img id="hotelImage" src="' + imgXHotelPic + '"/>';
						
							//stars = '<img src="/styles/img/icn/icn_' + hotelStars + 'star.gif"/>';
							
							stars = '<span class="star'+hotelStars+'"/>';
							
							document.getElementById("hotelImage").innerHTML = "";
							document.getElementById("hotelImage").innerHTML = '<img id="hotelImage" src="' + imgXHotelPic + '"/>';
							document.getElementById("hotelName").innerHTML = hotelName
									+ stars;
							document.getElementById("hotelAddress").innerHTML = hotelAddress;
							document.getElementById("hotelDesc").innerHTML = hotelDesc;
							document.getElementById("hotelPrice").innerHTML = hotelPrice;
							document.getElementById("hotelMoreInfo").innerHTML = complete;
							
							//console.log("Found Focus Hotel"+i);
						}
						if (typeof (centerHotel) != "undefined" && i==focusHotel) {
								marker = new GMarker(point,customIcons['focusIcon']);
							}
						else{
							marker = new GMarker(point,customIcons[hotelStars]);
							markerGroups[hotelStars].push(marker);
						}
//						var marker = new GMarker(point,customIcons[hotelStars]);
//						markerGroups[hotelStars].push(marker);						
						GEvent
								.addListener(
										marker,
										"mouseover",
										function() {
											div_b.style.display = 'block';
											tmp = '<img id="hotelImage" src="' + imgXHotelPic + '"/>';
											
											stars = '<span class="star'+hotelStars+'" style="float:right"/>';
											//stars = '<img src="/styles/img/icn/icn_' + hotelStars + 'star.gif"/>';
											document
													.getElementById("hotelImage").innerHTML = "";
											//console.log("clear div");
											document
													.getElementById("hotelImage").innerHTML = '<img id="hotelImage" src="' + imgXHotelPic + '"/>';
											//console.log("fill div: "+imgXHotelPic);
											document
													.getElementById("hotelName").innerHTML = hotelName
													+ stars;
											document
													.getElementById("hotelAddress").innerHTML = hotelAddress;
											document
													.getElementById("hotelDesc").innerHTML = hotelDesc;
											document
													.getElementById("hotelPrice").innerHTML = hotelPrice;
											document
													.getElementById("hotelMoreInfo").innerHTML = complete;
											//console.log("hover: "+tmp);
										});

						GEvent.addListener(marker, "click", function() {
							window.location.href = link;

						});

						return marker;
					}







function toggleGroup(type) {
    for (var i = 0; i < markerGroups[type].length; i++) 
    {
        var marker = markerGroups[type][i];
            if (marker.isHidden()) {
                marker.show();
             } else {
                marker.hide();
            }
    }
 }



// Close the lightbox
function closeWin() {
	document.getElementById('MapOverlay').style.display="none";
	document.getElementById('MapOverlayClose').style.display="none";
	

	//set original css
	ThisToggleStar.style.textAlign='left';
	ThisToggleStar.style.margin='2px';

	
	var changeFullScreen=document.getElementById("FullScreen");
	text = "Full Screen";
	createFullScreenButton.href='javascript:showWin()';
	changeFullScreen.innerHTML=text;
	changeFullScreen.style.marginLeft="5px";
	changeFullScreen.setAttribute("class", "small");
	
	ThisGmap.style.width=548+"px";
	ThisGmap.style.height=345+"px";
	ThisGmap.style.zIndex='0';
	ThisGmap.style.margin="2px";
	ThisGmap.style.padding='0';
	
	ThisHotelInfo.style.margin= '2px';
	ThisHotelInfo.style.cssFloat= 'right';

	document.getElementById("middleColumn_two").insertBefore(ThisToggleStar, document.getElementById("clear"));
	document.getElementById("middleColumn_two").insertBefore(ThisGmap, document.getElementById("clear"));
	document.getElementById("middleColumn_two").insertBefore(ThisHotelInfo, document.getElementById("clear"));
	diableAdds(false);
	
	
}

// Create Overlay and Form Container, add lightbox content to form container
function createDivs() {
var div = document.createElement('div');
		var container = document.createElement('div');
    	div.id = 'MapOverlay';
		container.id = 'MapOverlayClose';

    if (document.body.firstChild){
      	document.body.insertBefore(div, document.body.firstChild);
		document.body.insertBefore(container, document.body.firstChild);
		} else {
      	document.body.appendChild(div);
		document.body.appendChild(container);
		}
		

}

var wWidth = 0;
var wHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
  wWidth = window.innerWidth;
  wHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  wWidth = document.documentElement.clientWidth;
  wHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
  wWidth = document.body.clientWidth;
  wHeight = document.body.clientHeight;
}


function disableAdds(value)
{
	var res=""
	  if(value=='yes')
	  {res='none';}
	  else{
		  res='block';
	  }
	  
	  	if(document.getElementById("Leaderboard")!=null)
		{document.getElementById("Leaderboard").style.display=res;}
		if(document.getElementById("Square")!=null)
		{document.getElementById("Square").style.display=res;}
		if(document.getElementById("Vertical")!=null)
		{document.getElementById("Vertical").style.display=res;}
		if(document.getElementById("Vertical")!=null)
		{document.getElementById("Vertical").style.display=res;}
		if(document.getElementById("Skyscraper")!=null)
		{document.getElementById("Skyscraper").style.display=res;}
}

// Calls create div function, sends zip code variable to iframe url
function showWin() {
		
	
		disableAdds('yes');
	 	createDivs();
	 	
	 	MapOverlayCloseHeight = wHeight*0.9;
		MapOverlayCloseWidth = wWidth*0.9;
		posleft= (wWidth - (wWidth*0.9)) / 2;
		postop= (wHeight - (wHeight*0.9)) / 2;
		var MapOverlayClose=document.getElementById('MapOverlayClose');
		MapOverlayClose.style.width=MapOverlayCloseWidth +"px";
		MapOverlayClose.style.height=MapOverlayCloseHeight +"px";
		MapOverlayClose.style.top=postop +"px";
		MapOverlayClose.style.left=posleft +"px";
		
		ThisToggleStar.style.textAlign='left';
		ThisToggleStar.style.margin='0';
		ThisToggleStar.style.padding='0';
		
		
		//insert GoogleMaps
		var changeFullScreen=document.getElementById("FullScreen");
		text = "Close Full Screen";
		createFullScreenButton.href='javascript:closeWin()';
		changeFullScreen.innerHTML=text;
		changeFullScreen.style.marginLeft="5px";
		changeFullScreen.setAttribute("class", "small");
		
		var HotelInfoWidth=164;
		var ToggleStarHeight=30;
		
		var border="";
		var position4Divs="";
		if (typeof document.body.style.maxHeight != "undefined") {
			// alert(" IE 7, mozilla, safari, opera 9");
			  border=10;
			  position4Divs='fixed';
		} else {
				// alert(" IE 6,older browsers");
				 border=20;
				 position4Divs='absolute';
			}

		
		
		ThisGmap.style.width=(MapOverlayCloseWidth - HotelInfoWidth - border)+"px";
		ThisGmap.style.height=(MapOverlayCloseHeight-ToggleStarHeight) +"px";
		ThisGmap.style.zIndex='500';
		ThisGmap.style.margin='0';
		ThisGmap.style.padding='0';
		
		ThisHotelInfo.style.cssFloat = 'left';
		ThisHotelInfo.style.margin = '0';
		ThisHotelInfo.style.padding = '0';
		
		MapOverlayClose.appendChild(ThisToggleStar);
		MapOverlayClose.appendChild(ThisGmap);
		MapOverlayClose.appendChild(ThisHotelInfo);
		
		document.getElementById('MapOverlay').style.position=position4Divs;
		document.getElementById('MapOverlay').style.display="block";
		document.getElementById('MapOverlay').style.height=wHeight;
		document.getElementById('MapOverlay').style.width=wWidth;
		MapOverlayClose.style.position=position4Divs;
		MapOverlayClose.style.display="block";
		
			
	
//	console.log("document.body.offsetHeight["+document.body.offsetHeight+"]");
//	console.log("document.body.offsetWidth["+document.body.offsetWidth+"]");
//	console.log("MapOverlayCloseHeight["+MapOverlayCloseHeight+"]");
//	console.log("MapOverlayCloseWidth["+MapOverlayCloseWidth+"]");
//	console.log("posleft["+posleft+"]");
//	console.log("postop["+postop+"]");
	

}


