﻿/// <reference path="jquery.min-vsdoc.js" />

function initDefault() {
    $("#newsImage").hover(function(){
            $(this).attr("src", "images/news_active.jpg");
        }, function() {
            if (!$(this).hasClass("selected")) { $(this).attr("src", "images/news_inactive.jpg"); }
        }
    );
    $("#eventsImage").hover(function(){
            $(this).attr("src", "images/events_active.jpg");
        }, function() {
            if (!$(this).hasClass("selected")) { $(this).attr("src", "images/events_inactive.jpg"); }
        }
    );
    $("#vlogImage").hover(function(){
            $(this).attr("src", "images/video_blog_active.jpg");
        }, function() {
            if (!$(this).hasClass("selected")) { $(this).attr("src", "images/video_blog_inactive.jpg"); }
        }
    );

    $("#newsImage").bind("click", function(e) { selectNEVImage("newsImage"); showNEVDiv("newsContent"); });
    $("#eventsImage").bind("click", function(e) { selectNEVImage("eventsImage"); showNEVDiv("eventsContent"); });
    $("#vlogImage").bind("click", function(e) { selectNEVImage("vlogImage"); showNEVDiv("vlogContent"); });

    $("#membersTicker").liScroll();    
}
function deselectNEVImages() {
    $("#newsImage").attr("src", "images/news_inactive.jpg").removeClass("selected");
    $("#eventsImage").attr("src", "images/events_inactive.jpg").removeClass("selected");
    $("#vlogImage").attr("src", "images/video_blog_inactive.jpg").removeClass("selected");
}
function selectNEVImage(imgID) {
    deselectNEVImages();
    switch (imgID) {
        case "newsImage":
            $("#newsImage").attr("src", "images/news_active.jpg").addClass("selected");
            break;
        case "eventsImage":
            $("#eventsImage").attr("src", "images/events_active.jpg").addClass("selected");
            break;
        case "vlogImage":
            $("#vlogImage").attr("src", "images/video_blog_active.jpg").addClass("selected");
            break;
    }
}
function hideNEVDivs(){
    $("#newsContent").addClass("nodisplay");
    $("#eventsContent").addClass("nodisplay");
    $("#vlogContent").addClass("nodisplay");
}
function showNEVDiv(divID) {
    hideNEVDivs();
    $("#" + divID).removeClass("nodisplay");
}

jQuery.fn.liScroll = function(settings) {
    settings = jQuery.extend({
        travelocity: .1
    }, settings); //0.07
    return this.each(function() {
        var $strip = jQuery(this);
        $strip.addClass("newsticker")
        var stripWidth = 0;
        var $mask = $strip.wrap("<div class='mask'></div>");
        var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
        var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width 	
        $strip.find("li").each(function(i) {
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
        });
        $strip.width(stripWidth);
        var totalTravel = stripWidth + containerWidth;
        var defTiming = totalTravel / settings.travelocity; // thanks to Scott Waye		
        function scrollnews(spazio, tempo) {
            $strip.animate({ left: '-=' + spazio }, tempo, "linear", function() { $strip.css("left", containerWidth); scrollnews(totalTravel, defTiming); });
        }
        scrollnews(totalTravel, defTiming);
        $strip.hover(function() {
            jQuery(this).stop();
        },
				function() {
				    var offset = jQuery(this).offset();
				    var residualSpace = offset.left + stripWidth;
				    var residualTime = residualSpace / settings.travelocity;
				    scrollnews(residualSpace, residualTime);
				});
    });
};

// Drop-Down Menu ------------------------------------------------------------------------
// jQuery Code From: http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close()
{ if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout); }

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    } 
}

$(document).ready(function() {
    $('#navbar > li').bind('mouseover', jsddm_open)
    $('#navbar > li').bind('mouseout', jsddm_timer)
});

document.onclick = jsddm_close;
// End Drop-Down Menu ------------------------------------------------------------------------
