hinfo = new Array();
function showHideWeather(){
	if(jQuery('#pred').css('display') == 'none')
		jQuery('#pred').slideDown(300);
	else
		jQuery('#pred').slideUp(300);
}
function getGoogleMarkerOptions(){
	var tinyIcon = new GIcon(G_DEFAULT_ICON);
	tinyIcon.image = "/imgs/panoramio-marker.png";
	tinyIcon.shadow = "/imgs/panoramio-shadow.png";
	tinyIcon.iconSize = new GSize(18, 18);
	tinyIcon.shadowSize = new GSize(22, 22);
	tinyIcon.iconAnchor = new GPoint(18, 18);
	tinyIcon.infoWindowAnchor = new GPoint(18, 18);
	return {icon:tinyIcon};
}
function getHotelMarkerOptions(){
	var tinyIcon = new GIcon(G_DEFAULT_ICON);
//	tinyIcon.image = "/imgs/panoramio-marker.png";
//	tinyIcon.shadow = "/imgs/panoramio-shadow.png";
//	tinyIcon.iconSize = new GSize(18, 18);
//	tinyIcon.shadowSize = new GSize(22, 22);
//	tinyIcon.iconAnchor = new GPoint(18, 18);
//	tinyIcon.infoWindowAnchor = new GPoint(18, 18);
	return {icon:tinyIcon};
}

function initGmap(lon, lat, event){
	var targ;
	var hid = 0;
	if (!event) var event = window.event;
	if (event.target) targ = jQuery(event.target);
	else if (event.srcElement) targ = jQuery(event.srcElement);
	if(targ.attr('class') == 'hmap'){
		targ = targ.parent().parent().attr('id');
		if(targ != ''){
			hid = targ.replace(/hid_/gi, '');
		}
	}
	var w = 410;
	var h = 302;
	jQuery.getScript('http://www.google.com/jsapi?key='+gmap_api_key, function(){
		google.load("maps", "2", {"callback" : function(){
			if(typeof GBrowserIsCompatible == 'function'){
				if((typeof(jQuery("#gmap_holder").attr('id'))=='undefined') && GBrowserIsCompatible()){
					var gmap_container = jQuery('<div id="gmap_holder"><div id="gmapdrag"><span id="gmapdrag_">click to drag</span><span id="closegmap">X</span></div><div id="map_canvas"></div></div>');
					gmap_container.hide(0);
					jQuery('#container').after(gmap_container);
					var dragstart_pos = jQuery('#container').position();
					gmap_container.css({left:dragstart_pos.left});
					gmap_container
					.bind('dragstart',function( event ){
						return jQuery(event.target).is('#gmapdrag_');
		            })
			        .bind('drag',function( event ){
			        	jQuery( this ).css({
			            	top: (event.offsetY),
			                left: (event.offsetX)
		                });
		            });
					//init google map
					belogradchik_kml = new GGeoXml("http://www.belogradchik.biz/resources/belogradchik_sofia.kml");
					var map = new GMap2(jQuery('#map_canvas').get(0)
							,{ size: new GSize(w,h) }
					);
					var myMarker = getGoogleMarkerOptions();
					map.removeMapType(G_HYBRID_MAP);
					map.setCenter(new GLatLng(lon, lat), 11);
					map.addControl(new GSmallMapControl());
					var mapControl = new GMapTypeControl();
			        map.addControl(mapControl);
			        map.addOverlay(belogradchik_kml);
			        //add panoramino marker images
			        jQuery.getJSON('http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=100&minx='+(lat-0.05)+'&miny='+(lon-0.05)+'&maxx='+(lat+0.1)+'&maxy='+(lon)+'&size=thumbnail&callback=?', function(data){
			        	for(i in data.photos){
			        		var lat_lon = new GLatLng(data.photos[i].latitude, data.photos[i].longitude);
			        		var marker = new GMarker(lat_lon,myMarker);
			        		marker.photo = data.photos[i];
							GEvent.addListener(marker, "click", function() {
								var p = this.photo;
								// if photo_title is too long, cut it.
								if (p.photo_title.length > 33)
									p.photo_title = p.photo_title.substring(0, 33) + "&#8230;";
								this.openInfoWindowHtml(
									"<div id='panoramino_infowin'>" +
									"<a class='panoramino-logo' href='http://www.panoramio.com/' target='_blank'><img src='/imgs/panoramino-logo-small.gif' alt='Panoramio logo' /><\/a>" +
									"<a class='photo_infowin' target='_blank' href='" + p.photo_url + "'>" +
									"<img src='" + p.photo_file_url + "'/><\/a>" +
									"<div class='photoinf_text'>" +
									"<a target='_blank' class='photo_title' href='" + p.photo_url +
									"'>" + p.photo_title + "<\/a>" +
									"<p>Posted by <a target='_blank' href='" + p.owner_url + "'>" +
									p.owner_name + "<\/a></p><\/div>" +
								"<\/div>");
							});
		        			map.addOverlay(marker);
			        	}
			        });
			        if((hid>0) && (hinfo[hid] != undefined) && (hinfo[hid].lat>0) && (hinfo[hid].lon>0)){
			        	var lat_lon = new GLatLng(hinfo[hid].lon,hinfo[hid].lat);
			        	var marker = new GMarker(lat_lon,getHotelMarkerOptions());
			        	GEvent.addListener(marker, "click", function() {
			        		this.openInfoWindowHtml('<div class="ghotelwin"><strong>'+hinfo[hid].name+'</strong><br/><i>'+hinfo[hid].address+'</i></div>');
			        	});
			        	map.addOverlay(marker);
			        }
			        gmap_container.slideDown(300, function(){
						jQuery('#closegmap').click(function(){
							jQuery('#gmap_holder').slideUp(300, function(){
								jQuery(this).remove();
							});
						});
					});
				}else{
					if(GBrowserIsCompatible()){
						jQuery('#gmap_holder').slideUp(300, function(){
							jQuery(this).remove();
						});
					}
				}
			}
		}});
	});
}
function changeHotelImg(me){
	var unsed_id = parseInt(me.attr('id').replace(/s/ig,''));
	var normal_img = jQuery('.bigimgsrc');
	normal_img.fadeTo('slow', 0.01, function(){
		jQuery(this).attr('src',me.attr('longdesc'));
		normal_img.fadeTo('slow', 1);
		var bigest_id_obj = jQuery('#b'+unsed_id);
		var bigest_id = bigest_id_obj.attr('id');
		if(bigest_id != undefined){
			var big_img_a_vissible = jQuery('.bigimg');
			var big_img_id_vissible = big_img_a_vissible.attr('id');
			var big_img_href_vissible = big_img_a_vissible.attr('href');
			var bigest_id_obj_hidden = bigest_id_obj.attr('id');
			var bigest_href_obj_hidden = bigest_id_obj.attr('href');
			bigest_id_obj.attr('id', big_img_id_vissible);
			bigest_id_obj.attr('href', big_img_href_vissible);
			big_img_a_vissible.attr('href',bigest_href_obj_hidden);
			big_img_a_vissible.attr('id',bigest_id_obj_hidden);
		}
	});
}
function showRoomDetails(me){
	jQuery('.ri-opened').slideUp('slow', function(){
		jQuery(this).attr('class', 'ri-closed');
	});
	me.slideDown('slow', function(){
		me.attr('class', 'ri-opened');
		jQuery('.ri-opened').children().each(function(){
			jQuery(this).click(function(){return false;});
		});
	});
}
function get_hotelmail_position(){
	var el = jQuery('#h-d-right');
	var position = el.position();
	var w = el.width();
	var h = el.height();
	position.right = position.left+w;
	position.bottom = position.top+h;
	return position;
}

function showWindow_t1(data, position){
	position = 'var window_position='+position+'()';
	var data_obj = jQuery(data).css({display: "none"});
	var data_id = jQuery('#'+data_obj.attr('id'));
	var hideit = {};
	if(data_id.attr('id') == undefined){
		eval(position);
		data_obj.css({top:window_position.top+'px',left:window_position.left+'px'});
		jQuery('#container').append(data_obj);
		data_obj.show('slow');
	}else{
		data_id.hide('slow', function(){
			jQuery(this).remove();
		});
	}
}
function getMailForm(params){
	params.exec = 'get_mail_form'
	jQuery.get('/actions.php', params, function(data){
		eval(data);
	})
}
function escapeQuotes(str){
	str = str.replace(/'/ig, "\\'");
	str = str.replace(/\n/ig, "\\n");
	return str;
}
function sendmail2hotel(id){
	var send_button = jQuery('.sendmail2hotel');
	if(send_button.attr('cliked') == 'true'){
		alert('allready clicked');
		return;
	}
	var id = jQuery(id);
	var isempty = false;
	id.find('input,textarea').each(function(){
		var inel = jQuery(this).attr('class','');
		if(inel.attr('type')=='hidden')
			return;
		if(inel.attr('value') == ''){
			inel.attr('class','cs-emptyfield');
			isempty = true;
		}
	});
	if(!isempty){
		send_button.attr('cliked',true);
		id.find('input,textarea').attr('readonly',true);
		var paramsend = {};
		id.find('input,textarea').each(function(){
			var inel = jQuery(this);
			eval('paramsend.'+inel.attr('name')+"='"+escapeQuotes(inel.attr('value'))+"';");
		});
		var progresbar = jQuery('.progresbar');
		progresbar.show('fast');
		jQuery.post('/actions.php', paramsend, function(data){
			eval(data);
			if(typeof(dataretrun) == 'undefined'){
				progresbar.hide('fast');
			}
			else if(dataretrun == '1'){//ok
				progresbar.find('u').text(mailstat[0]);
				progresbar.find('img').fadeTo(1000,0.01);
				progresbar.css({background:"#C5E5B7"});
			}else{//not ok
				progresbar.find('u').text(mailstat[1]);
				progresbar.find('img').fadeTo(1000,0.01);
				progresbar.css({background:"#E2B5B5"});
			}
			send_button.attr('cliked',false);
			id.find('input,textarea').attr('readonly',false);
		});
	}
}