/**
 *  Project: WWF You!
 *  Description: Takes care of resizing the header area so the
 *               background and the flash movie is taking the full width
 */

var FlashResizer = {
	isFlash: false,
	minHeight: 480,
	minWidth: 979,
	swfMovieRatio: 0,
	flashFile: '',
	altImage: '',
	altLink: '',
	altImageWidth: 0,
	altImageHeight: 0,
	altHTML: '',
	swfparams: '',
	wmodetransparent: 0,
	usebackgroundcolor: '',
	

	init: function() {

		// abbrechen, falls kein flashcontainer vorhanden
		if ( ! jQuery('#header-flash').length) {
			return;
		}
		
		// resize first, for chrome
		this.resize();

		// check if fallback should replace flash
		if (jQuery('div.fallback').hasClass('replace') == true || this.flashFile == '') {
			jQuery('div.fallback').css('visibility', 'visible');
//4.1.12	jQuery('#header-flash').height(jQuery('div.fallback').height());
//4.1.12	jQuery('#header-container').height(jQuery('#header-flash').height());
		} 
		else 
		{
			var so;
	
			if (this.usebackgroundcolor != '') {
				so = new SWFObject(this.flashFile, 'headerflash', '100%', '100%', '9', this.usebackgroundcolor);
			} else {
				so = new SWFObject(this.flashFile, 'headerflash', '100%', '100%', '9', '#FFFFFF');
			}
	
			so.addParam('quality', 'high');
			so.addParam('scale', 'noscale');
			so.addParam('align', 'LT');
			
			if (this.wmodetransparent == 1 || this.flashFile == '') {
				so.addParam('wmode', 'transparent');
			}
			
			for (var i = 0; i < this.swfparams.length; i++) {
				so.addVariable(this.swfparams[i]['name'], this.swfparams[i]['value']);
			}
			
			if (so.write('header-flash')) {
			
				FlashResizer.isFlash = true;
				
			} else {
			
				if (typeof(isNonFlashPage) != 'undefined' && isNonFlashPage != 1) {
					// window.location = '/index.php?id=53';
				}
	
				jQuery('div.fallback').css('visibility', 'visible');
//4.1.12		jQuery('#header-flash').height(jQuery('div.fallback').height());
//4.1.12		jQuery('#header-container').height(jQuery('#header-flash').height());
				
				/*
	
				if (this.altLink != '') {
					jQuery('#header-flash').click(function () { 
					      window.location = FlashResizer.altLink;
					});
					jQuery('#header-flash').css({cursor: 'pointer'});
				}
	
				jQuery('#header-flash').html('<img src="/fileadmin/templates/img/blank.gif" usemap="#altImgMap" width="' + this.altImageWidth + '" height="' + this.altImageHeight + '">' + this.altHTML);
	
				*/
			}		
		}
		
		if (FlashResizer.isFlash) this.resize();
		this.adaptDivsections();
	},

	resize: function() {
		if ( ! this.flashFile) return;
		var flashContainer  = jQuery('#header-flash');
		var headerContainer = jQuery('#header-container');
		var windowWidth  = jQuery(window).width();
		var windowHeight = jQuery(window).height();
		
		if (windowHeight < FlashResizer.minHeight) {
			//jQuery(flashContainer).height(FlashResizer.minHeight + 'px');
			var newheight = windowWidth * this.swfMovieRatio - ((windowWidth - 900) * 0.08);
//4.1.12			if ( ! FlashResizer.isFlash) newheight = jQuery('div.fallback').height();
			jQuery(flashContainer).height(Math.round(newheight) + 'px');
		} else {
			//jQuery(flashContainer).height(Math.round(windowWidth * FlashResizer.minHeight/FlashResizer.minWidth) + 'px');
			//var correction = 0 + windowWidth * 0.04 * this.swfMovieRatio;
			//jQuery(flashContainer).height(Math.round(windowWidth * this.swfMovieRatio - correction) + 'px');
			var newheight = windowWidth * this.swfMovieRatio - ((windowWidth - 900) * 0.08);
//4.1.12			if ( ! FlashResizer.isFlash) newheight = jQuery('div.fallback').height();
			jQuery(flashContainer).height(Math.round(newheight) + 'px');
		}

		if (windowWidth < FlashResizer.minWidth) {
			//$(flashContainer).height(FlashResizer.minHeight + 'px');
			var newheight = FlashResizer.minWidth * this.swfMovieRatio - ((FlashResizer.minWidth - 900) * 0.08);
//4.1.12			if ( ! FlashResizer.isFlash) newheight = jQuery('div.fallback').height();
			jQuery(flashContainer).height(Math.round(newheight) + 'px');
			jQuery(flashContainer).width(FlashResizer.minWidth  + 'px');
		} else {
			jQuery(flashContainer).width(windowWidth + 'px');
		}
		
		if ( ! FlashResizer.isFlash) {
//4.1.12			jQuery(headerContainer).height(jQuery('div.fallback').height());
		} else {
			jQuery(headerContainer).height(jQuery(flashContainer).height());
		}
	},
	
	// Verlinkt Reiter "WWF.DE", "MITGLIEDER" etc. auf der linken Seite der weissen Contentboxen
	adaptDivsections: function() {
		var linkImg_wwf = '<a href="http://www.wwf.de"><img src="/fileadmin/templates/img/blank.gif" width="25" height="150" style="position: relative; border: 0px; z-index: 90; margin-bottom: -150px;"></a>';
		var linkImg_projekte = '<a href="/wwf-projekte/"><img src="/fileadmin/templates/img/blank.gif" width="25" height="150" style="position: relative; border: 0px; z-index: 90; margin-bottom: -150px;"></a>';
		var linkImg_mitglieder = '<a href="/wwf-mitglieder/"><img src="/fileadmin/templates/img/blank.gif" width="25" height="150" style="position: relative; border: 0px; z-index: 90; margin-bottom: -150px;"></a>';
		var linkImg_expedition = '<a href="/expedition/die-expedition-startseite/"><img src="/fileadmin/templates/img/blank.gif" width="25" height="150" style="position: relative; border: 0px; z-index: 90; margin-bottom: -150px;"></a>';
		//alert(jQuery('body').find(".contentbox-mitglieder").html());

		jQuery('.contentbox-wwf').prepend(linkImg_wwf);
		jQuery(".contentbox-projekte").prepend(linkImg_projekte);
		jQuery('.contentbox-mitglieder').prepend(linkImg_mitglieder);
		jQuery(".contentbox-expedition").prepend(linkImg_expedition);
	}
	

};

jQuery(window).resize(function()  { FlashResizer.resize(); } );
