// JavaScript Document
function global_functions(){

	// Search field clear and reset
	$('#csc_site_search').focus(function(){
		$(this).get(0).value = '';
	}).blur(function(){
		if($(this).get(0).value == ''){
			$(this).get(0).value = 'Google Search';
		}
	});
	
	// instead of hiding things with a css class, this function does it.
	// the reason being Contribute will hide the content in editing mode via CSS,
	// but Contribute doesn't run JavaScript in editing mode.
	$(document).find('.hide').hide();
	
	// new toggle div function. Just add the 'toggle' class, and
	// add set the href value to #id_of_div_to_toggle" to the link just like you would link to an anchor.
	// example: <a href="#id_of_div" class="toggle">click to toggle</a>
	$(document).find('.toggle').click(function(){
		var el = this.getAttribute("href");
		$(el).toggle();
		$("div.column").fauxColumns();
		return false;
	});
	
	// Stripe table rows
	$('.tableStripe tr').mouseover(function(){
		$(this).addClass('tableRowHover');
	}).mouseout(function(){
		$(this).removeClass('tableRowHover');
	});
	$('.tableStripe tr:even').addClass('altRow');
	
	// pop-up window. Requires a link to have the class 'popup' assigned to it.
	// example: <li><a href="/directions/" class="popup" rel="800:600">Directions</a></li>
	$(document).find('a.popup').click(function(){
		var rel = this.getAttribute("rel");
		if(rel == ''){
			window.open(this.href,'newWindow');
		} else {
			//var re = /[^0-9]/;
			var rel_split = rel.split(':');
			var w = rel_split[0];
			var h = rel_split[1];
			var leftPos=(screen.width-w)/2;
			var topPos=(screen.height-h)/2;
			window.open(this.href,'newWindow','width='+w+',height='+h+',left='+leftPos+',top='+topPos+',scrollbars=no,resizable=no,statusbar=no,menubar=no,toolbar=no');
		}
		return false;
	});
	
	// pop-up window. Requires a area to have the class 'popup' assigned to it.
	// example: <li><a href="/directions/" class="popup" rel="800:600">Directions</a></li>
	$(document).find('area.popup').click(function(){
		var rel = this.getAttribute("rel");
		if(rel == ''){
			window.open(this.href,'newWindow');
		} else {
			//var re = /[^0-9]/;
			var rel_split = rel.split(':');
			var w = rel_split[0];
			var h = rel_split[1];
			var leftPos=(screen.width-w)/2;
			var topPos=(screen.height-h)/2;
			window.open(this.href,'newWindow','width='+w+',height='+h+',left='+leftPos+',top='+topPos+',scrollbars=no,resizable=no,statusbar=no,menubar=no,toolbar=no');
		}
		return false;
	});

	$(document).find('.button').click(function(){
		$(document).href=''
	});
};