/**
 *  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 = {
	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;
		}
		
		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');
		}
		
		
		jQuery('#header-flash').css({background: 'url(' + this.altImage + ')  center top no-repeat'});
		
		
		for (var i = 0; i < this.swfparams.length; i++) {
			so.addVariable(this.swfparams[i]['name'], this.swfparams[i]['value']);
		}
		if(so.write('header-flash')){
			// ok, browser has flash
			if(this.wmodetransparent != 1 && this.flashFile != ''){
				jQuery('#header-menu-outer').hide();
			}
		}else{
			if(isNonFlashPage != 1){
				window.location = '/index.php?id=53';
			}
			
			/*
			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(this.flashFile == '' && this.altImage == ''){
			jQuery('#header-flash').height(this.minHeight);
			jQuery('#header-container').height(jQuery('#header-flash').height());
		}
		if(this.flashFile == '' && this.altImage != ''){
			jQuery('#header-flash').height(this.minHeight);
			jQuery('#header-container').height(jQuery('#header-flash').height());
			jQuery('#header-flash').html('<img src="/fileadmin/templates/img/blank.gif" usemap="#altImgMap" width="' + this.altImageWidth + '" height="' + this.altImageHeight + '">' + this.altHTML);
		}
		
			
		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);
			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);
			jQuery(flashContainer).height(Math.round(newheight) + 'px');
		}

		if (windowWidth < FlashResizer.minWidth) {
			jQuery(flashContainer).height(FlashResizer.minHeight + 'px');
			jQuery(flashContainer).width(FlashResizer.minWidth  + 'px');
		} else {
			jQuery(flashContainer).width(windowWidth + 'px');
		}
		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(document).ready(function() { FlashResizer.init(); }   );
jQuery(window).resize(function()  { FlashResizer.resize(); } );
