/*
Site-wide JS
*/

$(function(){
	// Enable drop-down twoLevel menu.
	$("#menu").wwMenu({
		mode: "horizontal"
	});
	$("#SearchQ").hint();
});
$(document).ready(function(){
	$(".green_block .content li, ul#audience_menu li, .right_corner_box ul li, #get_help").hover(function(){
		$(this).css({opacity:0.6})
	}, function(){
		$(this).css({opacity:1})
	});
});
var addLoadEvent = function(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
};

addLoadEvent(function(){
	$('#text_larger_button').click(function(){
		var fontsize = $('body').css('font-size');
		$("body").css('font-size', (parseFloat(fontsize, 10)+2)+fontsize.slice(-2));
	});
	$('#text_smaller_button').click(function(){
		var fontsize = $('body').css('font-size');
		$("body").css('font-size', (parseFloat(fontsize, 10)-2)+fontsize.slice(-2));
	});
	
	$("#home_content").each(function(){
		// shortcut
		var content = $(this);
		// hide all boxes initially.
		$("div.content > div.box", content).hide();
		// bind events to links.
		$("dl.triggers > dt > a", content).each(function(){
			// alert($(this).parent().attr("class"));
			$(this).data("type", $(this).parent().attr("class")).bind('click', function(e){
				// prevent default click event.
				e.preventDefault();
				//
				$("dl.triggers > dt > a", content).removeClass('current');
				$("dl.triggers > dt."+$(this).data("type")+" > a", content).addClass('current');
				//
				$("div.content > div.box", content).hide().filter("."+$(this).data("type")).show();
			});
		});
		// show welcome box on load.
		$("dl.triggers > dt.welcome > a", content).trigger('click');
	});
});

$.extend(String.prototype, {
	slug: function(){
		return ""+this.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/-+$/g,'').replace(/^-+$/g,'');
	}
});
