// equalize height
function equalHeight(group){
	var tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
};

$(document).ready(function(){
	
	// nav
	
	$(".nav ul > li:eq(" + x + ") > ul").show();
	$(".nav ul > li:eq(" + x + ") > a").each(function(){ $(this).replaceWith("<span>" + $(this).text() + "</span>"); });
	$(".nav ul > li:eq(" + x + ") > ul > li:eq(" + y + ") > a").each(function(){ $(this).replaceWith("<span>" + $(this).text() + "</span>"); });
	
	$(".nav ul > li:not(:eq(" + x + "))").hover(
		function(){
			$(this).find("ul").show();
			$(".nav ul > li:eq(" + x + ")").find("ul").hide();
		}, 
		function(){
			$(this).find("ul").hide();
			$(".nav ul > li:eq(" + x + ")").find("ul").show();
		}
	);
	$(".nav ul > li:eq(" + x + ")").hover(
		function(){
			$(this).find("ul").show();
		}, 
		function(){
			$(this).find("ul").show();
		}
	);
	
	// ticker
	
	// add class to children
	$(".ticker-itemlist > *").addClass("ticker-item");
	// set children's width to equal parent's
	var tickerWidth = $(".ticker-itemlist").parent().width();	
	$(".ticker-item").css({width: tickerWidth});
	// equalize children height
	equalHeight($(".ticker-item"));
	// set parent's height to match child's
	var tickerHeight = $(".ticker-item").height();
	$(".ticker-item, .ticker-v, .ticker-h").css({height: tickerHeight});
	// vertical options
	$(".ticker-v").scrollable({
		vertical: true,
		interval: 10000
	});
	// horizontal options
	$(".ticker-h").scrollable({
		vertical: false,
		interval: 5000
	});
	// number nav links
	$(".ticker-all a").each(function(i){
		$(this).text(i + 1);
	});
	
	// cycle
	
	$(".cycle > *").addClass("cycle-item");
	// equalize children height
	equalHeight($(".cycle-item"));
	// set parent's height to match child's
	var cycleHeight = $(".cycle-item").height();
	$(".cycle").css({height: cycleHeight});
	// set parent's width to match child's
	var cycleWidth = $(".cycle-item").width();
	$(".cycle").css({width: cycleWidth});
	
	// list nav
	
	$(".listnav").listnav();
	
	// accordion
	
	$("div.tree").find("h5").addClass("icon-max").click(function(){
		$(this).toggleClass("icon-max");
		$(this).toggleClass("icon-min");
		$(this).next().toggle();
		return false;
	}).next().hide();
	
	$(".accordion").accordion({
		active: 0,
		autoHeight: false
	});
	
	// footer
	
	$("#font-max, #font-min, #print").css({"cursor":"pointer"});
	$("#font-max").click(function(){
		$("body").css({"font-size":"13px"});
	});	
	$("#font-min").click(function(){
		$("body").css({"font-size":"11px"});
	});
	
	// email masking
	
	$(function(){
		var spt = $('.generate');
		var at = / at /;
		var dot = / dot /g;
		var addr = $(spt).text().replace(at,'@').replace(dot,'.');
		$(spt).after('<a href="mailto:' + addr + '" title="Send Email">' + addr + '</a>');
		$(spt).remove();
	});
	
});