﻿$(function () {

    $("li.page_item page-item a").removeClass("page_item page-item").addClass("current_link");
    $("#column-wrap").append("<img src='/images/ajax-loader.gif' id='ajax-loader' />");

    var $mainContent = $("#content_right"),
    URL = '',
    siteURL = "http://" + top.location.host.toString(),
    $internalLinks = $("a[href^='"+siteURL+"']"),
    hash = window.location.hash,


    $ajaxSpinner = $("#ajax-loader"),
    $el, $allLinks = $("a");

    $internalLinks.each(function()  {
        $(this).attr("href", "#" + this.pathname);
    }).click(function() {
        $ajaxSpinner.fadeIn();
        $mainContent.animate({ opacity: "0.1" });
        $el = $(this);
        $(".page_item page-item").removeClass(".page_item page-item");
        $allLinks.removeClass("current_link");
        URL = $el.attr("href").substring(1);
        URL = URL + " #content_right";
        $mainContent.load(URL, function() {
            $el.addClass("current_link").parrent().addClass("page_item page-item");
            $ajaxSpinner.fadeOut();
            $mainContent.animate({ opacity: "1" });
        });
    if ((hash) && (hash != "#/")) {
        $("a[href*='"+hash+"']").trigger("click");
    }


});

//slideshow begin

function slideSwitch() {
    var $active = $('#banner IMG.active');

    if ($active.length == 0) $active = $('#banner IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#banner IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 10000 );
});
