$(document).ready(function() {
	$(function(){
	
	    //code to implement ie6 transparent png fix
	    try {
		    jQuery.ifixpng('/assets/javascript/pixel.gif');
		    jQuery('img, #hd-logo, #hd-nav div, #main-wrapper div, #hd-search div').ifixpng();
        }
		catch(ex) { }
        
        //code to implement script to change text to image text
        try {
			//turns the title font into graphical letters if the class niagara-research does not exist on #main
			if ($(".sh-left").hasClass("true") == false && $(".sh-titles").hasClass("true") == false) {
				titleFont("sh-title");
				subTitleFont("sh-subtitle");
            }
		}
		catch(ex) { }
		
		
		//code to implement photoreel
		try {
		    $('#main-photoreel > ul').tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 5000, true);
		}
		catch(ex) { }
        
        //code to check if browser is ie6, if so does not run equal columns script
		try {
		    //if ie6 do not apply equal-columns
		    if (parseInt(jQuery.browser.version) == 6) {
			    //do nothing
			    
		    }
		    else {
			    //equalColumns('main-shadow-l', 'main', 'main-shadow-r', '', '');
		    }
		}
		catch(ex) { alert(ex); }
		
		// makes admin control panel an accordion
		try {
		    //hide lists on page load
		    cpMyAccount = false;
		    cpAddContent = false;
		    cpManageContent = false;
		    cpAdministration = false;
		    
		    var cpPanels = new Array(cpMyAccount, cpAddContent, cpManageContent, cpAdministration);
		    var cpPanelNames = new Array("cp-myaccount", "cp-addcontent", "cp-managecontent", "cp-administration");
		    
		    $(".panel ul").hide();
		    for (i = 0; i < cpPanels.length; i++) {
				cpPanels[i] = (getCookie(cpPanelNames[i]) == "false")? false: true;
				if (cpPanels[i] == true) {
					$("." + cpPanelNames[i] + " ul").show();
					$("." + cpPanelNames[i] + " .cp-title .togglechar").text("-");
				}
		    }
		    
		    $(".cp-myaccount .cp-title").click(function() {
				cpPanels[0] = cpActions(cpPanelNames[0], cpPanels[0]);
		    });
		    
		    $(".cp-addcontent .cp-title").click(function() {
				cpPanels[1] = cpActions(cpPanelNames[1], cpPanels[1]);
		    });
		    
		    $(".cp-managecontent .cp-title").click(function() {
				cpPanels[2] = cpActions(cpPanelNames[2], cpPanels[2]);
		    });
		    
		    $(".cp-administration .cp-title").click(function() {
				cpPanels[3] = cpActions(cpPanelNames[3], cpPanels[3]);
		    });
		}
		catch(ex) { }
		
		function cpActions(panelName, panelBool) {
			$("." + panelName + " ul").slideToggle("fast");
			
			// if openCP is false make it true, else make it false
			panelBool = (panelBool == false)? true: false;

			if (panelBool == true) $("." + panelName + " .cp-title .togglechar").text("-");
			else $("." + panelName + " .cp-title .togglechar").text("+");
			
			setCookie(panelName, panelBool, 7);
			return panelBool;
		}
		
		function setCookie(c_name, value, expiredays) {
			var exdate = new Date();
			exdate.setDate(exdate.getDate() + expiredays);
			document.cookie = c_name + "=" + escape(value)+
			((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
		}
		
		function getCookie(c_name) {
			if (document.cookie.length > 0) {
				c_start=document.cookie.indexOf(c_name + "=");
				if (c_start!=-1) {
					c_start=c_start + c_name.length+1;
					c_end = document.cookie.indexOf(";", c_start);
					if (c_end == -1) 
						c_end=document.cookie.length;
					return unescape(document.cookie.substring(c_start, c_end));
				}
			}
			return false;
		}
	});
});

//function to implement wymEditor
function wymeditor(target) {
	jQuery(target).wymeditor({
		 boxHtml: "<div class='wym_box'>"
			+ "<div class='wym_area_top'>" 
			+ WYMeditor.TOOLS
			+ "</div>"
			+ "<div class='wym_area_left'></div>"
			+ "<div class='wym_area_main'>"
			+ WYMeditor.HTML
			+ WYMeditor.IFRAME
			+ "</div>"
			+ "</div>"
	 });
}


function refreshShadow()
{
 //code to check if browser is ie6, if so does not run equal columns script
		try {
		    //if ie6 do not apply equal-columns
		    if (parseInt(jQuery.browser.version) == 6) {
			    //do nothing
		    }
		    else {
			    //equalColumns('main-shadow-l', 'main', 'main-shadow-r', '', '');
		    }
		}
		catch(ex) { }		
}


