﻿/**
*	Javascript Tools based on jquery
*
*	@date		22/02/2010
*	@author		Jasal Vadgama
*	@copyright	Live Nation UK
*   @require    jquery
*   @jquery     jquery-1.4.1.min.js
*
*/

/** Top Nav animation **/
function navSlider() {
    $("<span class='navPointer'>&#160;</span>").appendTo("nav");

    if ($("nav li:first .active").position() != null) { activeOffset = $("nav .active").position().left + ($("nav .active").width() / 2) - 25; }
    else if ($("nav .active").position() != null) { activeOffset = $("nav .active").position().left + ($("nav .active").width() / 2) - 2; }
    else { activeOffset = "-100"; }

    $(".navPointer").css({ left: activeOffset + "px" });

    $("nav ul:first li").mouseenter(function() {
        $(".navPointer").stop().animate({ left: $(this).position().left + ($(this).width() / 2) - 15 + "px" });
    }).mouseleave(function() {
        $(".navPointer").stop().animate({ left: activeOffset + "px" });
    });

    $("nav ul:first li:first").mouseenter(function() {
        $(".navPointer").stop().animate({ left: $(this).position().left + ($(this).width() / 2) - 27 + "px" });
    });
}

/** News Overlay **/
function newsOverlay(container, overlay) {
    $(container + " " + overlay).css({ opacity: "0" });

    list = $(container + " li");
    
    for (i = 0; i < list.length; i++) {
        $(list[i]).css({ zIndex: 10 - i });
    }

    $(container + " li").mouseenter(function() {
        $(this).find("img").css("border", "3px solid #ffc100");
        $(this).find(overlay).css("display", "block");
        $(this).find(overlay).stop().animate({ opacity: "1" });
    }).mouseleave(function() {
        $(this).find("img").css("border", "3px solid transparent");
        $(this).find(overlay).stop().animate({ opacity: "0" });
        $(this).find(overlay).css("display", "none");
    });
}


/** Hero **/
function scrollToPanel(panelToShow) {
    clearTimeout(t);

    if (panelToShow > items - 1) { currentPanel = 0; }
    else { currentPanel = panelToShow; }

    scrollPos = $(".heroContent").width() * currentPanel;
    $(".heroContent ul").animate({ marginLeft: "-" + scrollPos + "px" });

    $(".heroMenu .active").removeClass("active");
    $(".heroMenu a").eq(currentPanel).addClass("active");

    setTimer();
}

function setTimer() { t = setTimeout("scrollToPanel(" + (currentPanel + 1) + ");", 5000); }

function heroInit() {
    currentPanel = 0;

    items = $(".heroContent li").length;

    if (items > 1) {
        heroMenu = $("<ul></ul>").attr("class", "heroMenu");
        for (i = 0; i < items; i++) {
            pos = i + 1;
            heroMenu.append("<li><a href='#" + pos + "' title='' onclick='scrollToPanel(" + i + "); return false;'>" + pos + "</a></li>");
        }
        $("#hero").append(heroMenu);

        contentWidth = $(".heroContent").width() * items;
        $(".heroContent ul").css("width", contentWidth + "px");

        $(".heroMenu a:first").addClass("active");

        setTimer();
    }
}

$(document).ready(function() {
    /** Unobtrusive popup **/
    $(".popupLink").click(function() {
        window.open(this.href);
        return false;
    });
});