
var PrototypesObject = new Prototypes();
var isIE = false;
var isFirefox = false;
var isSafari = false;
var isIPhone = false;
var isIPad = false;
var agent = navigator.userAgent.toLowerCase();

var clearClick = true;
var currentPage = '';
var pageType = 1;

var gallery = new ThumbnailGallery();
var thumbnailScroller = new ThumbnailScroller();

 var videoPlayer;
 var lastPageEvents = false;

$(document).ready(function()
{
    if (agent.indexOf('msie') != -1) isIE = true;
    if (agent.indexOf('firefox') != -1) isFirefox = true;
    if (agent.indexOf('safari') != -1) isSafari = true;
    if (agent.indexOf('iphone') != -1) isIPhone = true;
    if (agent.indexOf('ipad') != -1) isIPad = true;

    $('#wrapper').width($(window).width());
    $('#wrapper').height($(window).height());

    initVideoBg();
    initMenu();
    initContent();
    initController();
    initNews();

    $(window).resize(function()
    {
        $('#wrapper').width($(window).width());
        $('#wrapper').height($(window).height());

        RPVideoBg();
        RPMenu();
        RPContent();
        RPController();
        RPNews();
    });

    $('#menu-logo').click(function()
    {
        if (currentPage != '' && clearClick){
            if (currentPage == 'hotel'){
                backMenu();
            }else{
                backMenu3();
            }
        }
    })
});

function initScroll()
{
    if (isIPhone || isIPad)
    {
        //$('#menu-list').css('overflow', 'scroll');
        $('#content-scroll').css('overflow', 'scroll');
    }
    else
    {
        $('#menu-list').jScrollPane();
        $('#content-scroll').jScrollPane();

        if (pageType == 1)
        {
            $('#content-scroll').width(700);
            $('.jspContainer', '#content-scroll').width(700);
            $('.jspPane', '#content-scroll').width(700);
        }
        else
        {
            $('#content-scroll').width(340);
            $('.jspContainer', '#content-scroll').width(340);
            $('.jspPane', '#content-scroll').width(340);
        }
    }
}

function setCookie(c_name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);

    document.cookie = c_name+"="+escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function validEmail(email)
{
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(email))
        {return true;}
    return false;
}

function initTexts(no)
{
    if (no == 1){
        for (var i=1; i<=parseInt(TextsNo); i++){
            $('#home-text-'+i).css('opacity', 0);
        }
    }
    if ($('#home-text').css('display') == 'block' && currentPage == '')
    {
        $('#home-text-'+no).css('display', 'block');
        $('#home-text-'+no).css('opacity', '0');
        $('#home-text-'+no).stop(true, true).animate({'opacity':'1'}, 600, function()
        {
            if (currentPage == ''){
                setTimeout(function()
                {
                    $('#home-text-'+no).stop(true, true).animate({'opacity':'0'}, 600, function()
                    {
                        $('#home-text-'+no).css('display', 'none');
                        if (currentPage == ''){
                            if (no == parseInt(TextsNo)) initTexts(1);
                            else initTexts(no+1);
                        }
                    });
                }, 3000);
            }
            else{
                $('#home-text-'+no).css('display', 'none');
            }

        });
    }
}
