var echoCollection;

// !!cdm 0301 Fixed Shadow Resize Problem
$.event.add(window, "load", resizeShadows);
$.event.add(window, "resize", resizeShadows);


$(document).ready(function(){
	KeyLargoInit();

	SearchBoxMod();

	//!!cdm 0314 Added to support "Empty Element Removal"
	RemoveEmptyBioImages();

	//Activates Mod of Get In Touch link if present
	GetInTouchReturnSource();	
	
	//Activates Pretty Photo For Modal Window Functions
	FireFlyModalInit();
	
	//Insert all Alice "keycode" links
	Alice();
	
});//^^ $(document).ready()



function Alice(){
	var RabbitHole = "<a rel='nofollow' href='/_layouts/viewlsts.aspx' accesskey='0'></a>";
	$('#Alice').append(RabbitHole);
	}


function SearchBoxMod(){
	var $cSearchBox = $('div#HeaderSegment div#SearchBox');
	var $cSRSB = $cSearchBox.find('div#SRSB div:first');
	var $cInputKeywords = $cSRSB.children('table:first').find('input:first');
	var $cInputFlag = $cSRSB.children('input:last');
	var $cGoSearchImg = $cSearchBox.find('td.ms-sbgo a img.srch-gosearchimg');

	
	$cSearchBox.addClass("zSearchBox");
	$cSRSB.addClass("zSRSB");
	$cInputKeywords.addClass("zInputKeywords");
	$cInputFlag.addClass("zInputFlag");
			
	$cGoSearchImg
		.livequery(function(){
			//$(selector).livequery( matchedFn );
			//$(selector).expire();

			$(this)
				.addClass("zHidden")
				.attr("src","http://www.lpsvcs.com/Style%20Library/Base/Images/SearchIcon.png")
				.attr("onmouseout","")
				.attr("onmouseover","")
				.attr("alt","")
				;
			
			
			//var msOnBlur = "if (this.value =='') {this.value='Search'; if (this.className.indexOf('s4-searchbox-QueryPrompt') == -1) this.className += this.className?' s4-searchbox-QueryPrompt':'s4-searchbox-QueryPrompt'; document.getElementById('ctl00_ctl37_ctl04').value = '0'} else {document.getElementById('ctl00_ctl37_ctl04').value='1';}";
			$cInputKeywords
				.attr("value","Search")
				.attr("title","Search")
				.attr("alt","Search")
				.attr("onBlur","")
				.blur(function(){
					if (this.value =='') {this.value='Search'; if (this.className.indexOf('s4-searchbox-QueryPrompt') == -1) this.className += this.className?' s4-searchbox-QueryPrompt':'s4-searchbox-QueryPrompt'; document.getElementById('ctl00_ctl37_ctl04').value = '0'} else {document.getElementById('ctl00_ctl37_ctl04').value='1';}
					})
				.focus(function(){
					$(this)
						.removeClass("s4-searchbox-QueryPrompt")
						;
					if(($(this).attr("value") == "Search") || ($(this).attr("value") == "search")){
						$cInputKeywords
							.attr("value","")
							;
						$cInputFlag
							.attr("value","1")
							;
						}
					})
				;

/*
if((this.value == '') || (this.value == ' ')){
	this.value='Search';
	if(this.className.indexOf('s4-searchbox-QueryPrompt') == -1){
		$(this)
			.addClass("s4-searchbox-QueryPrompt")
			;
		this.className += this.className?' s4-searchbox-QueryPrompt':'s4-searchbox-QueryPrompt';
		 document.getElementById('ctl00_ctl37_ctl04').value = '0'} else {document.getElementById('ctl00_ctl37_ctl04').value='1';}
*/


//$('div#SearchBox td.ms-sbgo a img.srch-gosearchimg[src]')

			$cSRSB
				.find('td.ms-sbgo a img.srch-gosearchimg[src*="SearchIcon.png"]:first')
				.addClass("zGoSearchImg")
				.livequery(function(){
						$(this)					
						.removeClass("zHidden")
						.expire()
						;
					})// ^^livequery
				;


			$cSearchBox
				.children('div#SearchEntry')
				.removeClass("zHidden")
				;
			})
		;
	}



	
function resizeShadows(){
	return;
	}//^^ resizeShadows()




function RemoveEmptyBioImages(){
	var $zCollection = $('div#ContentSegment div.imageLeft');
	if($zCollection.find('img').size() != 0){
		$zCollection
			.show()
			;
		}
	}



// !!cdm 0318 To Support Get In Touch links returning back to source page
function GetInTouchReturnSource(){
	//If the <div id="GetInTouch"> exists
	var $GetInTouch = $('div#GetInTouch');
	if($GetInTouch.size() > 0){
		//Get the url of the page
		var CurrentPageHref = window.location.href;
		
		//Get the GetInTouch <a>
		var $GetInTouchAnchor = 
			$GetInTouch
				.find('a:first')
				;
		
		//Get the href of the <a>
		var GetInTouchHref = 
			$GetInTouchAnchor
				.attr("href")
				;

		//Calculate the new href to include the Return Source parameter
		var HrefWithReturnSource = GetInTouchHref + "?ReturnSource=" + encodeURI(CurrentPageHref);
		
		//Store the newly calculated href
		$GetInTouchAnchor.attr("href", HrefWithReturnSource)
		}// ^^EndIf
	}// ^^GetInTouchReturnSource()



//Pretty Photo is the current FireFly Modal base Jquery plugin
function FireFlyModalInit(){ 
	$("a[rel^='prettyPhoto']")
		.prettyPhoto()
		;
  }
function printWindow(){
	window.print();
	}




//__________________________________________________________________________________________
//Debug Using Console (Cross Browser Friendly)

function zz(fnString){
	if(typeof(console) != "undefined"){
		console.log(fnString);
		}
	else{
		//alert(fnString);
		}
	}

