﻿//populates the MSegment variable with the value of the .MemberSegment cookie
var MSegment = "";

var found = 1;

var dc = document.cookie;
var prefix = ".MemberSegment=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) found = 0;
} else {
    begin += 2;
}

if (found != 0) {
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    MSegment = unescape(dc.substring(begin + 15, end));
}

var sliding = false;
var latestSlide = "";
var inSubMenu = false;
var needHide = false;


var choiceThumbs;
var curThumb = 0;
var thumbClicked = false;
var delay = 4000;



function swapImage(image) {
    var temp = $(image).attr('src');

    $(image).attr('src', $(image).attr('swap'));
    $(image).attr('swap', temp);
}

function showChoice(choice) {
    var id = "#" + $(choice).attr("name");

    var position = $(choice).position();

    $('#bannerBorder').animate({
        left: position.left
    }, 500, function(e) {
        if ($(id + ":visible").length == 0) {
            $("#banners #top div:visible").hide();
            $(id).show();
        }
    });
}

function showNextThumb() {

    if (!thumbClicked) {

        curThumb = (curThumb + 1) % choiceThumbs.length;

        showChoice(choiceThumbs[curThumb]);
        setTimeout(function() { showNextThumb(); }, delay);
    }
}

function hideOvers() {
    $('div#menus div img[over]').each(function() {
        $(this).attr('src', $(this).attr('orig'));
    });
}

// Hides all open menus and sets variable so that after any animations complete, they will be hidden too
function HideStore() {
    $('div#menus div ul').hide();
    needHide = true;
    hideOvers();
}


$(function() {

    $('div#menus div img[over]').each(function() {
        $(this).attr('orig', $(this).attr('src'));
    });

    $('div#menus div').hover(function(e) {
        var curId = $(this).attr('id')

      
            hideOvers();
            $(this).children('a').children('img').attr('src', $(this).children('a').children('img').attr('over'));
      

        if ($(this).children('ul:visible').length == 0) {
            needHide = false;
            latestSlide = curId;

            $('div#menus div ul').hide();


            sliding = true;
            $(this).children('ul').slideDown('fast', function(e) {
                if (latestSlide != curId || needHide) {
                    $(this).hide();
                    $(this).children('a').children('img').attr('src', $(this).children('a').children('img').attr('orig'));
                    needHide = false;

                }
                sliding = false;

            }

        );
        }
    },
    function(e) {
        if ($('#holder').length = 0) {
            HideStore();
        } else {
            needHide = true;
        }
    }
    );



    $('#mainHeader').hover(function() {
        // Hide if the user backs up from a menu div
        HideStore();
    }, function() { });


    $('div#menus div ul').hover(function(e) { },
    function(e) {
        if (!sliding) {
            HideStore();
        }
    });


    $('div#menus li').hover(function(e) {
        $(this).children("ul").show();
    }, function(e) {
        if (!inSubMenu) {
            $(this).children("ul").hide();
        }
    });

    $('div#menus li ul').hover(function(e) {
        inSubMenu = true;
    }, function(e) {
        inSubMenu = false;
        $(this).hide();
    });


    $('td#tabarea ul li').click(function(e) {
        var rel = $(this).attr('rel');

        $('td#tabarea div').hide();
        $('td#tabarea div#' + rel).show();

        $('td#tabarea ul li').removeClass('selected');
        $(this).addClass('selected');
    });

    $('img[swap]').hover(function(e) {
        swapImage(this);
    }, function(e) { swapImage(this); });


    choiceThumbs = $("#banners #thumbs div.thumb");


    if (choiceThumbs.length > 0) {
        var position = $(choiceThumbs[0]).position();


        $('#bannerBorder').click(function(e) {
            window.location = $("#banners #top div:visible").children('a').attr('href');
        });



        $("#banners #thumbs div").bind("click", function(ex) {
            thumbClicked = true;
            showChoice(this);
            return false;
        });

        if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
            showChoice(choiceThumbs[0]);
        }
        setTimeout(showNextThumb, delay);
    }



});

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}

function MM_jumpMenuGo(selName, targ, restore) { //v3.0
    var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ, selObj, restore);
}