$(document).ready(function(){
	
	var  searchterms = $('#searchterms')
		,mobileNav = $('.mobilenav')
		,mobileSiteMenu = $('#siteNav');

	searchterms
		.focus(function(){ 
			if ($(this).val() == 'Search Site') $(this).val('')
		})
		.blur(function(){			
			if ($(this).val() == '') $(this).val('Search Site');
		});
	
	
	mobileNav.delegate('a','click',function(){

		if ( $(this).parent().hasClass('search') ) {
			mobileSearch();
		} else if ( $(this).parent().hasClass('menu') ) {
			mobileSiteMenu.toggle();
		}

	});	

	
	showStatusBar();
	
	// ReadSpeaker - change icon for turning off
	if ( getCookie('RSENABLED') == 1 ) { // needs to be all caps for some reason
    	$('#ttsImage a').attr('title','Disable text to speeech')
    	$('#ttsImage a img').attr('src','/images/texttospeechorange.gif');
    	$('#pageImageFrame .readspeaker').hide();
    	$('#siteNameArea .readspeaker').hide();
	}

	if ( isMobile() ) {
		
		$(".move-to-top").prependTo($('#center')); 			//	Used for the: athletics team finder module student journals detail bio view
		
		mobileMenu(mobileSiteMenu);							//  actions for mobile site menu
		
	}
	
	$('#biGraphic img').hover(function() {
    	$('#biGraphic img').attr('src','/images/2-Bicentennial-Graphic-on.png');
    	},function() {
    	$('#biGraphic img').attr('src','/images/2-Bicentennial-Graphic.png');
    });

});


/*
	mobileMenu				display mobile version of the site menu	


	Attributes
	none
		
	History
	2011AUG08 	jbenson		created function
*/
mobileMenu = function(element){

	var  siteMenuHeads = element.find('.navHead ul');

	element
		.find('.navHead div').click(function(){
	
			var  currentElement = $(this).parent().children('ul') 
				,currentState = currentElement.css('display');
		
			if ( currentElement.length ) {
		
				siteMenuHeads.hide();					// close all
				
				if ( currentState == 'none' ) {		
					currentElement.show() 		// show active menu
				} else {
					currentElement.hide() 		// hide active menu
				}
				
			} else {
				return true;
			}

			return false;
			
		});

};


/*
	mobileSearch			display mobile version of the site search form	


	Attributes
	none
		
	History
	2011AUG08 	jbenson		created function
*/
mobileSearch = function(){

	var  siteSearch = $('#siteSearch')
		,mobileSiteSearch = $('.mobileSiteSearch');

	if ( !mobileSiteSearch.length ) {
		
		var content = siteSearch.html();		// copy original search form from header
		
		$('<div></div>')
			.addClass('mobileSiteSearch')
			.html(content)
			.find('input.terms')
				.focus(function(){
					if ( $(this).val() == 'Search Site' ) $(this).val('')
				}).blur(function(){
					if ( !$(this).val().length ) $(this).val('Search Site');
				}).end()
			.find('input.submit').attr('src','/mobile/icons/205-search-arrow.png').css('height',30).end()
			.insertAfter('#siteHeader');

	} else {
		
		mobileSiteSearch.remove('div');
		
	}

};
 

showStatusBar = function() {
	$.ajax({
		type: "POST",
		url: "/ajax/loginStatusBar.cfm",
		success: function(msg){
			$('body').prepend(msg);
		}
	});
}


showContactInformation = function() {
	$('#contactinfo').dialog();
};


getCookie = function(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
