﻿$(document).ready(function() {
    document.body.className += "hasJs";
});


// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {
    //$(".titles").focus().autocomplete(titles);
    $('.iframe').colorbox({ width: "900px", height: "600px", iframe: true });
    $('.iframe02').colorbox({ width: "655px", height: "520px", iframe: true });
    $('.sendToFriend').colorbox({ width: "655px", height: "700px", iframe: true });


    // append show/hide links to the element directly preceding the element with a class of "toggle"
    $('#SiteMapMenu').prev().append('<a href="javascript:;" class="toggleLink"><span class="arrowDown">Find your way around</span></a>');

    // hide all of the elements with a class of 'toggle'
    $('#SiteMapMenu').show();

    // capture clicks on the toggle links
    $('a.toggleLink').click(function() {
        
        var isVisible = $('#SiteMapMenu').is(':visible');
           
        if(!isVisible)
        {
            $('a.toggleLink span').removeClass('arrowUp');
            $('a.toggleLink span').addClass('arrowDown');
        }
        else
        {
            $('a.toggleLink span').removeClass('arrowDown');
            $('a.toggleLink span').addClass('arrowUp');
        }

        $('#SiteMapMenu').toggle('slow');

        // return false so any link destination is not followed
        return false;

    });
});
    
// Faq show hide functionality.
$(document).ready(function() {
	$(".answer").hide();

	$(".question").click(function() {
		$(this).next(".answer").slideToggle("fast");
		$(this).next(".answer").toggleClass("answerOpen");
		$(this).toggleClass("questionOpen");

	});
});

// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {

    $('#MetaEditLink').click(function() {
        $('#MetaEditDiv').slideToggle("fast");
        $('.MetaPanel').toggleClass("height");
    });


    $().bind('cbox_open', function() {
        $('object, embed').css({ 'visibility': 'hidden' });
    }).bind('cbox_closed', function() {
        $('object, embed').css({ 'visibility': 'inherit', 'overflow': 'hidden' });
    });
});
    


var rotateSpeed = 8000; // Milliseconds to wait until switching tabs. http://www.cssnewbie.com/example/tabbed-box/advanced.html
var currentTab = 0;     // Set to a different number to start on a different tab.
var numTabs;            // These two variables are set on document ready.
var autoRotate = null;
var videoPlaybackInProgress = false;
var IsMultiPanelWrapHovered = false;

// tabs setup
$(document).ready(function () {
    //$(".tabbed-content").equalHeights();

    // count the tabs
    numTabs = $(".tabbed-box .tabs li a").length;

    // setup tab link so it won't be followed
    $(".tabbed-box .tabs li a").click(function () {
        openTabEventHandler($(this)); return false;
    });

    if (numTabs > 1) {
        // on mouse over - stop tab rotation
        // on mouse out - start rotation
        //$(".tabbed-box")
        $("#MultiPanelWrap, #FullWidthPanelWrap")
            .mouseenter(MultiPanelWrapMouseEnter)
            .mouseleave(MultiPanelWrapMouseLeave);

        // set the mouse to be outside of the tabs to start rotation
        //$(".tabbed-box").mouseout();
        $("#MultiPanelWrap, #FullWidthPanelWrap").mouseout();
    }

    // activate current tab
    openTab(currentTab, true);
});

function openTab(clickedTab) {
    openTab(clickedTab, false);
}

function openTab(clickedTab, isFirstLoad) {
    var thisTab = $(".tabbed-box .tabs a").index(clickedTab);
    $(".tabbed-box .tabs li a").removeClass("active");
    $(".tabbed-box .tabs li a:eq(" + thisTab + ")").addClass("active");
    //$(".tabbed-box .tabbed-content").hide(9999);
    //$(".tabbed-box .tabbed-content").fadeOut(700);
    if (isFirstLoad) {
        $(".tabbed-box .tabbed-content").hide();
        $(".tabbed-box .tabbed-content:eq(" + thisTab + ")").show();
    }
    else {
        $(".tabbed-box .tabbed-content").fadeOut(700);
        $(".tabbed-box .tabbed-content:eq(" + thisTab + ")").fadeIn(700);
    }
    currentTab = thisTab;
}


function rotateTabs() {
    var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
    openTab($(".tabbed-box .tabs li a:eq("+nextTab+")"));
}

// event is raised when video playback is finished - cannot rename this function?
function startRotation() {
    videoPlaybackInProgress = false;
    if (!IsMultiPanelWrapHovered) {
        startRotationWrapper(); // - mouse is out of the tab - START ROTATION
    }
}

// event is raised when video playback is started - cannot rename this function?
function stopRotation() {
    videoPlaybackInProgress = true;
    stopRotationWrapper();
}

function MultiPanelWrapMouseEnter() {
    IsMultiPanelWrapHovered = true;
    stopRotationWrapper();
}

function MultiPanelWrapMouseLeave() {
    IsMultiPanelWrapHovered = false;
    if (!videoPlaybackInProgress) {
        startRotationWrapper();
    }
}

function startRotationWrapper() {
    if (autoRotate == null) {
        autoRotate = setInterval(rotateTabs, rotateSpeed);
    }
}

function stopRotationWrapper() {
    clearInterval(autoRotate);
    autoRotate = null;
}

function openTabEventHandler(clickedTab) {
    videoPlaybackInProgress = false;    // since user clicked to the next tab video playback has been stopped
    openTab(clickedTab);
}

