/**
 * @author Marcus
 */
 $(document).ready(function() {
	setupMenu();
	setupExpanders();
	setupMediaplayer();
	setupMouseOvers();
	//$(".box").pngFix();
 });
 
function setupMouseOvers() 
{
	$("img.hoverpuff").hover(
		function () {
			var image_name = this.src;
			this.src = image_name.replace("_out","_over");
		},
		function () {
			var image_name = this.src;

			this.src = image_name.replace("_over","_out");
		}
	);
	
	$("#blogpuff").hover(
		function () {
			this.src = "/images/puff_blog_over.jpg";
		},
		function () {
			this.src = "/images/puff_blog_out.jpg";
		}
	);
	
	$("#mediaplayer").hover(
		function () {
			this.src = "/images/puff_mediaplayer_over.gif";
		},
		function () {
			this.src = "/images/puff_mediaplayer_out.gif";
		}
	);	
}
function setupMenu() {

	$("#cssdropdown li.headlink a img").not('.active').hover(
		function () {
			var image_name = this.src;
			this.src = image_name.replace("images/main_nav/normal","images/main_nav/hover");
		},
		function () {
			var image_name = this.src;

			this.src = image_name.replace("images/main_nav/hover","images/main_nav/normal");
		}
	);
	
	/*
	 * Prepare submenus
	 */
	$('#cssdropdown li.headlink').hover(
		function() 
		{ 
			$('ul', this).css('display', 'block');
			
		},
		function() 
		{ 
			$('ul', this).css('display', 'none');
		}
	);
	
}

function setupExpanders()
{
	$("a.expander").toggle(function(e) {
		var el = $('img',this).get(0);
		el.src = el.src.replace("images/plus.gif", "images/minus.gif");
		$(this).parent().find("div.expander").slideDown('fast');
		e.preventDefault();
		return false;
		
	}, function(e) {
		var el = $('img',this).get(0);
		el.src = el.src.replace("images/minus.gif", "images/plus.gif");
		$(this).parent().find("div.expander").slideUp('fast');
		e.preventDefault();
		return false;
	});

}

function setupMediaplayer() 
{
	$("#show-mediaplayer").click(function(e) {
		var el = $('img',this).get(0);
	
		$(this).parent().addClass("mediaplayer_on");
		$("#hide-mediaplayer").show();
		$(this).hide();
		$("#mediaplayer").slideDown('fast');
		e.preventDefault();
		return false;		
	});
	
	$("#hide-mediaplayer").click(function(e) {
		var el = $('img',this).get(0);

		$(this).parent().removeClass("mediaplayer_on");
		$("#show-mediaplayer").show();
		$(this).hide();
		$("#mediaplayer").slideUp('fast');
		$('#mediaplayer-obj').get(0).sendEvent('STOP');
		e.preventDefault();
		return false;		
	});		
	
	// Listener for the power button
	$("#mediaplayer-holder a img").hover(
		function () {
			var image_name = this.src;
			this.src = image_name.replace("images/mediaplayer/normal","images/mediaplayer/hover");
		},
		function () {
			var image_name = this.src;
			this.src = image_name.replace("images/mediaplayer/hover","images/mediaplayer/normal");
		}
	);
	
	$("a.medialink").click(

		function(event){
   			event.preventDefault();
			window.open(this.href, 'mywindow','toolbar=0,location=0,menubar=0,status=0,resizable=0,scrollbars=0,directories=0,height=340,width=544');
		}
	);
}
