﻿function createCookie(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function OnDisciplineComboChanged() {
    //-- Get a reference to the combo box
    $combo = $('#discipline');

    //-- Get the value of the selected element
    var value = $combo.attr('options')[$combo.attr('selectedIndex')].value;

    //-- Set the cookie to the specified value and reload the window
    createCookie('Discipline', value, 30);
    window.location = window.location;    
}

function SetTabHover(button, isHovered) {
    //-- If the tab is not already active, then set it to hover
    var $button = $(button);
    if ($button.attr('class') != 'TabButtonActive') {
        $button.attr('class', (isHovered ? 'TabButtonHover' : 'TabButton'));
    }
}

function SetActiveTab(parentDivID, activeTabPanelID, tabButton) {
    //-- Get the reference to the parent div
    var $parentDiv = $('#' + parentDivID);

    //-- Hide all of the child panels
    $parentDiv.find('.TabPanel').hide();

    //-- Show only the proper panel
    $('#' + activeTabPanelID).show();

    //-- Deselect all of the tabs
    $parentDiv.find('.TabButtonActive').attr('class', 'TabButton');

    //-- Set the proper tab button
    $(tabButton).attr('class', 'TabButtonActive');
}

//-- Highslide
hs.graphicsDir = '/Images/Highslide/';
hs.wrapperClassName = 'colored-border';
hs.skin.contentWrapper = '<div class="highslide-body"></div>';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.numberPosition = 'caption';
hs.showCredits = false;
hs.allowSizeReduction = false;
// always use this with flash, else the movie will be stopped on close:
hs.preserveContent = false;

// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
    slideshowGroup: 1,
    interval: 5000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
        opacity: .6,
        position: 'bottom right',
        hideOnMouseOut: false
    }
});

hs.registerOverlay({
    html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
    position: 'top right',
    fade: 2, // fading the semi-transparent overlay looks bad in IE
    useOnHtml: true
});	
