﻿
greyImage = new Image();
greyImage.src = "/portals/0/Images/GreyBG.jpg";

redImage = new Image();
redImage.src = "/portals/0/Images/redBG.jpg";

blueImage = new Image();
blueImage.src = "/portals/0/Images/blueBG.jpg";

arrowOff = new Image();
arrowOff.src = "/portals/0/arrow-off.png";
arrowOn = new Image();
arrowOn.src = "/portals/0/arrow-on.png";



function GreyTheme()
{

changecss('.pagemaster','background-image','url('+ greyImage.src + ')')
Set_Cookie('Page_Master_BG_Image','url('+ greyImage.src + ')',1,'/');

changecss('.MenuTD','background-color','#979A9F')
Set_Cookie('Menu_TD_BG_Color','#979A9F',1,'/');

changecss('.main_dnnmenu_rootitem','color','#FFFFFF')
Set_Cookie('Menu_Root_Item_Color','#FFFFFF',1,'/');

changecss('.main_dnnmenu_itemhover','background-color','#a1a4a9')
Set_Cookie('Menu_Root_Item_Hover_BG_Color','#a1a4a9',1,'/');

changecss('.main_dnnmenu_itemhover','color','#FFFFFF')
Set_Cookie('Menu_Root_Item_Hover_Color','#FFFFFF',1,'/');

changecss('.MainMenu_RootMenuItemActive','color','#2B2541')
Set_Cookie('Menu_Root_Item_Active_Color','#2B2541',1,'/');

changecss('.footerStyle00','background-color','#979A9F')
Set_Cookie('Footer_Style_BG_Color','#979A9F',1,'/');


}

function RedTheme()
{
changecss('.pagemaster','background-image','url('+ redImage.src + ')')
Set_Cookie('Page_Master_BG_Image','url('+ redImage.src + ')',1,'/');


changecss('.MenuTD','background-color','#8E0438')
Set_Cookie('Menu_TD_BG_Color','#8E0438',1,'/');

changecss('.main_dnnmenu_rootitem','color','#FFFFFF')
Set_Cookie('Menu_Root_Item_Color','#FFFFFF',1,'/');

changecss('.main_dnnmenu_itemhover','background-color','#9c063f')
Set_Cookie('Menu_Root_Item_Hover_BG_Color','#9c063f',1,'/');

changecss('.MainMenu_RootMenuItemActive','color','#E0B616')
Set_Cookie('Menu_Root_Item_Active_Color','#E0B616',1,'/');

changecss('.footerStyle00','background-color','#8E0438')
Set_Cookie('Footer_Style_BG_Color','#8E0438',1,'/');


}

function BlueTheme()
{
changecss('.pagemaster','background-image','url('+ blueImage.src + ')')
Set_Cookie('Page_Master_BG_Image','url('+ blueImage.src + ')',1,'/');

changecss('.MenuTD','background-color','#2B2742')
Set_Cookie('Menu_TD_BG_Color','#2B2742',1,'/');

changecss('.main_dnnmenu_rootitem','color','#FFFFFF')
Set_Cookie('Menu_Root_Item_Color','#FFFFFF',1,'/');

changecss('.main_dnnmenu_itemhover','background-color','#303A52')
Set_Cookie('Menu_Root_Item_Hover_BG_Color','#303A52',1,'/');

changecss('.MainMenu_RootMenuItemActive','color','#E0B616')
Set_Cookie('Menu_Root_Item_Active_Color','#E0B616',1,'/');

changecss('.footerStyle00','background-color','#2B2742')
Set_Cookie('Footer_Style_BG_Color','#2B2742',1,'/');


}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

//window.onload= function () {
$(document).ready(function() {
    // Your code here...

    if (Get_Cookie('Page_Master_BG_Image') != null) {
        changecss('.pagemaster', 'background-image', Get_Cookie('Page_Master_BG_Image'));
        changecss('.MenuTD', 'background-color', Get_Cookie('Menu_TD_BG_Color'))
        changecss('.main_dnnmenu_rootitem', 'color', Get_Cookie('Menu_Root_Item_Color'))
        changecss('.main_dnnmenu_itemhover', 'background-color', Get_Cookie('Menu_Root_Item_Hover_BG_Color'))
        changecss('.MainMenu_RootMenuItemActive', 'color', Get_Cookie('Menu_Root_Item_Active_Color'))
        changecss('.footerStyle00', 'background-color', Get_Cookie('Footer_Style_BG_Color'))
    }

    var allMenuItems = document.getElementById("dnn_dnnNAV_ctldnnNAVctr88").parentNode.childNodes;

    count = 0
    for (i = 0; i < allMenuItems.length - 1; i++) {
        if (allMenuItems[i].nodeName == "SPAN") {

            var theTable = allMenuItems[i + 1];
            //var haschildren = theTable.hasChildNodes();

            if (allMenuItems[i + 1].nodeName != "SPAN") {

                var tableChildren = theTable.childNodes[0].childNodes;
                var j = 0;
                for (j = 0; j < tableChildren.length; j++) {
                    var theImageTD = tableChildren[j].childNodes[2];

                    tableChildren[j].par = theImageTD;
                    tableChildren[j].onmousemove = function() { menuCellMouseMove(this.par); }
                    tableChildren[j].onmouseout = function() { menuCellMouseOut(this.par); }


                }
            }
        }

    }

});
//}

function menuCellMouseMove(imageTD) {

    if (imageTD.childNodes[0] == null) {
        imageTD.parentNode.childNodes[1].style.color = "#ffffff";
        
        
    }
    else {
        imageTD.childNodes[0].src = arrowOff.src;
        imageTD.parentNode.childNodes[1].style.color = "#ffffff";

        
    }



}

function menuCellMouseOut(imageTD) {

    if (imageTD.childNodes[0] == null) {
        imageTD.parentNode.childNodes[1].style.color = "#2B3D7F";
       
    }
    else {
        imageTD.childNodes[0].src = arrowOn.src;
        imageTD.parentNode.childNodes[1].style.color = "#2B3D7F";
        
    }
}



function changecss(theClass,element,value) {
	//Last Updated on June 23, 2009
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;

	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){

    if (document.styleSheets[S]['rules']) {
	  cssRules = 'rules';
	 } else if (document.styleSheets[S]['cssRules']) {
	  cssRules = 'cssRules';
	 } else {
	  //no rules found... browser unknown
	 }

	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }
	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}
