﻿/// <reference path="lib/jquery-1.4.2.min.js" />
//Vars

var tminus;
var days;
var hours;
var minutes;
var seconds;

/********************* 
* Countdown
***********************/


function setClock(now, target) {

    tminus = (target - now) / 1000;

    runClock();
    timer = setInterval('runClock()', 1000);



    //center the countdown
    $('#countdown').css('margin-left', $('#countdown').outerWidth() / 2 * (-1));
}


function runClock() {

    //Get Time
    calculateTimeValues();

    //render values.
    $("#countdown .days").text(days);
    $("#countdown .hours").text(hours);
    $("#countdown .minutes").text(minutes);
    $("#countdown .seconds").text(seconds);


    tminus--;
}

//Function to calculate time values.
function calculateTimeValues() {


    days =  zeroFill(parseInt(tminus / 86400));
    hours = zeroFill(parseInt(tminus % 86400 / 3600));
    minutes = zeroFill(parseInt(tminus % 86400 % 3600 / 60));
    seconds = zeroFill(parseInt(tminus % 86400 % 3600 % 60));
}

//Function that formats the time values to be at least 2 digits in length.
function zeroFill(number) {
    
    if (number < 10) {
        number = "0" + number.toString();
    }

    return number;
}

/********************* 
* See Items Button
***********************/
$(function () {
    $("a[href=#items-listing]").click(function () {

        //scroll to the link target
        $.scrollTo($(this).attr('href'), {duration:1000});

        //disable default reaction
        return false;
    });
});

/********************* 
* Sidebar Shadowboxing
***********************/
$(function () {
    $("#supporting-content .asside.abbridged").each(function () {
        if ($(this).has('.teaser')) {

            //clone this content
            var shadowBox = $(this).clone();

            //modify clone
            shadowBox.addClass('shadowbox');
            shadowBox.attr('id', shadowBox.attr('id')+'-shadowbox');

            //remove extra paragraphs
            $(this).children().not('.teaser, h4').remove();

            //create 'read more' link
            var link = $('<a>Continue Reading</a>');

            //modify link
            link.attr('href', '#' + $(this).attr('id') + '-shadowbox')
                .css('display', 'inline-block')
                .addClass('read-more');

            //link will open a modal box
            link.colorbox({
                tansition:"fade",
                html:shadowBox, 
                width:650, 
                close: "x",
                scrolling: "false"
            });

            //add link to teaser
            $(this).find('.teaser').append(link);

        }
    });
});

//Fix colorbox opacity
$(document).bind('cbox_load', function () {
    $('#cboxOverlay').css('opacity', .8);
});

//fix colorbox scrolling
$(document).bind('cbox_complete', function () {
    $('#cboxLoadedContent').css('overflow', 'visible');

});
