var timedRotation, linkEl;
function homepageBranding(linkEl) {
	if(linkEl == '' || linkEl == null) {
		if($('#home #content .nav .current').next().length == 1) {
			linkEl = $('#home #content .nav .current').next().children('a');
		} else {
			linkEl = $('#home #content .nav li:first-child > a');
		}
	} else {
		clearTimeout(timedRotation);
	}
	
	var $linkPar = linkEl.parent();
	if(!$linkPar.hasClass('current')) {
		var elNum = $linkPar.prevAll().length + 1;
		$('#home #content .nav .current').removeClass('current');
		$('#home #content .frame.current').fadeOut(400).removeClass('current');
		$('#home #content > .frame:nth-child('+elNum+')').fadeIn(200).addClass('current');
		$linkPar.addClass('current');
	}
	linkEl = '';
	timedRotation = setTimeout(homepageBranding,8500);
}

$(document).ready(function() {				   
	//Sifr
	$.sifr({
		path: '/images/template/',
		save: true
	});
	$('#sidebar .section h3').sifr(
		{ 
			font: 'Helveticaneue'
			//,filters: {
			//	DropShadow: {
			//		knockout: true
			//		,distance: 1
			//		,color: '#330000'
			//		,strength: 2
			//	}
			//}
		}
	);
	$('.subpage #content .sectionHeading').sifr(
		{ 
			font: 'Helveticaneue'
		}
	);
	//End sifr
						   
	//Add/Remove Input Values
	$('input[title]').each(function() {
		if($(this).val() == '') {
			$(this).val($(this).attr('title'));	
		}
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('');	
			}
		});
		$(this).blur(function() {
			if($(this).val() == '') {
				$(this).val($(this).attr('title'));	
			}
		});
	});
	//End Add/Remove Input Values

	//Homepage branding area
	/*$('#home #content .nav a').click(function() {
		var $linkPar = $(this).parent();
		if(!$linkPar.hasClass('current')) {
			var elNum = $linkPar.prevAll().length + 1;
			$('#home #content .nav .current').removeClass('current');
			$('#home #content .frame.current').fadeOut(400).removeClass('current');
			$('#home #content > .frame:nth-child('+elNum+')').fadeIn(200).addClass('current');
			$linkPar.addClass('current');
		}
		return false;
	});*/
	
	if($('body').attr('id') == 'home') {
		timedRotation = setTimeout(homepageBranding,8500);
		$('#home #content .nav a').click(function() {
			//clearTimeout(timedRotation);
			homepageBranding($(this));
			return false;
		});
	}
	//End homepage branding area
	
	//Expand and Collapse
	$('.toggle > li').each(function() {
		var $this = $(this);
		if($this.find('li,.content').length > 0) {
			$this.children('h2,h3,h4').addClass('expand');
			$this.children('ol,ul,.content').hide();
		}
	});
	$('.toggle .expand').click(function() {
		var $this = $(this);
		if($this.hasClass('collapse')) {
			$this.siblings('ol,ul,.content').slideUp(300);
			$this.removeClass('collapse');
		} else {
			$this.siblings('ol,ul,.content').slideDown(300);
			$this.addClass('collapse');
		}
	});
	//End Expand and Collapse

	//Print link
	$('.tools .print a').click(function() {
		window.print();
		return false;
	});
	//End print link

	//Text Resizer
	if($.cookie('TEXT_SIZE')) {
		$('body').addClass($.cookie('TEXT_SIZE'));	
	}
	$('.utilityNav .resizer a').click(function() {
		var textSize = $(this).parent().attr('class');
		$('body').removeClass('small medium large').addClass(textSize);
		$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
		return false;
	});
	//End text resizer
	
	//Modal Windows
	$('a[rel*="modal"]').colorbox({iframe: true, height: '80%', width:'80%'});
	
	$('dfn[rel*="def"]').each(function() {
		var $this = $(this), def = '/definitions/' + ($this.attr('rel').replace('def-','')) + '/';
		$this.addClass('definition');
		$this.colorbox({href:def, maxWidth: '600px', maxHeight: '80%'});
	});
	//End Modal Windows
	//Login
	$(".disclaimer").colorbox({width:"50%", inline:true, href:"#terms-of-use"});
	//End Login

});