﻿jQuery(function ($) {
    var fadingSpeed = 1000; // speed of the fading effect applied to slideshow image and text
    var intBannerCount = $('div#StoryboardBanner').children('img').size();
    $('div#StoryboardBanner .slide').each(function(index) {

        // var caption = ("slideshow_caption" + index);


        var strIndex = $("img", this).attr('index'), strTextColour = $("img", this).attr('text'), strLinkColour = $("img", this).attr('link');
        var boolHomePage = ($('div#HomeHeadline').length == 1);


        if (strTextColour == '')
            strTextColour = 'black';
        if (strLinkColour == '')
            strLinkColour = '#969c23'; // olive

        var intTop, intLeft;

        switch ($("img", this).attr('pos')) {
            case 'Top Left':
            default:
                intTop = 40;
                intLeft = 57;
                break;
            case 'Bottom Left':
                intTop = (boolHomePage) ? 220 : 190;
                intLeft = 57;
                break;
            case 'Top Right':
                intTop = 40;
                intLeft = 610;
                break;
            case 'Bottom Right':
                intTop = (boolHomePage) ? 220 : 190;
                intLeft = 610;
                break;
        }
        var divToInsert = $("div[id='slideshow_caption" + strIndex + "']")
				.css('left', intLeft + 'px')
				.css('top', intTop + 'px')
				.css('color', strTextColour)
                .addClass("layerSlideshowOverlay");

        $('*', divToInsert).css('color', strTextColour);
        $('a', divToInsert).css('color', strLinkColour);

    });

    // Univers (700 weight); and must attach JS of font family in head; doc http://github.com/sorccu/cufon/wiki/API
    Cufon.set('fontFamily', 'Univers').set('fontWeight', 'normal').replace('div.layerSlideshowOverlay');
	Cufon.set('fontFamily', 'Univers').set('fontWeight', '700').replace('div.layerSlideshowOverlay div.h1');
    Cufon.set('fontFamily', 'Univers').set('fontWeight', 'normal').replace('div.layerSlideshowOverlay p');
  


    $('div#StoryboardBanner').cycle({
        fx: 'fade',
        speed: fadingSpeed,
        timeout: 6000,
        pager: 'ul#SlideshowPaging',
        startingSlide: Math.floor(Math.random() * intBannerCount),
        // callback fn that creates a thumbnail to use as pager anchor 
        pagerAnchorBuilder: function (idx, slide) {
            return '<li><a href="javascript:;">' + (idx + 1) + '</a></li>\n';
        }
    });
});
