//Add class jsOn to the html tag if the user has javascript enabled, then use it in front of a style to override
//For example: #basicstyle {display:block} followed by .jsOn #basicstyle {display: none;} will show by default and hide by default if js is on.
//document.getElementsByTagName('html')[0].className='jsOn';

//Side Nav 
function initPage()
{
	var n = document.getElementById("side-nav");
	if (n)
	{
		var lis = n.getElementsByTagName("li");
		for (var i = 0; i < lis.length; i++)
		{
			if (lis[i].getElementsByTagName("ul").length)
			{
				var a = lis[i].getElementsByTagName("a").item(0);
				if (a)
				{
//				/* Doesn't work right*/
//					a.onmouseover = function ()
//					{	
//						var p = this.parentNode;
//						if (p.className.indexOf("active") != 1) 
//						p.className += " active";
//						return false;
//					}
//					
//					a.onmouseout = function ()
//					{	
//						var p = this.parentNode;
//						if (p.className.indexOf("active") != 1) 
//						p.className = p.className.replace("active", "");
//						return false;
//					}
					
					a.onclick = function ()
					{	
						var p = this.parentNode;
						if (p.className.indexOf("active") != -1) 
						{
							p.className = p.className.replace("active", "");
						}
						else {
							p.className += " active";
							window.open(this.href,this.target='_self');
						}
						return true;
					}
				}
			}
		}
	}
}

if (window.addEventListener)
    window.addEventListener("load", initPage, false);
else if (window.attachEvent)
    window.attachEvent("onload", initPage);

//Nav test

// PRINT PAGE	
// unobtrusive JavaScript for "Print This!" links
// http://perishablepress.com/press/2009/02/01/unobtrusive-javascript-for-print-this-links/

function printClick() {
    if (!document.getElementById) return false;
    if (!document.getElementById("print_this")) return false;

    var link = document.getElementById("print_this");
    link.onclick = function() {
        window.print();
        return false;
    }
    link.onkeypress = link.onclick;
}

// onload function (not needed if script called at the end of the page)
// replace with "printClick();" if script called at the end of the page

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
addLoadEvent(printClick);
// End PRINT PAGE

// BEGIN BOOKMARK CODE
function addBookmark() {
    var url = location.href;
    var title = document.title;

    if (url.indexOf("file:") > -1) // IE cannot bookmark pages saved on hd: use main URL
        url = "http://www.interiordesign.edu";

    if (window.sidebar && sidebar.addPanel) { // add to FF bookmarks
        window.sidebar.addPanel(title, url, '');
    }
    else if (window.external) { // add IE favorite
        window.external.AddFavorite(url, title);
    }
    else { // unknown browser
        alert('Failed to recognize your browser, please bookmark the page manually.');
    }
}
// END BOOKMARK LINK

function toggleSelection(object, value) {
    var AllOption = (value == "-1");
    var cbL = document.getElementById('ctl00_Main_Container_Content_cbDegreeLevel');    //TODO
    toggleSelections(cbL, AllOption);
}

function toggleSelections(ListObject, AllIsSelected) {
    var options = ListObject.getElementsByTagName('input');
    var NoneSelected = true;

    if (AllIsSelected) {
        //All option is selected.  Uncheck every other option.
        for (i = 1; i < options.length; i++) {
            ListObject.getElementsByTagName('input')[i].checked = false;
        }
    } else {
        ListObject.getElementsByTagName('input')[0].checked = false;
    }

    for (i = 1; i < options.length; i++) {
        if (options[i].checked) {
            NoneSelected = false;
        }
    }

    if (NoneSelected) {
        //All options unchecked.  Check "All" option.
        ListObject.getElementsByTagName('input')[0].checked = true;
    } else {
        ListObject.getElementsByTagName('input')[0].checked = false;
    }

}

// Need to add a call to transmitErrorsToLP() statement somewhere!
function transmitErrorsToLP() {
    if (typeof (Page_Validators) != 'undefined') {
        var i;
        var j = 0;
        for (i = 0; i < Page_Validators.length; i++) {
            if (!Page_Validators[i].isvalid) {
                j += 1;
            }
        }
        if (j > 0) {
            lpAddVars('page', 'CTUErrorCounter', j);
        }
    }
}

/* Degree Page Tabs */
try {
    //google.setOnLoadCallback(function() {
        jQuery(document).ready(function() {
            if (document.getElementById('DegreeTabs') != null) {
                /* Product Page Product Tab */
                jQuery(function() {
                    var tabContainers1 = jQuery('.DescriptionTab > div.tabContainer div.s1');
                    jQuery('.DescriptionTab ul li a').click(function() {
                        tabContainers1.hide().filter(this.hash).fadeIn('normal').show();
                        jQuery('.DescriptionTab ul li').removeClass('selected');
                        jQuery(this).parent().addClass('selected');
                        return false;
                    }).filter(':first').click();
                    //}).filter(':first').click();
                });
            }
        });
    //});
}
catch(err) {}


try {
        jQuery(document).ready(function() {
			/*TopNavigation dropdowns
            jQuery('#nav li').hover(
		      function() {
		          // show
		          jQuery('ul', this).fadeIn(200);
		      },
		      function() {
		          // hide
		          jQuery('ul', this).fadeOut(200);
		      }
	        );*/
			
		//Mega Top Navigation
		function megaHoverOver(){
			jQuery(this).find(".sub").stop().fadeTo('fast', 1).show();
				
			//Calculate width of all ul's
			(function(jQuery) { 
				jQuery.fn.calcSubWidth = function() {
					rowWidth = 0;
					//Calculate row
					$(this).find("ul").each(function() {					
						rowWidth += jQuery(this).width(); 
					});	
				};
			})(jQuery); 
			
			if (jQuery(this).find(".row").length > 0 ) { //If row exists...
				var biggestRow = 0;	
				//Calculate each row
				jQuery(this).find(".row").each(function() {							   
					jQuery(this).calcSubWidth();
					//Find biggest row
					if(rowWidth > biggestRow) {
						biggestRow = rowWidth;
					}
				});
				//Set width
				jQuery(this).find(".sub").css({'width' :biggestRow});
				jQuery(this).find(".row:last").css({'margin':'0'});
				
			} else { //If row does not exist...
				
				jQuery(this).calcSubWidth();
				//Set Width
				jQuery(this).find(".sub").css({'width' : rowWidth});
				
			}
		}
		
		function megaHoverOut(){ 
		 jQuery(this).find(".sub").stop().fadeTo('fast', 0, function() {
			  jQuery(this).hide(); 
		  });
		}
	 
	 
		var config = {    
			 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 100, // number = milliseconds for onMouseOver polling interval    
			 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 200, // number = milliseconds delay before onMouseOut    
			 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
		};
	 
		jQuery("ul#nav li .sub").css({'opacity':'0'});
		jQuery("ul#nav li").hoverIntent(config);
			
			//simple popup
			jQuery('.popup').click(function(ev){
				window.open($(this).attr('href'),'popup','width=430,height=350');
				ev.preventDefault();
				return false;
			})
        });
}
catch (err) { }
