/*
**	Javascript coding by Nossebro Mediaproduktion 2008
**	This code is delivered as-is and is not subject to
**	any guarantee regarding problems with rare browsers,
**	not yet released browsers or outdated browsers.
**
**	Support tested with current popular browsers, which
**	includes IE6, IE7, Firefox 3, Safari 3, Opera 9.6
**	and derivatives of their respective layout engines.
**
**	This code requires jQuery (www.jquery.com) and was
**	developed using jQuery 1.2.6.
**
**	- Nossebro Mediaproduktion, november 2008
*/


//
//	Document is done loading, time to do our stuff
//
$(document).ready( function() {

	//
	//	Resize iframe immediately on page load
	//
	$( "#content-frame" ).height( $(window).height() - 132 );
	
	//
	//	Make sure height is recalculated whenever window is resized
	//
	$(window).resize( function() {
		$( "#content-frame" ).height( $(window).height() - 132 );
	});
	
	//
	//	If we have an active card, show it
	//
	$( "#" + cardActive ).css({
		top: "10px",
		height: "100px"
	});

	//
	//	Copy alt text into title attribute if it's
	//	empty, or the other way around.
	//
	$( "body #essen a.ess, #sidepanel a.sidepanel-links" ).each( function() {
		if( $(this).attr("title") == "" ) {
			if( $(this).attr("alt") != "" ) {
				$(this).attr("title", $(this).attr("alt"));
			}
		} else {
			if( $(this).attr("alt") == "" ) {
				$(this).attr("alt", $(this).attr("title"));
			}
		}
	});

	//
	//	The logotype needs a cursor that better
	//	indicates it can be used as a link
	//
	$( "#logo" ).mouseover( function() {
		$(this).css({
			cursor: "pointer"
		});
	});

	//
	//	Make clicking the logo redirect top
	//	location to the top domain name/host
	//
	$( "#logo" ).click( function() {
		location = "http://" + window.location.hostname;
	});

	//
	//	We don't want any ugly borders on the links
	//	NOTE: for proper accessibility, remove this!
	//
	$("body #essen a.ess, #sidepanel a.sidepanel-links").focus( function() {
		this.blur();
	});
	
	//
	//	Mousing over a card, slide it up
	//	NOTE: value 300 is duration in milliseconds
	//
	$("body #essen a.ess").mouseover( function() {
		if( $(this).attr( "id" ) != cardActive ) {
			$(this).animate({
				top: "10px",
				height: "100px"
			},300);
		}
	});
	
	//
	//	Mousing out from a card, slide it back down
	//	NOTE: value 600 is duration in milliseconds
	//
	$("body #essen a.ess").mouseout( function() {
		if( $(this).attr( "id" ) != cardActive ) {
			$(this).animate({
				top: "36px",
				height: "75px"
			},600);
		}
	});
	
	//
	//	Whenever a card/link is clicked, that card will stay in
	//	the upper position until a different card is clicked
	//	NOTE: value 600 is duration in milliseconds
	//
	$("body #essen a.ess").click( function() {
		if( $(this).attr( "id" ) != cardActive ) {
			$( "#" + cardActive ).animate({
				top: "36px",
				height: "75px"
			},600);
			cardActive = $(this).attr( "id" );
		}
	});
});