﻿var browserIE = false;
var IEversion = false;
var strapIndex = getCookie('strapIndex');
var index = parseInt(Math.floor(Math.random() * 4));
var color = '';

$(function () {
    if (strapIndex != "" && strapIndex != null && strapIndex != false) {
        index = parseInt(strapIndex);
    }
    else {
        setCookie('strapIndex', index, null);
    }

    switch (index) {
        case 0: $('body').attr('id', 'ng_us_fuschia'); color = 'fuschia'; break;
        case 1: $('body').attr('id', 'ng_us_navy'); color = 'navy'; break;
        case 2: $('body').attr('id', 'ng_us_aqua'); color = 'aqua'; break;
        case 3: $('body').attr('id', 'ng_us_orange'); color = 'orange'; break;
        default: $('body').attr('id', ''); color = 'fuschia';
    }
    setActiveStyle();

    if ($.browser.msie) {
        browserIE = true;
        IEversion = $.browser.version;
        if (IEversion < 7) {
            $('.ng_us_dropdown').mouseover(
					function () {
					    $(this).addClass('over');
					}
				)
            $('.ng_us_dropdown .ng_us_submenu').mouseout(
					function () {
					    $(this).parent().removeClass('over');
					}
				)
        }
        if (IEversion <= 7) {
            var v_css = document.createElement('link');
            v_css.rel = 'stylesheet'
            v_css.type = 'text/css';
            v_css.href = '/hip/us/ng/assets/css/ie7.css';
            document.getElementsByTagName('head')[0].appendChild(v_css);

            var v_css2 = document.createElement('link');
            v_css2.rel = 'stylesheet'
            v_css2.type = 'text/css';
            v_css2.href = '/hip/us/ng/assets/css/ie6.css';
            document.getElementsByTagName('head')[0].appendChild(v_css2);
        }
    }


    if ($.browser.mozilla && $.browser.version.substring(0, 5) == '1.9.1') {
        $('body').addClass('ff35');
    }

    if ($('ul.ng_us_dropDownNav').length > 0) {
        $('ul.ng_us_dropDownNav').superfish({
            animation: { slide: 'toggle' },
            autoArrows: false,
            delay: 300
        });
    }

    $('.ui-button').mouseover(function () {
        $(this).addClass('ui-state-hover');
    });
    $('.ui-button').mouseout(function () {
        $(this).removeClass('ui-state-hover');
    });

    setActiveStyleSheet(color);
});                  /****End onload functions*******/



function getCookie(c_name) {
    if (document.cookie.length > 0) {
        var i, x, y, ARRcookies = document.cookie.split(";");
        for (i = 0; i < ARRcookies.length; i++) {
            x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
            y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == c_name) {
                return unescape(y);
            }
        }
    }
    return false;
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
	((expiredays == null) ? ";path=/" : ";expires=" + exdate.toUTCString()); +"path=/";
}


function setActiveStyleSheet(title) {
    var i, a, main;

    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("Style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) a.disabled = false;
        }
    }
}
function setActiveStyle() {
    var i, a, main;

    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("href").indexOf("navy") != -1) {
            a.setAttribute('title', 'navy');
            a.setAttribute('media', 'screen');
            a.setAttribute('rel', 'Alternate Stylesheet');
        }
        if (a.getAttribute("href").indexOf("fuschia") != -1) {
            a.setAttribute('title', 'fuschia');
            a.setAttribute('media', 'screen');
            a.setAttribute('rel', 'Alternate Stylesheet');
        }
        if (a.getAttribute("href").indexOf("aqua") != -1) {
            a.setAttribute('title', 'aqua');
            a.setAttribute('media', 'screen');
            a.setAttribute('rel', 'Alternate Stylesheet');
        }
        if (a.getAttribute("href").indexOf("orange") != -1) {
            a.setAttribute('title', 'orange');
            a.setAttribute('media', 'screen');
            a.setAttribute('rel', 'Alternate Stylesheet');
        }
    }
}


/*Begin VideoModal*/
function videoModal(url, width, height, title) {
	var dialogWidth = width * 1.05;
	var dialogHeight = height * 1.3;
	$('<div class="videoModal" title="' + title + '"><iframe frameborder="0" src="/assets/images/ppt.gif" ></iframe></div>').dialog({
	  width: dialogWidth,
	  height: dialogHeight,
	  open: function () {
	    $(this).find('iframe').eq(0).attr({
	      src: url,
	      width: width,
	      height: height
	    })
	  },
	  modal: true,
	  resizable: false,
	  draggable: false,
	  buttons: { 'Close': function () { $(this).dialog("destroy").remove() } },

//	 RWP:
//	 05-Dec-2011
//	 Added close function to ensure jQuery dialog
//	 and its contents are destroyed when close is
//	 called from the upper-right-hand-corner 'x'
//	 Note: this is a mod of McCann's original script
	  close: function() {
    	$(this).dialog("destroy").remove();
  		}
//	 end RWP changes
		
	});
}
/*End VideoModal*/
