/**
 * Eike Zuleeg Homepage
 *
 * @author Tom Klingenberg (http://www.lastflood.com/)
 */

/**
 * main
 */
$(document).ready
(
	function()
	{
		ezh_main();
	}
);

/**
 * ezh_main
 *
 */
function ezh_main()
{
	// init thumbnails on work page
	ezh_work_thumbnailimgs();

	// init player switch

	ezh_work_playerswitch();
}


/**
 * ezh_work_movie_handler
 *
 * handle an anchor (element) as a movie link
 */
function ezh_work_movie_handler(element)
{	

	moviehref = $(element).attr('href');

	movietype = moviehref.substr(moviehref.length - 4);

	switch(movietype)
	{
		case '.mov':
		case '.mpg':

			// files displayed in quicktime player inside the website by script.

			$('#playeron').show();
			$('#playeroff').hide();
			
			ezhPlayer(moviehref);

			return false;

		default:

			// unknown filetypes are handled as links

			return true;
	}
	
}


/**
 * ezh_work_playerswitch
 *
 * Adds the click on player link to switch to player and back.
 * Enables direct disply with the direct display class.
 */
function ezh_work_playerswitch()
{
	/* switch */
	$("#playeroff a.movieplayer").each
	(
		function(i)
		{
			$(this).click
			(
				function()
				{
					return ezh_work_movie_handler(this);
				}
			);
		}
	);

	/* direct play */
	if ($("#playeroff").hasClass('direct'))
	{
		element = $("#playeroff a.movieplayer").get(0);

		ezh_work_movie_handler(element);
	}

	return;
}

/**
 * ezh_work_thumbnailimgs
 *
 * Adds Hovering to small work images
 */
function ezh_work_thumbnailimgs()
{
	/**
	 * has-imgs -- thumbnail images handler
	 */
	$("#has-imgs").each
	(
		function(i)
		{
			// set default
			jQuery.data( $('#has-imgs').get(0), 'default', 0 );

			// set hover handler				
			$('.imgs a').hover
			(
				function() // hover over
				{
					$('#img').get(0).src = this.href;
				}
				,
				function(){}
			);

			//set click handler
			$('.imgs a').click
			(
				function()
				{
					return false;
				}
			);
		}
	);
}


/** 
 * ezhPlayer
 *
 * Embed Player Javascript Abstraction using the
 * QTObject (qtobject.js)
 *
 * @param  (string) srcmovie src of movie to show in player
 * @return (void)
 */
function ezhPlayer(srcmovie) {

		// create the qtobject and write it to the page, this includes plugin detection

		id   = "ezhplayer";
		mid  = id + "movie";

		/*
		 * simple player 
		 */

		// be sure to add 15px to the height to allow for the controls

		var myQTObject = new QTObject(srcmovie, mid, "480", "285");

		myQTObject.addParam("autostart", "true");		
		
		myQTObject.addParam("scale", "aspect");

		// href'ed to self (local dir!) (disabled)
		
		myQTObject.addParam("target", "myself");

		myQTObject.addParam("controller", "true");

		// myQTObject.addParam("id", mid);

		myQTObject.addParam("name", mid);

		myQTObject.addParam("enablejavascript", "true");

		// output
		
		myQTObject.write(id);


		// fix the internet explorer by re-setting the same url
		// some millisecs afterwards again.

		if (jQuery.browser.msie)
		{
			var loadMovie = function()
			{
				document.ezhplayermovie.SetURL(srcmovie);
			}

			setTimeout(loadMovie, 10);
		}
		
		return;	
}

