﻿$(document).ready(function() {
    $("a.booking").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'overlayColor': '#000',
        'overlayOpacity': 0.4,
        'width': 480,
        'height': 550
    });

    $("a.gmaps").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'overlayColor': '#000',
        'overlayOpacity': 0.4,
        'width': 670,
        'height': 470
    });

    $("a.ourstory").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'overlayColor': '#000',
        'overlayOpacity': 0.4,
        'width': 600,
        'height': 600,
        'padding': 0
    });

    $("a.copyright").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'overlayColor': '#000',
        'overlayOpacity': 0.4,
        'width': 660,
        'height': 66,
        'padding': 0
    });

    $("a.imageviewer").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'overlayColor': '#000',
        'overlayOpacity': 0.4,
        'padding': 0,
        'titleShow': false,
        'autoScale': true
    });

    $("#contactcontent").hide();
    $(".contact").click(function() {
        $("#contactcontent").slideToggle("fast");
    });

    $(".expandcontent").hide();
    $("#expandbar").hide();

    $(".collapsecontent").click(function() {
        $("#content").animate({ width: 'toggle' }, 'normal');
        $(".collapsecontent").hide();
        $("#bg").css("width", "240px");
        $(".expandcontent").show();
        $("#expandbar").show();
    });

    $(".expandcontent").click(function() {
        $("#content").animate({ width: 'toggle' }, 'normal');
        $(".collapsecontent").show();
        $("#bg").css("width", "974px");
        $(".expandcontent").hide();
        $("#expandbar").hide();
    });

    $("#slider").easySlider({
        auto: false,
        continuous: false,
        speed: 500
    });

    $('#text').jScrollPane({
        showArrows: true,
        animateStep: '90'
    });
});

$(window).load(function() {
    var $secondimage = true;

    var $myPictures = new Array();
    var $nummerPic = 0;

    $("#backgroundimages a").each(function(index) {
        $myPictures[index] = $(this).attr("href");
    });

    checkRatio();

    $(window).resize(function() {
        checkRatio();
    });

    var intervalBgImg;

    if ($myPictures.length > 1) {
        startbgTimer();
    }

    function startbgTimer() {
        intervalBgImg = setInterval(function() {
            $nummerPic++;

            if ($nummerPic >= $myPictures.length) {
                $nummerPic = 0;
            }

            loadTargetPic();

        }, 7500);
    }

    function clearbgTimer() {
        clearInterval(intervalBgImg);
    }

    function loadTargetPic() {
        if ($secondimage) {
            $('#backgroundimages img.backgroundImage2').load(function() {
                if ($.browser.msie && $.browser.version < 9) {
                    $('#backgroundimages img.backgroundImage1').css({ "display": "none" });
                } else {
                    $('#backgroundimages img.backgroundImage1').fadeOut('slow');
                }
            }).attr("src", $myPictures[$nummerPic]);
            $secondimage = false;
        }
        else {
            $('#backgroundimages img.backgroundImage1').load(function() {
                if ($.browser.msie && $.browser.version < 9) {
                    $('#backgroundimages img.backgroundImage1').css({ "display": "block" });
                } else {
                    $('#backgroundimages img.backgroundImage1').fadeIn('slow');
                }
            }).attr("src", $myPictures[$nummerPic]);
            $secondimage = true;
        }
    }

    function checkRatio() {
        var $settingMarginLeft = 0;
        var $targetWidth = $(window).width() - $settingMarginLeft;
        $('#backgroundimages .backgroundImage1, #backgroundimages .backgroundImage2').css({ "width": $targetWidth + "px", "height": "auto", "margin-left": $settingMarginLeft + "px" });

        if ($(window).height() > $('#backgroundimages img.backgroundImage1').height()) {
            $('#backgroundimages .backgroundImage1, #backgroundimages .backgroundImage2').css({ "width": "auto", "height": "100%", "margin-left": $settingMarginLeft + "px" });
        }
    }
});

