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>');
	



	initContactLinks();
});


function initContactLinks(){
	$('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
}

function flashFallBack(thisDiv,thisMP3,autoPlay){
	flashembed(thisDiv, "/sro/singlemp3player.swf", {          
		file: thisMP3,
	    autoStart: autoPlay,
	    showDownload: "false",
	    backcolor:"B8D4DE",
	    forecolor:"0000ff" //doesn't work. should. http://www.sean-o.com/jquery/jmp3/
	});
}

/* 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 setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function deleteCookie(name) {
    setCookie(name,"",-1);
}


function setCookieByElem(elem){
	//LOG('YO ' + jQuery(elem).attr('value'));
	var cName = jQuery(elem).attr('name');
	var cValue = jQuery(elem).attr('value');
	if(cValue!=null && cValue!="" &&cValue!="(___) ___-____"){
		setCookie(cName,cValue,365);
		//LOG('setCookie('+cName+','+cValue+',365);');
	}

}

function fillFromCookie(elem){
	//only works w/elements with an input element
	var thisName= jQuery(elem).attr('name'),
	    thisID= jQuery(elem).attr('id');
//	var thisSel= "#"+ thisID;
	var thisSel= "input[name="+ thisName + "]";
	var thisVal = getCookie(thisName);
//	LOG(thisName + " " + thisVal);
	if(thisVal!==null && thisVal!=""){
		jQuery(thisSel).attr('value',unescape(thisVal)).removeClass('initText');
//		LOG('Populated');
	}
}

function isWithin(obj,arr) {
  for(var i=0; i<arr.length; i++) {
    if (arr[i] == obj) return true;
  }
}




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



function displayWindow2(url, width, height) {
        var Win = window.open(url,"_blank",'width=' + width +
',height=' + height + ',resizable=0,scrollbars=1');
}

