﻿$(document).ready(function () {

    //rollover effect on links 
    $("a.simplehover img, img.simplehover").mouseover(function () {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function () {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });


    //Add hint to the search box
    $('.searchbox').hint();


    //Start the rotating banner
    $('#slider').nivoSlider({
        effect: 'fade',
        pauseTime: 5000,
        beforeChange: function () {
            $(".toprightfade").fadeTo(1000, 0.01);
        },
        afterChange: function () 
        {
            $(".news-movietitle").text($(".graybar-newsname").text());
            $(".movieintro").text($(".graybar-synopsis").text());
            //$(".moviedescription").text($(".graybar-content").text());
            $(".moviedescription").text($(".graybar-content").text().substring(0, $(".graybar-content").text().indexOf('...') + 3));
            $(".news-readmore a").attr("href", $(".news-readmore a").attr("href").substring(0, $(".news-readmore a").attr("href").lastIndexOf(".aspx") + 5) + "?i=" + $(".graybar-newsid").text());
            //$(".news-readmore a").attr("href", $(".news-readmore a").attr("href").substring(0, $(".news-readmore a").attr("href").lastIndexOf(".aspx") + 5) + "?i=" + $(".graybar-newsid").text());

            $(".toprightfade").fadeTo(500, 1);

            ResizeMovieTitle();
        }
    });


    //start the thumbnails carousel
    $('#jcarousel').jcarousel({ initCallback: mycarousel_initCallback, wrap: 'last', scroll: 2, animation: 1000 });
    function mycarousel_initCallback(carousel) {
        $('.thumbs-prev').click(function () { carousel.prev(); return false; });
        $('.thumbs-next').click(function () { carousel.next(); return false; });
    };


    //Highlight the large boxes on the homepage
    $(".homepreviews").bind("mouseenter", function () {
        $(this).children(".homepreviews-hover").stop(true, true).fadeIn(400);
    }).bind("mouseleave", function () {
        $(this).children(".homepreviews-hover").stop(true, true).fadeOut(150);
    });

    //load lazy load (problem with the rotating items)
    //$("img").lazyload({ effect: "fadeIn", threshold: 25 });

    //----Award and press Popup Start----
    //$(".awards-popup").overlay({ load: true, fixed: true });
    //$(".press-popup").overlay({ load: true });

    $(".modalmask").hide();
    $(".IEmask").hide();
    $(".awards-popup").hide();
    $(".press-popup").hide();
    $(".popup").hide();

    $("#btn-popupawards").click(function () {

        var winH = $(window).height();
        var winW = $(window).width();

        $("#divPopup").html($("#awards-popup").html());

        //Set the popup window to center
        $(".popup").css('top', winH / 2 - $(".popup").height() / 2);
        $(".popup").css('left', winW / 2 - $(".popup").width() / 2);

        $(".modalmask").css('filter', 'alpha(opacity=60)');
        $('.modalmask').css({ 'width': $(window).width(), 'height': $(document).height() });
        $(".modalmask").fadeIn("slow");
        $(".popup").fadeIn("slow");
    });

    $("#btn-popuppress").click(function () {

        var winH = $(window).height();
        var winW = $(window).width();

        $("#divPopup").html($("#press-popup").html());

        //Set the popup window to center
        $(".popup").css('top', winH / 2 - $(".popup").height() / 2);
        $(".popup").css('left', winW / 2 - $(".popup").width() / 2);

        $(".modalmask").css('filter', 'alpha(opacity=60)');
        $('.modalmask').css({ 'width': $(window).width(), 'height': $(document).height() });
        $(".modalmask").fadeIn("slow");
        $(".popup").fadeIn("slow");
    });

    $(".modalmask").click(function () {
        $(".modalmask").fadeOut("slow");
        $(".IEmask").fadeOut("slow");
        $(".popup").fadeOut("slow");
    });
    //----Award Popup End----

    /*Awards Expose
    $("#btn-popupawards").click(function () {
    $(".awards-popup").expose({
    onBeforeLoad: function () { $(".awards-popup").fadeIn("slow"); },
    onBeforeClose: function () { $(".awards-popup").fadeOut("slow"); }
    });
    });

    //Press Expose
    $("#btn-popuppress").click(function () {
    $(".press-popup").expose({
    onBeforeLoad: function () { $(".press-popup").fadeIn("slow"); },
    onBeforeClose: function () { $(".press-popup").fadeOut("slow"); }
    });
    });*/




    if ($.browser.msie) { $(".tooltipme[title]").tooltip({ position: "center right", offset: [0, -10] }); }
    else { $(".tooltipme[title]").tooltip({ position: "center right", offset: [0, -10] }); }

});

//Top right box need a width which cannot be determined with css.
$(document).ready(function() { SetTopRightBoxWidth(); SetButtonsBesideDescription(); ResizeMovieTitle(); });
$(window).resize(function() { SetTopRightBoxWidth(); SetButtonsBesideDescription(); ResizeMovieTitle(); });

function SetTopRightBoxWidth() { $('.toprightbox').css("width", $("#wrapper").width() - 660); }

function SetButtonsBesideDescription() {

    if ($(".toprightbuttons").width() > 650) {
        $('.toprightfade').css("width", 375);
    }
    else { $('.toprightfade').css("width", "100%"); }
}


//Resize text h1
function ResizeMovieTitle() {
    $(".movietitle").css("font-size", "40px");
    
    while ($(".movietitle").width() > $(".movietitle-englober").width())
    {
        var dFontsize = parseFloat($(".movietitle").css("font-size"), 10);
        $(".movietitle").css("font-size", dFontsize - 1);
    }
}

//parse URL to get values
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
