﻿/* HERO PLAYER */

var scrollOn = true;

function scrollToPanel(panelToShow) {
    clearTimeout(t);

    if (panelToShow > items - 1) { currentPanel = 0; }
    else { currentPanel = panelToShow; }
    // find out width and animate left
    scrollPos = $("#heroHolder").width() * currentPanel;
    $("#heroHolder .desc").animate({ marginTop: "-300px" });
    pie = setTimeout('$("#heroHolder ul").animate({ marginLeft: "-" + scrollPos + "px" }, "slow");', 500);
    pie2 = setTimeout('$("#heroHolder .desc").animate({ marginTop: "0" });', 1100);
    
    if (scrollOn)
        setTimer();
}

function setTimer() {
    // initialize & animate the hero player after 5sec
    t = setTimeout("scrollToPanel(" + (currentPanel + 1) + ");", 5000);
}

function swapImage(panelToShow) {
    clearTimeout(t);

    // make sure panel is in range
    if (panelToShow > $("#heroHolder li").length - 1) { currentPanel = 0; }
    else if (panelToShow < 0) { currentPanel = $("#heroHolder li").length - 1 }
    else { currentPanel = panelToShow; }

    // scroll to panel
    scrollPos = $("#heroHolder li").width() * currentPanel;
    $("#heroHolder .desc").animate({ marginTop: "-300px" });
    pie = window.setTimeout('$("#heroHolder ul").animate({ marginLeft: "-" + scrollPos + "px" }, "slow");', 500);
    pie2 = window.setTimeout('$("#heroHolder .desc").animate({ marginTop: "0" });', 1100);

    if (scrollOn)
        setTimer();
}

function setButtons() {
    $("#heroRight").click(function() {
        swapImage(currentPanel - 1);
        return false;
    });

    $("#heroLeft").click(function() {
        swapImage(currentPanel + 1);
        return false;
    });
}

// initialize buttons 
function setTimer() {
   t = setTimeout("swapImage(" + (currentPanel + 1) + ");", 5000);
}

function heroInit() {
    currentPanel = 0;

    items = $("#heroHolder li").length;
    
    if (items > 1) {
        // appending dynamically previous and next buttons
        $buttons_prev = $(document.createElement('div'))
		        .attr('id', 'heroRight')
		        .attr('href', '#')
		        .appendTo('#heroPlayer');

        $buttons_next = $(document.createElement('div'))
		        .attr('id', 'heroLeft')
		        .attr('href', '#')
		        .appendTo('#heroPlayer');
		        
        // prev button
        $("#heroLeft").click(function() {
            swapImage(currentPanel - 1);
            return false;
        });
        // next button
        $("#heroRight").click(function() {
            swapImage(currentPanel + 1);
            return false;
        });
       // makes and end to the slideshow so it always returns to end/beginning img
        contentWidth = $("#heroHolder").width() * items;
        $("#heroHolder ul").css("width", contentWidth + "px");

        setTimer();

        // kill timer on hover - the mouse if all powerful!
        $("#heroPlayer").mouseenter(function() {
            scrollOn = false;
            clearTimeout(t);
        }).mouseleave(function() {
            scrollOn = true;
            setTimer();
        });
    }
}
// acordion news 
jQuery(document).ready(function() {
    $(".accordion h4").click(function() {
        $(this).next().toggle('slow');
        return false;
        }).next().hide();
 }); 
