$(function () {

    /**///instrukcje dla IE lte 9
    if ($.browser.msie && $.browser.version < 9) {
        $("table").attr('cellspacing', '0').find("tbody tr:nth-child(2n)").addClass("odd");
        $("blockquote p:last-child, #secondary .module:last-child").addClass("last-child");
        $(".listing-triple li:nth-child(3n+4), #offer-map-toolbar li:nth-child(2n)").addClass("nth-child");
        $("#offer-map-toolbar li:nth-child(2n+3)").addClass("clear");
    }

    /**///instrukcje dla Opery
    if ($.browser.opera) {
        $("body").addClass("opera");
    }

    /**///FAQs folding
    $("#faq > li div").addClass("hide");
    $("#faq > li h2 a").click(function (event) {
        event.preventDefault();
        $(this).parent("h2").next("div").toggleClass("hide");
    });

    /**///gallery
    //create first image
    //	var firstImgSrc		= $("#thumbs a").attr("href");
    //	var firstImgHtml	= '<img src="'+firstImgSrc+'" alt="" />';
    //	$("#main-image").prepend(firstImgHtml);
    //change on clickin the thumb
    $("#thumbs a").live("click", function (event) {
        event.preventDefault();


        var i = 0;
        var imgs = $("#main-image img");
        var fi = 0;
        for (i = 0; i < imgs.length; i++) {
            if (imgs[i].src == this.href)
                fi = i;
        }
        $('#gallery div').cycle('destroy');

        CreateHotelPicturesCycle(fi);
    });

    /**///tabs

    $("#tabs").tabs();

    $('#tabs').bind('tabsshow', function (event, ui) {
        
        
        if (ui.panel.id.match("man-and-attractions") == "man-and-attractions") {
            
            LoadHotelMap();
        }
    });


    /**///colorbox if needed
    $("a[rel='gallery'], a.thumbnail").colorbox({
        opacity: 0.65
    });

    /**///lightbox me - popup on home
    $('#ghg-promise-trigger-1').click(function (event) {
        event.preventDefault();
        $('#ghg-promise-popup-1').lightbox_me({
            //centered: true, 
            modalCSS: { top: '164px' },
            closeSelector: ".popup-close",
            overlayCSS: { background: 'transparent', opacity: 0 }
        });
    });

    /**///lightbox me - popup on home
    $('#ghg-promise-trigger-2').click(function (event) {
        event.preventDefault();
        $('#ghg-promise-popup-2').lightbox_me({
            //centered: true, 
            modalCSS: { top: '164px' },
            closeSelector: ".popup-close",
            overlayCSS: { background: 'transparent', opacity: 0 }
        });
    });

    /**///lightbox me - popup on home
    $('#ghg-promise-trigger-3').click(function (event) {
        event.preventDefault();
        $('#ghg-promise-popup-3').lightbox_me({
            //centered: true, 
            modalCSS: { top: '164px' },
            closeSelector: ".popup-close",
            overlayCSS: { background: 'transparent', opacity: 0 }
        });
    });

    /**///slideshow on home
    $("#slideshow ul").cycle({
        fx: 'fade',
        speed: 4500,
        timeout: 7000,
        pause: 0
    });








});


function ScrollView(element) {
    var el = element.parent().parent();
    $('html,body').animate({ scrollTop: el.offset().top }, { duration: 'slow', easing: 'swing' });
}

function ScrollToSpecialOffer() {

    var $tabs = $('#tabs').tabs(); // first tab selected
    var length = $tabs.tabs("length");
    $tabs.tabs('select', length-1);
    ScrollView($('#exclusiveOfferTab'));
}

function showHelp() {
    window.open('help.htm', 'help', 'width=200,height=60,toolbar=0,resizable=1,scrollbars=1,screenX=200,screenY=200,left=200,top=200');
    return false;
}

function showPrivacy() {
    window.open('privacy.htm', 'privacy', 'width=432,height=270,toolbar=0,resizable=1,scrollbars=1,screenX=200,screenY=200,left=200,top=200');
    return false;
}

function centerSlideshowPicture(imageObject) {
    if ($('body').width() >= 800) {
        imageObject.css('height', '310px');
        var imageWidth = imageObject.width();
        var containerWidth = $("#gallery div").width();
        imageObject.css('margin-left', ((containerWidth - imageWidth) / 2) + 'px');
    }
}

function CreateHotelPicturesCycle(startIndex) {
    $("#gallery div").cycle({
        fx: 'fade',
        speed: 3500,
        timeout: 2000,
        pause: 0,
        startingSlide: startIndex

    });
}

$(document).ready(function () {
    $("#hotelOfTheWeek div").cycle({
        fx: 'fade',
        speed: 3500,
        timeout: 2000,
        pause: 0

    });
    CreateHotelPicturesCycle(0);
});
