﻿$j(document).ready(function ()
{
    initLandingPageSlides();
});

var SlideShow = {
    slides: new Array(),
    currentSlide: 0,
    timerId: null,

    loadSlide: function (slideNumber)
    {
        if (typeof (slideNumber) == "undefined")
        {
            var lnRandomNumber = Math.floor(Math.random() * this.slides.length)
            slideNumber = lnRandomNumber;
        }

        SlideShow.currentSlide = slideNumber;
        $j("#holbornLandingPageContentLeft")[0].onclick = this.previousSlide;
        $j("#holbornLandingPageContentRight")[0].onclick = this.nextSlide;
        $j("#holbornLandingPageContent")[0].style.backgroundImage = "url(" + this.slides[slideNumber].imagePath + ")";
        $j("#holbornLandingPageContentTitle")[0].innerHTML = this.slides[slideNumber].titleText;
        $j("#holbornLandingPageContentCenterLink")[0].href = this.slides[slideNumber].linkUrl;
        $j("#holbornLandingPageContentCenterLink")[0].innerHTML = this.slides[slideNumber].linkText + "<img src=\"/Data/Sites/1/skins/HolbornCorporation/images/arrow.png\" alt=\"\" border=\"0\" style=\"padding-left:5px;padding-top:2px;\"/>";

        //Handle the color of the title
        if (typeof (this.slides[slideNumber].titleColor) != "undefined")
            $j("#holbornLandingPageContentTitle")[0].style.color = this.slides[slideNumber].titleColor;
        else
            $j("#holbornLandingPageContentTitle")[0].style.color = "#ffffff";



        //Handle the color of the sub descriptions
        if (this.slides[slideNumber].darkLink)
            $j("#holbornLandingPageContentCenterLink")[0].style.color = "#000000";
        else
            $j("#holbornLandingPageContentCenterLink")[0].style.color = "#ffffff";

        //Handle the target of the link
        if (typeof (this.slides[slideNumber].linkUrlTarget) != "undefined")
        {
            $j("#holbornLandingPageContentCenterLink")[0].target = this.slides[slideNumber].linkUrlTarget;
        }
        else
            $j("#holbornLandingPageContentCenterLink")[0].target = "_self";

        //Disable back button
        bajb_backdetect.OnBack = function ()
        {
            return true;
        }



        //Handle the slide show logic
        if (typeof (this.slides[slideNumber].isPresentation) != "undefined")
        {

            if (this.slides[slideNumber].isPresentation)
            {
                //Set the click event
                $j("#holbornLandingPageContentCenterLink").live("click", slideClickEvent);

                //Disable back button
                bajb_backdetect.OnBack = function ()
                {
                    var id = $j("#holbornLandingPageContentCenterLink")[0].nameProp.toString().replace('#', '');
                    var loElement = document.getElementById(id);
                    $j(loElement).hide();
                    $j('.window').hide();
                    $j('#mask').hide();
                    return false;
                };
            }
            else
            {
                //Clear Click Event
                $j("#holbornLandingPageContentCenterLink").die("click", slideClickEvent);

                //Reset Back Button
                bajb_backdetect.OnBack = function () { return true; };
            }

            window.clearInterval(this.timerId);
            this.timerId = window.setInterval("SlideShow.nextSlide()", 7500);
        }

    },

    nextSlide: function ()
    {
        if (SlideShow.currentSlide != SlideShow.slides.length - 1)
        {
            SlideShow.loadSlide(SlideShow.currentSlide + 1);
        }
        else
        {
            SlideShow.loadSlide(0);
        }

    },

    previousSlide: function ()
    {
        if (SlideShow.currentSlide >= 1)
            SlideShow.loadSlide(SlideShow.currentSlide - 1);
        else
        {
            SlideShow.loadSlide(SlideShow.slides.length - 1)
        }

    },

    cacheSlideImages: function ()
    {
        if (document.images)
        {
            for (var lnCount = 0; lnCount < this.slides.length; lnCount++)
            {
                var loImage = null;
                loImage = new Image(336, 861);
                loImage.src = this.slides[lnCount].imagePath;
            }
        }
    }
};


function initLandingPageSlides()
{
    SlideShow.slides.push(new Slide("Eye in the Sky", "/Data/Sites/1/skins/HolbornCorporation/images/lp_EITS.jpg", "Learn more about our interactive tool for viewing exposures.", "#EITS-SlideShow", true, { isPresentation: true }));
    SlideShow.slides.push(new Slide("A Different Perspective", "/Data/Sites/1/skins/HolbornCorporation/images/lp_perspective.jpg", "Our brochure explains the Holborn approach...", "#Capbilities-SlideShow", true, { titleColor: "#ee3224", isPresentation: true }));
    SlideShow.slides.push(new Slide("Claims Reporting", "/Data/Sites/1/skins/HolbornCorporation/images/lp_claims.png", "The claims process transformed, with a new level of transparency -- and more.", "#Claims-SlideShow", false, { isPresentation: true }));
    SlideShow.slides.push(new Slide("The 2012 Reinsurance Market: Changing Tides", "/Data/Sites/1/skins/HolbornCorporation/images/lp_marketupdate.jpg", "Holborn’s view of the market.", "/the-2012-reinsurance-market-changing-tides.aspx", false, { isPresentation: false }));
    SlideShow.slides.push(new Slide("Clients Say...", "/Data/Sites/1/skins/HolbornCorporation/images/lp_testimonials.jpg", "A few of our clients share their thoughts.", "#Testimonial-SlideShow", true, { isPresentation: true }));
    SlideShow.slides.push(new Slide("BestDay Video:  Holborn's 2012 Market Review", "/Data/Sites/1/skins/HolbornCorporation/images/bestvideo122011-3alt.png", "BestDay Video:  Holborn's 2012 Market Review", "http://bcove.me/278rsftt", false, { isPresentation: false }));

    SlideShow.loadSlide();
    SlideShow.cacheSlideImages();

    disableSelection($j('#leftArrow')[0]);
    disableSelection($j('#rightArrow')[0]);
    disableSelection($j('#holbornLandingPageContentTitle')[0]);
    disableSelection($j('#holbornLandingPageContent')[0]);

    $j('#leftArrow').css('cursor', 'hand');
    $j('#rightArrow').css('cursor', 'hand');

    //process this function whenever a key is pressed
    document.onkeyup = function (e)
    {
        //Next
        if (typeof (event) != "undefined")
        {
            if (typeof (event.keyCode) != "undefined")
            {
                if (event.keyCode == 37)
                {
                    SlideShow.previousSlide();
                }
                if (event.keyCode == 39)
                {
                    SlideShow.nextSlide();
                }
            }
        }
    };

}

function Slide(title, imgPath, lnkText, lnkUrl, darkLinkColor, options)
{
    this.imagePath = imgPath;
    this.titleText = title;
    this.linkText = lnkText;
    this.linkUrl = lnkUrl;

    if (typeof (darkLinkColor) == undefined)
        this.darkLink = false;
    else
        this.darkLink = darkLinkColor;


    if (typeof (options) != "undefined")
    {
        if (typeof (options.isPresentation) != "undefined")
        {
            this.isPresentation = options.isPresentation;
        }
        if (typeof (options.target) != "undefined")
        {
            this.linkUrlTarget = options.target;
        }

        if (typeof (options.titleColor) != "undefined")
        {
            this.titleColor = options.titleColor;
        }
    }
}

function disableSelection(target)
{

    if (typeof target.onselectstart != "undefined") //IE route
        target.onselectstart = function () { return false }

    else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
        target.style.MozUserSelect = "none"

    else //All other route (ie: Opera)
        target.onmousedown = function () { return false }

    target.style.cursor = "default"
}

function slideClickEvent(e)
{
    mbMaskLoading = true;
    //Get the A tag
    var id = $j("#holbornLandingPageContentCenterLink")[0].hash.toString().replace('#', '');
    msActiveFlashDiv = id;
    //Get the screen height and width
    var maskHeight = $j(document).height();
    var maskWidth = $j(window).width();

    ////Set height and width to mask to fill up the whole screen
    $j('#mask').css({ 'width': maskWidth, 'height': maskHeight });
    $j('#mask').css({ 'left': 0, 'top': 0, 'position': "absoulte", "z-index": 200 });

    //transition effect    
    $j('#mask').fadeIn(1000);
    $j('#mask').fadeTo("slow", 0.8);

    //Get the window height and width
    var winH = $j(window).height();
    var winW = $j(window).width();

    //Set the popup window to center
    var loElement = document.getElementById(id);

    $j(loElement).css("z-index", 201);
    $j(loElement).css('position', "absolute");
    $j(loElement).css('top', winH / 2 - $j(loElement).height() / 2);
    $j(loElement).css('left', winW / 2 - $j(loElement).width() / 2);

    //transition effect
    $j(loElement).fadeIn(1500);

    msMaskLoadingTimmer = window.setTimeout("setMaskLoaded();", 2000);

    return false;
}

