$(document).ready(function() {
    
    /*
        Overlay
    */
    var overlayHeight = $(document).height();
    $('#loading_overlay').height(overlayHeight);
    $('#loading_overlay').css("visibility", "visible");
    
    if($("input[name='showOverlayOnLoad']").val() == 1) {
        $('#loading_overlay').show();
        $("div#loading").html('<img src="fileadmin/images/global/loader.gif" />');
    } else {
        $('#loading_overlay').hide();
    }
    
    $('span.close').click(function () {
        $('#form_overlay').fadeOut('fast');
        $('#loading_overlay').fadeOut('fast');
    });
    
    
    /*
        Filter der Suche - Rechte Spalte
    */
    $('#formFilterProperty').submit(function() {
        $('#buttonPropertyName').css('display', 'none');
        $('#buttonPropertyName').css('float', 'none');
        $('#ajaxLoadingPropertyName').css('float', 'left');
        
        $('#formFilterProperty').css({
            'background-image' : 'url(fileadmin/images/global/ajax-loader.gif)',
            'background-repeat' : 'no-repeat',
            'background-position' : '190px 22px'
        });
    });
    
    $('select#landmark').change(function() {
        if($('select#landmark').selectedIndex != 0) {
            $('#formFilterLandmark').submit();
            $('#formFilterLandmark').css({
                'background-image' : 'url(fileadmin/images/global/ajax-loader.gif)',
                'background-repeat' : 'no-repeat',
                'background-position' : '190px 22px'
            });
        }
    });
    
    
    
    /*
        Language-Switch
    */
    $('li#dropdownNavLng').hover(function () {
        $(this).children('div#SiteNav-subnavLng').show();
    },
    function () {
        $(this).children('div#SiteNav-subnavLng').hide("fast");
    });
    
    /*
        Kundenservice Nav
    */
    var subnavWidth = $('li#main_navigation_item_3').width();
    
    $('li#main_navigation_item_3').hover(function () {
        $(this).children('ul').css({
            'width': subnavWidth
        });
        $(this).children('ul').show();
    },
    function () {
        $(this).children('ul').hide();
    });
    
	/* Toggle Hotel-Detail Panel: Hotelausstattung */
	$('div.hotel_facilities').addClass("hotel_facilities_collapsed");
	$('div.hotel_facilities a.bottom_link').addClass("block");
	$('div.hotel_facilities a.bottom_link').click(function () {
        $('div.hotel_facilities').toggleClass("hotel_facilities_expanded");
        $('div.hotel_facilities').toggleClass("hotel_facilities_collapsed");
    });
    
    /* Toggle Hotel-Detail Panel: Zimmerausstattung */
    $('div.hotel_categories').addClass("hotel_categories_collapsed");
	$('div.hotel_categories a.bottom_link').click(function () {
        $(this).parent('div.hotel_categories').toggleClass("hotel_categories_collapsed");
        $(this).parent('div.hotel_categories').toggleClass("hotel_categories_expanded");
    });
	
	/* Carousels */
	$('div#main_gallery, div#sub_gallery').removeClass("nojs");
    
	$("#carousel_large").jcarousel({
        scroll: 4,
        initCallback: carouselStart_initCallback
    });
    function carouselStart_initCallback(carousel) {
        $('.jcarousel-control a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false;
        });
    };
    
    /*
        Startseite Euerope Hotels - Controls
    */
    
    $('a.control-1').addClass("active");
    
    $('a.control-1').click(function () {
        $(this).addClass("active");
        $(this).removeClass("sub");
        $('a.control-2').removeClass("active");
        $('a.control-2').addClass("sub");
    });
    $('.jcarousel-next').click(function () {
        $('a.control-2').addClass("active");
        $('a.control-2').removeClass("sub");
        $('a.control-1').addClass("sub");
        $('a.control-1').removeClass("active");
    });
    
    $('a.control-2').click(function () {
        $(this).addClass("active");
        $(this).removeClass("sub");
        $('a.control-1').removeClass("active");
        $('a.control-1').addClass("sub");
    });
    
    $('.jcarousel-prev').click(function () {
        $('a.control-1').addClass("active");
        $('a.control-1').removeClass("sub");
        $('a.control-2').addClass("sub");
        $('a.control-2').removeClass("active");
    });
    

	/* Tabs on Hotel-Detail */

    
    $('.hotel_detail_head a.button').mousedown(function() {
        $tabs.tabs('select', 2);
        return false;
    });

    
    /* ScrollTo */
    $("#content_left .index_list").localScroll();
});






var Hoteles = {} //Namespace hoteles

Hoteles.ToggleVisible = function (TargetID, sender) {
    var theTarget = document.getElementById(TargetID);
    var displayStyle = theTarget.currentStyle ? theTarget.currentStyle.display : (document.defaultView && document.defaultView.getComputedStyle) ? document.defaultView.getComputedStyle(theTarget, "").getPropertyValue('display') : '';

    if (displayStyle == 'block') {
        theTarget.style.display = 'none';
        sender.innerHTML = sender.innerHTML.replace("Ocultar", "Ver");
    }
    else {
        theTarget.style.display = 'block';
        sender.innerHTML = sender.innerHTML.replace("Ver", "Ocultar");
    }
    return false; //Cancel click
}

Hoteles.LoadGalleryPic = function (PicSrc) {
    document.getElementById('GalleryMainPic').src = PicSrc;
}

//
function loading_overlay_size() {
    if (window.navigator.userAgent.indexOf("MSIE ") > -1 &&
        parseFloat(navigator.appVersion) >= 4) {
        $('loading_overlay').setStyle({
            'height' : $('PageContainer').getHeight() - 97 + 'px'
        });
    } else {
        $('loading_overlay').setStyle({
            'height' : $('PageContainer').getHeight() - 82 + 'px'
        });
    }
}





function set_correct_credit_card_image(selected_value)
{
	credit_card_images = new Array();
	credit_card_images[0] = 'creditcard.jpg';
	credit_card_images[1] = 'creditcard.jpg';
	credit_card_images[2] = 'creditcard.jpg';
	credit_card_images[3] = 'en_amex.gif';
	credit_card_images[4] = 'creditcard.jpg';
	credit_card_images[5] = 'creditcard_diner_club.jpg';

	creadit_card_keys = new Array();
	creadit_card_keys[0] = 'VI';
	creadit_card_keys[1] = 'MC';
	creadit_card_keys[2] = 'T';
	creadit_card_keys[3] = 'AX';
	creadit_card_keys[4] = 'E';
	creadit_card_keys[5] = 'DC';
	for (var i = 0; i < creadit_card_keys.length; ++i)
	{
		if (creadit_card_keys[i] == selected_value)
		{
			document.getElementById('credit_card_image').src = 'fileadmin/images/registrierung/' + credit_card_images[i];
			return 1;
		}
	}
	document.getElementById('credit_card_image').src = 'fileadmin/images/registrierung/' + 'blank_credit_card.JPG';
}

//   @TP 2011/03/04 Expands or collapses the hotel description
// [+@ START]
var objExpandable = {
    bolExpanded : false,
    objDescription : null,
    objContent : null,
    objLink : null,
    strText : "", 


    // Expands or collapses the description
    toggleDescription : function ()
    {
        var intDiff = 0;
        var objThis = this;

        // Expand or collapse?
        if (!this.bolExpanded)
        {
            intDiff = this.objContent.outerHeight();
        }
        else
        {
            intDiff = 323;
        }

        // Animate
        this.objDescription.animate({
            height: intDiff
        }, 750 , function()
        {
            // Save the old text
            var _strText = objThis.objLink.html();
            objThis.bolExpanded = !objThis.bolExpanded;
            
            // Change the link
            objThis.objLink.html(objThis.strText);
            objThis.strText = _strText;

            // CSS class
            objThis.objLink.toggleClass('expand', !objThis.bolExpanded);
            objThis.objLink.toggleClass('collapse', objThis.bolExpanded);
        });
    }
};
// [+@ END]
