/*
	Created by: Klaus Hoermann <klaus.hoermann@world-direct.at>
	Created for: world-direct eBusiness solutions GmbH
	Client: Tiroler Festspiele Erl
	Description: Startpage Animation JavaScript
	Copyright: (C) world-direct eBusiness solutions GmbH 2011
*/

// jQuery's noConflict mode is used instead of the $
var J = jQuery.noConflict();

/* when the document is ready */
jQuery(document).ready(function() {
	
	//-------------------------------------------------------
	// STARTPAGE ANIMATION
	
	// Append html div with animated gif
	J("#animation_wrap").prepend('<div id="startpage_animation"><img src="fileadmin/templates/img/animation_startpage.gif" border="0" /></div>');
	
	resizeAnimation();
	
	// On Resize event
	J(window).bind('resize', resizeAnimation);
	
	/*
	 * Function resizes the animation div and sets the settings for the sourrunding container
	 * @return void
	 */
	function resizeAnimation() {
		var browserWidth = getBrowserWidth();
		var animationWidth = 1506;
		var animationHeight = 281;
		
		// Set basic css styles
		J("#startpage_animation")
			.css("display", "block")
			.css("position", "absolute")
			.css("overflow", "hidden")
			.css("height", animationHeight)
			.css("top", 0);
		
		
		if (browserWidth < 1480) {
			J("#startpage_animation")
				.css("width", (browserWidth-20))				
				.css("left", 0);
			J("#startpage_animation img")
				.css("margin-left", ( (-1) * ((animationWidth - browserWidth)/2)));
		} else {
			J("#startpage_animation")
				.css("width", animationWidth)
				.css("left", ((browserWidth-animationWidth)/2));
		}
	}
	
	/*
	 * Function returns the width of the browser window (also for IE)
	 * @return browserWidth
	 */
	function getBrowserWidth() {
		var viewportwidth;
		var viewportheight;
		
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		if (typeof window.innerWidth != 'undefined') {
			viewportwidth = window.innerWidth,
			viewportheight = window.innerHeight
		}
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
			viewportwidth = document.documentElement.clientWidth,
			viewportheight = document.documentElement.clientHeight
		}
		// older versions of IE
		else {
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
		return viewportwidth;
	}
});
