/* == FUNCTION: TOGGLE CONTACT PANEL == */

function toggleContactPanel()
{
	$("div#contact_container").css({
		backgroundPosition : "0px -190px"
	});
	
	$("div#navigation ul li#navigation_contact a").click(function () {
		$(this).toggleClass("active");
		
		if ($("div#contact_container").height() > 20)
		{
			$("div#contact_container").animate({
				height : "12px",
				backgroundPosition : "(0px -190px)"
			});
		}
		else
		{
			$("div#contact_container").animate({
				height : "202px",
				backgroundPosition : "(0px 0px)"
			});
		}
		
		return false;
	});
}



/* == FUNCTION: FEATURED CONTENT BANNER == */

function featuredContentBanner()
{
	if ($("div#featured_content dl.featured_content_banner").length > 0)
	{
		$("div#featured_content dl.featured_content_banner dt").css({
			"opacity" : 0.5,
			"top" : "48px"
		});
		
		$("div#featured_content dl.featured_content_banner dd").css({
			"opacity" : 0,
			"top" : "85px"
		});
		
		$("div#featured_content dl.featured_content_banner").hover(
			function() {
				$("dt", this).animate({
					"opacity": 0.9,
					"top" : "36px"
				}, "fast");
				
				$("dd", this).animate({
					"opacity": 0.9,
					"top" : "73px"
				}, "fast");
			}, function() {
				$("dt", this).animate({
					"opacity" : 0.5,
					"top" : "48px"
				}, "fast")
				
				$("dd", this).animate({
					"opacity" : 0,
					"top" : "85px"
				}, "fast")
			}
		);
	}
	
	$("div#featured_content dl.featured_content_banner").each(function() {
		if ($("a", this).length > 0)
		{
			$(this).attr("href", $("a", this).attr("href"));
			$(this).attr("target", $("a", this).attr("target"));
			
			$("a", this).removeAttr("href");
			$("a", this).removeAttr("target");
			
			$(this).click(function () {			
				if ($(this).attr("target") == "_blank")
				{
					window.open($(this).attr("href"));
				}
				else
				{
					window.location = $(this).attr("href");
				}
			});
		}
	});
}



/* == FUNCTION: SUBNAVIGATION == */

function subnavigation()
{
	if ($("div#subnavigation ul li a").length > 1)
	{
		$("div#subnavigation ul li:last").addClass("last");
	}
}



/* == FUNCTION: IMAGE ROTATOR == */

function imageRotator()
{
	var current_img = $("div#banner_container div#banner img.current");
	var next_img = current_img.next();
	
	if (next_img.length == 0)
	{
		next_img = $("div#banner_container div#banner img:first");
	}
	
	current_img.removeClass("current").addClass("previous");
	
	next_img.css({"opacity" : 0}).addClass("current").animate({
		"opacity" : 1
	}, 500, function() {
		current_img.removeClass("previous");
	});
}



/* == EVENTS == */

$(function() {
	Cufon.replace("div#navigation ul li a", {hover: true});
	Cufon.replace("div#subnavigation h2");
	Cufon.replace("div#subnavigation ul li a", {hover: true});
	Cufon.replace("div#content h2");
	Cufon.replace("div#content h3");
	Cufon.replace("div#featured_content dl.featured_content_banner dt");
	Cufon.now();
	
	toggleContactPanel();
	
	featuredContentBanner();
	
	subnavigation();
	
	if ($("div#banner_container div#banner img").length > 1);
	{
		setInterval("imageRotator()", 5000);
	}
});