var lang="";

function setLang(_lang){
	lang = _lang;
}

function __jquery_ajax(data,div_id)
{
	jQuery.ajax({
		url: '/ajax/booking/',
		data: data,
		type: 'POST',
		timeout: 30000,
		error: function(transport, type) { jQuery("#"+div_id).html(transport);},
		success: function(transport) { jQuery("#"+div_id).html(transport);}
	});

}

function getHotelDescription(hotel_id,div_id)
{

	var data = "doType=6&do=getHotelDescriptionTranslations&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelDetailDescription(hotel_id,div_id){
	var data = "doType=0&do=getHotelDescriptionTranslations&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelDetailZusatz(hotel_id,div_id)
{
	var data = "doType=8&do=getHotelDescriptionTranslations&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelFacilities(hotel_id,div_id)
{
	var data = "doType=0&do=getHotelFacilities&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelPhotos(hotel_id,div_id){

	var data = "doType=0&do=getHotelPhotos&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelPhotoGallery(hotel_id,div_id)
{

	var data = "doType=1&do=getHotelPhotos&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}

function getHotelDescriptionPhotoGallery(hotel_id,div_id){

	var data = "doType=2&do=getHotelPhotos&languagecode="+lang+"&hotel_id="+hotel_id;
	__jquery_ajax(data, div_id);
}



function getHotelRoomPhoto(hotel_id,room_Id,div_id)
{

	var data = "doType=3&do=getHotelPhotos&languagecode="+lang+"&hotel_id="+hotel_id+"&room_id="+room_Id;
	__jquery_ajax(data, div_id);
}

function getHotelRoomPhotoGallery(hotel_id,room_Id,div_id)
{
	var data = "doType=4&do=getHotelPhotos&languagecode="+lang+"&hotel_id="+hotel_id+"&room_id="+room_Id;
	__jquery_ajax(data, div_id);
}


function showFullPic(picurl,elementId)
{
	jQuery("#"+elementId).fadeTo("fast", 0.0);
	jQuery(document).ready(function(){
		jQuery("#"+elementId).attr({
        	src: picurl,
        	title: "",
        	alt: ""
        });
	});
	jQuery("#"+elementId).fadeTo("slow", 1);
}


function ShowImageRoomBox(hotelId, roomId)
{
	getHotelRoomPhoto(hotelId,roomId,"HotelRoomPhotoImg");
 	getHotelRoomPhotoGallery(hotelId,roomId,"HotelRoomPhotosImg");
 	jQuery("#imageRoomDiv").show();
}

function initPage()
{
	setLang("de");

	jQuery(document).ready(function(){

		getHotelFacilities(jQuery("#hotelFacilities").attr("value"),"hotelFacilities");
		getHotelPhotos(jQuery("#hotelPhotoMainImg").attr("value"),"hotelPhotoMainImg");
		jQuery("#photoGallery").tabs();
		jQuery("#photoRoomGallery").tabs();

	});
}


function __drawStreetMap(_mapContainer,_lat,_lng,hotelName,hotel_id)
{
	var streetviewClient;
	var panorama;
	var centre = new GLatLng(_lat,_lng);

	var mapContainer = document.getElementById( _mapContainer );


        var streetOverlay = new GStreetviewOverlay();
	streetviewClient = new GStreetviewClient();

	panorama = new GStreetviewPanorama(mapContainer);

	panorama.setLocationAndPOV(centre, {yaw:80.5});

	GEvent.addListener(panorama, "error", function(e) {
  		alert('Für den Ort des Hotels ' + hotelName + ' gibt es derzeit noch keine Strassendaten.');
	});

	panorama.checkResize();
	return panorama;
}


function __drawMap(_mapContainer,_lat,_lng,hotelName,hotel_id)
{


	        var mapContainer = document.getElementById( _mapContainer );

	        mapObject = new GMap2( mapContainer );
	        var geoObject = new GLatLng( _lat,_lng  );
		mapObject.setCenter( geoObject , 16 );

		icon = new GIcon();
		icon.image = 'http://media.stadtbranchenbuch.com/images/marker-hotel-orange-large.png';
		icon.iconSize = new GSize(26, 27);
		icon.iconAnchor = new GPoint(22, 42);
		icon.infoWindowAnchor = new GPoint(18, 0);

		var marker = new GMarker( geoObject, icon );
		mapObject.addOverlay( marker );

		GEvent.addListener(marker, "mouseover", function() {
          		marker.openInfoWindowHtml(jQuery("#hotelBlockGoogle"+hotel_id).html());
          		jQuery("#hotelBlockGoogle"+hotel_id).show();
        	});

		GEvent.addListener(marker, "infowindowclose", function() {


        	});


		GEvent.addDomListener( mapContainer , "DOMMouseScroll", _wheelEvent);
		mapContainer.onmousewheel = _wheelEvent;

		mapObject.addControl( new GLargeMapControl() );
		mapObject.addControl( new GOverviewMapControl() );
		mapObject.addControl( new GScaleControl());
		mapObject.addControl( new GMenuMapTypeControl());

		mapObject.enableScrollWheelZoom();
		mapObject.enableContinuousZoom();

}



function showHotelMap(_mapContainer,_lat,_lng,_adress,_hotelName,_hotel_id)
{

	var height = 0;
	var width = 0;
	var panorama;
        jQuery.ui.dialog.defaults.bgiframe=true;

	jQuery("#modalDialogGoogleMap").dialog
	({
                modal: false,
                closeOnEscape: true,
                title: 'Karte ' + _adress ,
                resizable: true,
                width: 700,
                height: 500,
		maxWidth: 1000,
                maxHeight: 800,
                open: function(event, ui)
                {
                	height = jQuery("#modalDialogGoogleMap").dialog('option', 'height') - 105;

                	jQuery("#modalDialogGoogleMap").html('<div id="'+_mapContainer+'" name="'+_mapContainer+'" style="background-color: #999; margin: 0px; padding: 0px; border: 3px double; border-color: #999; width: 675px; height:' + height+'px;"></div>');

                	__drawMap(_mapContainer,_lat,_lng,_hotelName,_hotel_id);


                },
                beforeclose: function(event, ui)
                {

                        jQuery("#modalDialogGoogleMap").dialog('destroy');
                },
                buttons:
                {
                        "Abbrechen": function()
                        {

                        	jQuery("#modalDialogGoogleMap").dialog('destroy');
                        },
                        "Home": function()
                        {

                        	__drawMap(_mapContainer,_lat,_lng,_hotelName,_hotel_id);
                        },
                        "Strassenansicht": function()
                        {

                        	panorama = __drawStreetMap(_mapContainer,_lat,_lng,_hotelName,_hotel_id);
                        },
                        "Kartenansicht": function()
                        {

                        	__drawMap(_mapContainer,_lat,_lng,_hotelName,_hotel_id);
                        }


                },
                resizeStop: function(event, ui)
                {
                	height = jQuery("#modalDialogGoogleMap").dialog('option', 'height');
                	width = jQuery("#modalDialogGoogleMap").dialog('option', 'width');
                	jQuery("#"+_mapContainer).height(height-105);
                	jQuery("#"+_mapContainer).width(width-25);
                	if (panorama)
                	{
                		panorama.checkResize();
                	}
                }
        });


}









