jQuery(document).ready(function($) {	

   //track thickbox hits
   	$("a.thickbox").click(function () {
   		var thisHref=$(this).attr('href');
   		pageTracker._trackPageview(thisHref);}
   	); 

    $(".initText").focus(function () {
  		if($(this).is('.initText') ){
  			$(this).attr('value','').removeClass('initText');
  		}  
    });


	$("#sideNav .nav").accordion({
			autoHeight: false,//requires upper case, with  1.3.2. Safari tested. 
			active: '.selected',
			header: "a.header",
			navigation: true,
			event: 'click',
			fillSpace: false,
			clearStyle: true,
			alwaysOpen: false,
			icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
	});	

   
	// injection of arrows into left-flush 'more'  
	//IE6 requires the nbsp's
	//IE6 and 7 line-height ignored when replaced elements are  present
	//http://www.positioniseverything.net/explorer/lineheightbug.html
	 $('#contentSuppl a.more, .leftFlush  a.more, #pptools li a, #sideCol .calendar a').append('&nbsp;<span>&nbsp;<\/span>');
	



	$("a[href*=/forms/] ").click(function() {
		//alert('hi');
		var myURL =  this.href;
		var theseParams = parseGetVars(myURL);
		var thisDept = unescape(theseParams['department']);
		var thisSubject = unescape(theseParams['subject']);
		var thisBody = unescape(theseParams['body']);
		//alert(thisDept);

			
		// Pass a value to thickbox window by updating parent page's hidden form field	
		// set the value of the hidden form field id='dept' in the calling page
		// to the 'department' value captured from the link clicked on, that is now stored in the var 'thisDept'
		//document.getElementById("dept").value = thisDept;
		document.globalStorage.field1.value = thisDept;
		document.globalStorage.field2.value = thisSubject;
		document.globalStorage.field3.value = thisBody;
	});
});



/*String Mining*/
/*DEPRECATED. Has trouble with apostrophes. use unescape($.getURLParam("Event")) instead*/
function parseGetVars(thisString) {
	var getVars = new Array();
	var qString = thisString;
	if(qString!=''){
		var pairs = qString.split(/\&/);
		for (var i in pairs) {
			var nameVal = pairs[i].split(/\=/);
			getVars[nameVal[0]] = nameVal[1];
		} 
	}
	return getVars;
}

/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de) */
jQuery.extend({
/**
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});



//function fancyShow(theSelector){$(theSelector).show('slow').animate({ backgroundColor: "lightblue" }, 100).animate({ backgroundColor: "white" }, 500);}
function fancyShow(theSelector){$(theSelector).show('slow').animate({ backgroundColor: "lightblue" }, 100).animate({ backgroundColor: "black" }, 500);}
function fancyShow2(theSelector,theBg){$(theSelector).show('slow').animate({ backgroundColor: "lightblue" }, 100).animate({ backgroundColor: theBg }, 500);}
function fancyHide(theSelector){$(theSelector).animate({ backgroundColor: "lightblue" }, 100).animate({ backgroundColor: "black" }, 500).hide('slow');}

function updateCalculator(theCalculator,theClass,amount,notes){
	var theLabel = theCalculator +" ."+theClass+" b";
	var theSpan = theCalculator +" ."+theClass+" .amount";
	var theElement = theCalculator +" ."+theClass;

	$(theLabel).html(notes);
	if(amount!=""){
		thePrefix="$";
		if(theClass=="giftCertificate"){thePrefix="&mdash; $" }

		prettyNum = Number(amount).toFixed(2);
		$(theSpan).html(
			thePrefix + prettyNum
		)
	}else{
		$(theSpan).html("")
	}
	
	$(theSpan).attr("title",notes);
	
	if(notes=="total deposit"){
		var depNotes=	 "guests: $"+ guestAmount +", space: $" +spaceAmount ;
		$(theSpan).attr("title",depNotes);
	}


	var bgColor = "white";
	if($(theElement).parent().is('.black')){bgColor = "black"}//make the calculator table black to tell this script to flash to black
	fancyShow2(theElement,bgColor);//fundraisers reservation form must be white
}


/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de) */
jQuery.extend({
/**
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});


function LOG(msg) {
    try {
        if (console) {
            console.log(msg);
        }
        
    } catch(err) {}
}
