﻿
//  don't delete this -  it is a VS script reference to the jQuery file, and allows intellisense to almost work
/// <reference path="~/scripts/jquery-1.3.2.js" />

var lclSpotlights = new Array();
var lclSpotlightCount = 0;
var numbersToShow = 5; // must be 3, 5, 7, 9 etc....

//these are the element ids and get set in the cs file
var lclSpotlightImage = "";
var lclSpotlightTitle = "";
var lclSpotlightSummary = "";
var lclSpotlightImageLink = "";
var lclPagingDiv = "";
var lclSpotlightDiv = "";

var txtNext = "";
var txtPrevious = "";
var txtSpotlight = "";
var txtHiddenText = "";

function lclPrintPagingNumbers(current)
{

    // here we are adding the paging links to the screen
    if (lclSpotlightCount > 1)
    {
        //there is an amazing amount of html around each number so put it into two strings to spare your sanity
        var partOne = '<div class="topLeft"><div class="bottomRight"><div class="bottomLeft"><div class="topRight">';
        var partTwo = '<div class="clear"></div></div></div></div></div>';
        
        
        // for each spotlight in the list add the right number
        var html = '<ul class="rotatorNav">';
        
        // left arrow if needed
        if (current > 0)
            html = html + '<li><div class="rotatorButton">' + partOne + '<a class="rotatorNavBtn" title="' + txtPrevious + '" href="javascript:lclDisplaySpotlight(' + (current - 1) + ')"><img src="/Images/WycombeMainSite/nav/rotator/blank.gif" class="rotatorNavBtnPrev" alt="' + txtPrevious + '" /></a>' + partTwo + '</div></li>';


        // work out the start and end points
        var offSet = (numbersToShow - 1) / 2, start = 0, end = numbersToShow < lclSpotlightCount ? numbersToShow : lclSpotlightCount;
        if (current > offSet)
        {
            end = current + offSet + 1 < lclSpotlightCount ? current + offSet + 1 : lclSpotlightCount;
            start = end > current + offSet ? current - offSet : (lclSpotlightCount > numbersToShow ? lclSpotlightCount - numbersToShow : 0);
        }

        // then print the numbers
        for (i = start; i < end; i++)
        {
            if (i === current)
                html = html + '<li><div class="rotatorButtonSelected">' + partOne + '<a>' + (i + 1) + '</a>' + partTwo + '</div></li>';
            else
                html = html + '<li><div class="rotatorButton">' + partOne + '<a href="javascript:lclDisplaySpotlight(' + i + ')" title="' + txtSpotlight + ' ' + (i + 1) + '"><span class="hide">' + txtSpotlight + '</span>' + (i + 1) + '</a>' + partTwo + '</div></li>';
        }

        // print the end arrow if needed
        if (current < lclSpotlightCount - 1)
            html = html + '<li><div class="rotatorButton">' + partOne + '<a class="rotatorNavBtn" title="' + txtNext + '" href="javascript:lclDisplaySpotlight(' + (current + 1) + ')"><img src="/Images/WycombeMainSite/nav/rotator/blank.gif" class="rotatorNavBtnNext" alt="' + txtNext + '" /></a>' + partTwo + '</div></li>';
            
        html = html + '</ul><div class="clear"></div>';
        document.getElementById(lclPagingDiv).innerHTML = html;
    }
}

function lclDisplaySpotlight(selected)
{
    // reset the background image
    var currentSpotlight = lclSpotlights[selected];
    $('#' + lclSpotlightDiv).fadeOut('fast').queue(function()
    {
        // image
        $('#' + lclSpotlightImage).attr("src", currentSpotlight.Path);
        $('#' + lclSpotlightImage).attr("alt", currentSpotlight.Title);
        $('#' + lclSpotlightImage).attr("title", currentSpotlight.Title);

        //links, title and summary
        $('#' + lclSpotlightSummary).html(currentSpotlight.Summary);
        $('#' + lclSpotlightTitle).html(currentSpotlight.Title);
        if (currentSpotlight.IsLinkWrapper)
        {
            $('#' + lclSpotlightTitle).attr("href", "");
            $('#' + lclSpotlightImageLink).attr("href", "");
        } else
        {
            $('#' + lclSpotlightTitle).attr("href", currentSpotlight.Link);
            $('#' + lclSpotlightImageLink).attr("href", currentSpotlight.Link);
        }
        
        $('#' + lclSpotlightDiv).dequeue();
    }).fadeIn('fast');

    if (currentSpotlight.IsLinkWrapper)
    {
        document.getElementById("aRotatorID").setAttribute("target", "_blank");
        document.getElementById("aRotatorID").onclick = function() { eval(currentSpotlight.OnClick); return false; };
    }
    else
    {
        document.getElementById("aRotatorID").removeAttribute("target");
        document.getElementById("aRotatorID").onclick = function() { return true; };
    }

    // then sort the paging numbers
    lclPrintPagingNumbers(selected);
}


function lclAddSpotlight(contentID, path, link, title, summary, isLinkWrapper, onclickLink)
{
    var spotlight = new Object();
    spotlight.ContentID = contentID;
    spotlight.Path = path;
    spotlight.Link = link;
    spotlight.Title = title;
    spotlight.Summary = summary;
    spotlight.IsLinkWrapper = isLinkWrapper;

    if (isLinkWrapper)
        spotlight.OnClick = onclickLink;
    else
        spotlight.OnClick = "";
    
    lclSpotlights[lclSpotlightCount] = spotlight;
    lclSpotlightCount++;
}



