var BASE_URL = 'http://www.freedreams.ch/';

if(DOMAIN_NAME)
	var BASE_URL = DOMAIN_NAME;


var IS_POP_MAP = false;
var EUR_TO_CHF_FACTOR = 1.65;

$(function() {
    //    hotel images switcher
    try {
        var buttons = []; 
        var len     = $('#images-container ul li').length;
        
        if(len > 1)
        {       
            for(var i = 1; i <= $('#images-container ul li').length; i++)
            {    
                $('#buttons').append('<li><a href="#" class="button-'+i+'">'+i+'</a></li>');
                buttons.push('#buttons .button-'+i);            
            }
	    }
                                
        $('#images-container').jCarouselLite({
            btnNext: '#image-next',
            btnPrev: '#image-prev',
            btnGo:   buttons,
            circular: false,
            visible: 1
        });
    } catch(e){};
    
    //    rootmenu login box
	 /*
     if(show_login_box == 0){
	    try {
	        $('#my-freedreams a').click(function(){
	            $('#login-box').slideToggle('fast');
	            return false;
	        });
	        
	    } catch(e){};
	 }
    */

     try {
        //  hotel details map

        if(!GBrowserIsCompatible())
        {   throw 'apiError';
        }
        if(hotelDetailsLAT == 0 || hotelDetailsLNG == 0)
        {   throw 'badCoords';
        }
        
        hotelMapContainer   = document.getElementById('hotel-details-map');
        
        if(!hotelMapContainer)
        {   throw 'apiError';
        }

        hotelMapObject      = new GMap2(hotelMapContainer);
        hotelMapObject.addControl(new GSmallMapControl());
        hotelMapObject.setCenter(new GLatLng(hotelDetailsLAT, hotelDetailsLNG), 8);
        
        hotelDetailsPrice   = Math.ceil(hotelDetailsPrice*EUR_TO_CHF_FACTOR);

        if(hotelDetailsPrice < 55)
        {   
            baseIcon   = BASE_URL+'images/maps/gmap-icon-hotel-lvl3.png';
            hoverIcon  = BASE_URL+'images/maps/gmap-icon-hotel-lvl3-hover.png';
        }
        else if(hotelDetailsPrice > 80)
        {   
            baseIcon   = BASE_URL+'images/maps/gmap-icon-hotel-lvl2.png';
            hoverIcon   = BASE_URL+'images/maps/gmap-icon-hotel-lvl2-hover.png';
        }
        else
        {   
            baseIcon   = BASE_URL+'images/maps/gmap-icon-hotel-lvl1.png';
            hoverIcon  = BASE_URL+'images/maps/gmap-icon-hotel-lvl1-hover.png';
        }

        //console.debug(hotelDetailsPrice);

        var icon                = new GIcon();
        icon.image              = baseIcon;
        icon.iconSize           = new GSize(24, 24);
        icon.iconAnchor         = new GPoint(6, 20);
        icon.infoWindowAnchor   = new GPoint(5, 1);
        
        var marker              = new GMarker(new GLatLng(hotelDetailsLAT, hotelDetailsLNG), {icon: icon, title: hotelDetailsName });
        
        GEvent.addListener(marker, 'mouseover', function(){
            this.setImage(hoverIcon);
        });

        GEvent.addListener(marker, 'mouseout', function(){
            this.setImage(baseIcon);
        });
        
        hotelMapObject.addOverlay(marker);
     }
     catch(e)
     {   
         if(e == 'badCoords')
         {  
				if(maplang == "de")
					$('#hotel-details-map').html('<div id="map-api-error" style="padding-top:70px">Dieses Hotel kann nicht auf der Karte angezeigt warden.</div>');
				else
					$('#hotel-details-map').html('<div id="map-api-error" style="padding-top:70px">Cet h&#244;tel ne peut pas être visualis&#233; sur la carte</div>');

         }
         if (e == 'apiError')
         {  $('#hotel-details-map').html('<div id="map-api-error" style="padding-top:85px">Your browser does not support GoogleMaps API</div>');
         }
     };
    
    try {
                
        $('#map-filters').submit(function(){ 
            try {
                viewMode = 'filter';
                DataLoader.loadHotels('filters');
            } catch(e) {};
            return false; 
        });
        $('#map-filters').find('select, input').attr('disabled', true);    

        $(document).unload(function(){
            mapFilters      = null;
            mapContainer    = null;
            mapObject       = null;
            countryMarkers  = null;
            regionMarkers   = null;
            hotelMarkers    = null;
            countries       = null;
            regions         = null;
            hotels          = null;
            data            = null;
        });
    }
    catch(e){};




	 // order kreditkarte

    try {
        $("input[name='zahlungsart']").click(function(){
            
            if($(this).val() == 'Kreditkarte')
            {   $("#Kartentyp, #Kartennummer, #CVV, #exp2, #exp").attr('disabled', false);
            }
            else
            {   $("#Kartentyp, #Kartennummer, #CVV, #exp2, #exp").attr('disabled', true);
            }
        });
    }
    catch(e) {alert(e)};

    // hotel details map pop up
    try {
        $("#hotel-map-enlarge").click(function(){
            
            var hotelNo = $(this).attr('href').split('#')[1].split('-')[1];
            var top     = (screen.availHeight - 655) / 2;
            var left    = (screen.availWidth - 560) / 2;
            var opts    = 'height=675,width=560,resizable=yes,scrollbars=auto,top='+top+',left='+left;
            var win     = window.open(BASE_URL+'hotelMapEnlarge.php?hotel='+hotelNo,'hotel_map_enlarge',opts);            
            win.focus();
        });
    }
    catch(e) {alert(e)};

    try {
        $('#toggle-vershenken').click(function(){
            $('#vershenkenholder').toggle('fast');
				
				ajba = document.getElementById('verschenken');
				
				if(ajba.value == 1)
					ajba.value=0;
				else
					ajba.value=1;
            return false;
        });
    }
    catch(e){};
	
    try {
        if(typeof initMap != 'undefined')
        {   initMap();
        }
    }
    catch(e){};

});