/**
 * Retrieved from: http://www.quirksmode.org/js/detect.html
 */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/**
 * @classDescription Gaggenau Tab
 * @author mmazo
 * @requires prototype.js, effects.js
 * @param {Object} id - tab id
 * @param {Object} group_id - id of the tab elements group
 * @param {Object} active_src - active image source
 * @param {Object} inactive_src - inactive image source
 * @param {Object} state - 1 = active, 0 = inactive
 */
function GTab (id, group_id, active_src, inactive_src, state){
	this.id = id;
	this.group_id = group_id;
	this.active_src = active_src;
	this.inactive_src = inactive_src;
	this.state = state; 
}


/**
 * @classDescription Slideshow
 * @author mmazo
 * @requires prototype.js, effects.js
 * 
 * @param {Object} target_id - gallery target element
 * @param {Object} images_array - gallery array of images url
 * @param placeholder - placeholder image url
 * @param interval - time interval between image change (in seconds)
 */
function Slideshow (target_id, images_array, placeholder, interval){
		//slideshow run/stop flag
		var runShow = true;
		
		//generate container and image id�s
		var galCon = "gal[" + target_id + "]";
		var galImg = "pic[" + target_id + "]";
		
		//preload and prepare placeholder image
		var pholder = new Image();
		pholder.src = placeholder;
				
		//preload and prepare slideshow image objects	
		if (( Object.isArray(images_array) === false )&&(images_array)){
			images_array = [images_array];
		}
		var images = [];
		var tmpImg = {};
		for(i=0; i < images_array.length; i++){
			tmpImg = new Image();
	        tmpImg.src = images_array[i];
			images.push(tmpImg);
	    }
		
		//ranges and next image index
		var imagesLeng = images.length;
		var currentImageIndex = 0;
		
		//make first array image as placeholder if we have no placeholder
		if ((placeholder === "")||(imagesLeng === 1)){
			placeholder = images[currentImageIndex].src;
			currentImageIndex = currentImageIndex + 1;	
		}

		//prepare container and get its dimensions
		var trg = $(target_id);
		var width = trg.offsetWidth;
		var height = trg.offsetHeight;
        
		//render slideshow gui in the container
		var content = "<div id='" + 
		              galCon + 
		              "' style='position:relative;top:0px;left:0px;width:" + 
					  width + 
					  "px;height:" + 
					  height + 
					  "px;overflow:hidden;'>" + 
					 "<table width=100% height=100% border='0' " + 
					 " cellpadding='0' cellspacing='0'>" +
                     "<tr>" +
                     "<td align='center' valign='middle'>" +
						  "<img id='" + 
						  galImg + 
						  "' style='display:none;' " +
						  "src='" + 
						  placeholder + 
						  "'" +
						  " />" +
					  "</td></tr></table></div>";					  
		trg.innerHTML = content;
		
		//get image slideshow object
		var imgObj = $(galImg);
		
		//make image slideshow object visible with placeholder 
		//if placeholder is a valid image url
		if (placeholder != ""){
			//Effect.Appear(imgObj);
			imgObj.show();
		}
		
		//run the slideshow by default if we have more than one element
		if (imagesLeng > 1){
	        var refr = new PeriodicalExecuter(function() {
				if ((runShow === true)&&($('overlay').visible() === false)){
					runShow = false;
					imgObj.hide();
					imgObj.src = images[currentImageIndex].src;
					currentImageIndex = currentImageIndex + 1;
					if (currentImageIndex >= imagesLeng){
						currentImageIndex = 0;
					}
					Effect.Appear(imgObj);
					runShow = true;
					//alert(imgObj.src);
				}
	        }, interval);
		}else{
			//otherwise always show only one image
			//imgObj.hide();
			//imgObj.src = images[0].src;
			//Effect.Appear(imgObj);
			//alert(imgObj.src);
		}
		
		//add a onclick event to stop/run image slideshow
	 /* Event.observe($(galImg), 'click', function(event){
			if (runShow === true){
				runShow = false;
			}else{
				runShow = true;
			}
		}); */
}


/**
 * @classDescription responsible for providing web2.0 functionality
 * to gaggenau portal. Current features include: overlay
 * @author mmazo
 * @requires prototype.js, effects.js
 */
function GaggenauEffects(){


	/***************************************************************************
	 * Public attributes
	 **************************************************************************/
	
	/**
	 * animation speed
	 */
	GaggenauEffects.animationSpeed = 0.5;
	
		
	/***************************************************************************
	 * Private attributes
	 **************************************************************************/
	
	/**
	 * tabs array
	 */
	var tabsArray = new Array();

	/***************************************************************************
	 * Public functions
	 **************************************************************************/
	/**
	 * closes popup
	 * @param {Object} popupId
	 */
	GaggenauEffects.closeFlashPopup = function(popupId){
		window.scrollTo(0,0);
		Effect.Fade("overlay",{duration:GaggenauEffects.animationSpeed});
		$("overlay").innerHTML="";
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			var pg = $("page");
			if (pg === null){
				pg = document.getElementsByClassName("page")[0];
			}
			var pg_width = pg.offsetWidth;
			var pg_height = pg.offsetHeight;		
			var pg_top = Element.viewportOffset(pg)[1];
			var pg_left = Element.viewportOffset(pg)[0];
		    var ov = $("overlay");
			ov.style.top = pg_top + "px";
			ov.style.left = pg_left + "px";
			ov.style.width = pg_width + "px";
			ov.style.height = pg_height + "px";
		}else{
			var ov = $("overlay");
			ov.className = "disableScreen";
			ov.style.width = "100%";
			ov.style.height = "100%";
		}
	};
	
	GaggenauEffects.closeFlashPopupNoTransparency = function(popupId){
		window.scrollTo(0,0);
		Effect.Fade("overlay",{duration:GaggenauEffects.animationSpeed});
		$("overlay").innerHTML="";
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			var pg = $("page");
			if (pg === null){
				pg = document.getElementsByClassName("page")[0];
			}
			var pg_width = pg.offsetWidth;
			var pg_height = pg.offsetHeight;		
			var pg_top = Element.viewportOffset(pg)[1];
			var pg_left = Element.viewportOffset(pg)[0];
		    var ov = $("overlay");
			ov.style.top = pg_top + "px";
			ov.style.left = pg_left + "px";
			ov.style.width = pg_width + "px";
			ov.style.height = pg_height + "px";
		}else{
			var ov = $("overlay");
			ov.style.width = "100%";
			ov.style.height = "100%";
		}
	};
	
	/**
	 * registrates tab to page tabs array
	 * 
	 * @param {Object} id - tab id
	 * @param {Object} group_id - id of the tab elements group
	 * @param {Object} active_src - active image source
	 * @param {Object} inactive_src - inactive image source
	 * @param {Object} state - 1 = active, 0 = inactive
	 */
	this.registrateTab = function(id, group_id, active_src, inactive_src, status){
		var tab = new GTab(id, group_id, active_src, inactive_src, status);
		tabsArray.push(tab);
	};
	
	/**
	 * toggles tab with given id
	 * @param {Object} tab_id
	 */
	this.toggleTab = function(tab_id){
		var i = 0;
		var found = false;
		var tab_index = 0;
		var group_id = '';
		while ((found === false)&&(i < tabsArray.length)){
			if (tabsArray[i].id === tab_id){
				group_id = tabsArray[i].group_id;
				tab_index = i;
				found = true;
			}
			i = i + 1;
		}
		for (i = 0; i < tabsArray.length; i++){
			if ((i === tab_index)&&(group_id === tabsArray[i].group_id)){
			  try{
				$(tabsArray[i].id).className = tabsArray[i].active_src;
				$(tabsArray[i].state).show();
			  }catch(error){}
			}else if (group_id === tabsArray[i].group_id){
			  try{
				$(tabsArray[i].id).className = tabsArray[i].inactive_src;
				$(tabsArray[i].state).hide();
			  }catch(error){}
				
			}
		}
	};
		
	/**
	 * creates overlay DOM element if it is not created yet
	 */
	this.createOverlay = function(){
		if ($("overlay") === null){
			var ov = document.createElement("div");
			ov.id = "overlay";
			
			if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
				ov.className = "disableScreenIE6";
			}else{
				ov.className = "disableScreen";	
			}
			document.body.appendChild(ov);
			Element.hide("overlay");

		}
	};
	
	this.createOverlayNoTransparency = function(){
		if ($("overlay") === null){
			var ov = document.createElement("div");
			ov.id = "overlay";
			document.body.appendChild(ov);
			Element.hide("overlay");

		}
	};
		
	/**
	 * sets overlay dimensions according current page dimensions
	 */
	this.setOverlayDimensions = function(){
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			var pg = $("page");
			if (pg === null){
				pg = document.getElementsByClassName("page")[0];
			}
			var pg_width = pg.offsetWidth;
			var pg_height = pg.offsetHeight;		
			var pg_top = Element.viewportOffset(pg)[1];
			var pg_left = Element.viewportOffset(pg)[0];
		    var ov = $("overlay");
			ov.style.top = pg_top + "px";
			ov.style.left = pg_left + "px";
			ov.style.width = pg_width + "px";
			ov.style.height = pg_height + "px";
		}
	};
	

////////////////

	/**
	 * renders overlay iframe popup
	 * @param {Object} title - popup title
	 * @param {Object} content_url - flash movie url
	 * @param {Object} width - flash movie width
	 * @param {Object} height - flash movie height
	 */
	this.renderIframePopup = function(popup_id, title, content_url, width, height){
		        window.scrollTo(0,0);		
				Element.show("overlay");
				var ovip = document.createElement("div");
				ovip.id = popup_id;
				if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
					ovip.className = "overlayFPopupIE6";
				}else{
					ovip.className = "overlayFPopup";	
				}
				if ($(popup_id) === null){
					document.body.appendChild(ovip);
			    }
				ovip = $(popup_id);
				ovip.hide();
				ovip.innerHTML = "<div class='overlayLayerMenue'  style='height:30px;width:" + width + "px;overlfow:hidden;'>" +
								     "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
									 title + 
									 "</label>" +
									 "<button class='overlayPopupButton' " + " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
									 "</button>" +
								 "</div>" +
								 "<div style='width:" + width + "px;height:" + height + "px;overflow:hidden;'>" +
								 
					             	"<iframe frameborder=0 scrolling='none' width=" + 
					             	width + " height=" + height + 
					             	" src='" + content_url + "' ></iframe>" +
					             	 
								 "</div>";
						
				//calculate popup position
				var win_w = document.viewport.getWidth() / 2;
				var pop_w = width / 2;
						
				if (pop_w <= win_w){
					ovip.style.left = "50%";		
					ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
				}else{
					ovip.style.left = "0px";		
					ovip.style.marginLeft =  "0px";
				}
				ovip.style.width = width + "px";
				ovip.style.maxWidth = width + "px";
		
				Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
	};
	
	/**
	 * ATTENTION!!! The solution works only in IE.
	 */
	this.renderVideoPopup = function(popup_id, title, content_url, width, height){
        window.scrollTo(0,0);		
		Element.show("overlay");
		var ovip = document.createElement("div");
		ovip.id = popup_id;
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			ovip.className = "overlayFPopupIE6";
		}else{
			ovip.className = "overlayFPopup";	
		}
		if ($(popup_id) === null){
			document.body.appendChild(ovip);
	    }
		ovip = $(popup_id);
		ovip.hide();
		ovip.innerHTML = "<div class='overlayLayerMenue'  style='height:30px;width:" + width + "px;overlfow:hidden;'>" +
						     "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
							 title + 
							 "</label>" +
							 "<button class='overlayPopupButton' " + " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
							 "</button>" +
						 "</div>" +
						 "<div style='width:" + width + "px;height:" + height + "px;overflow:hidden;'>" +
						 "<object id='MediaPlayer' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'" +	"" +
						 	" codebase='http://activex.microsoft.com/nsmp2inf.cab#Version=5,1,52,701'" +
						 	" standby='Loading Microsoft Windows Media Player components...'" +
						 	" type='application/x-oleobject'" +
						 	" width=" + width +
						 	" height=" + height + ">" +
						 	" <param name='FileName' value=" + content_url + ">" +
						 	" <param name='AnimationatStart' value='1'>" +
						 	" <param name='TransparentatStart' value='1'>" +
						 	" <param name='AutoStart' value='1'>" +
						 	" <param name='ShowControls' value='1'>" +
						 	" <param name='ShowAudioControls' value='1'>" +
						 	" <param name='EnableFullScreenControls' value='1'>" +
						 	" <param name='ShowDisplay' value='0'>" +
						 	" <param name='ShowGotoBar' value='0'>" +
						 	" <param name='ShowPositionControls' value='1'>" +
						 	" <param name='ShowStatusBar' value='0'>" +
						 	" <param name='ShowTracker' value='0'>" +
						 	" <param name='AllowChangeDisplaySize' value='1'>" +
						 	" <param name='AutoSize' value='0'>" +
						 	" <param name='DisplaySize' value='0'>" +
						 	" <embed type='application/x-mplayer2'" +
						 	" pluginspage='http://www.microsoft.com/windows/windowsmedia/en/download/plugin.asp'" +
						 	" src='http://www.ctv.ca/servlet/1070247679.wmv'" +
						 	" name='MediaPlayer'" +
						 	" showcontrols='1'" +
						 	" showstatusbar='0'" +
						 	" showgotobar='0'" +
						 	" width=" + width +
							" height=" + height + ">" +
							" </embed>" +
							" </object>"				 
						 "</div>";
				
		//calculate popup position
		var win_w = document.viewport.getWidth() / 2;
		var pop_w = width / 2;
				
		if (pop_w <= win_w){
			ovip.style.left = "50%";		
			ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
		}else{
			ovip.style.left = "0px";		
			ovip.style.marginLeft =  "0px";
		}
		ovip.style.width = width + "px";
		ovip.style.maxWidth = width + "px";

		Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
};

	/**
	 * renders overlay flash popup
	 * @param {Object} title - popup title
	 * @param {Object} flash_url - flash movie url
	 * @param {Object} width - flash movie width
	 * @param {Object} height - flash movie height
	 */
	this.renderFlashPopup = function(popup_id, title, flash_url, width, height){
		        window.scrollTo(0,0);
				var ovip = document.createElement("div");
				ovip.id = popup_id;
				if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
					ovip.className = "overlayFPopupIE6";
				}else{
					ovip.className = "overlayFPopup";	
				}
				if ($(popup_id) === null){
					document.body.appendChild(ovip);
			    }  
				if ($('overlay').innerHTML === null){
					this.createOverlay();
	                this.setOverlayDimensions();
				}
				$('overlay').innerHTML = "<div style='left: 50%; margin-left: -320px; width: 640px; max-width: 640px; display: none;' class='" + ovip.className + "' id='" + ovip.id + "'></div>";
				ovip = $(popup_id);
				ovip.innerHTML = "<div class='overlayLayerMenue'  style='background-color:#29292C;height:30px;width:" + width + "px;overlfow:hidden;'>" +
								     "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
									 title + 
									 "</label>" +
									 "<button id='" + popup_id + "_close' class='overlayPopupButton' " + " onclick='GaggenauEffects.closeFlashPopup();'>" + 
									 "</button>" +
								 "</div>" +
								 "<div style='width:" + width + "px;height:" + height + "px;overflow:hidden;'>" +
					             	"<div id='" + popup_id + "_flashcontent'>" + 
									"</div>" + 
								 "</div>";
				//calculate popup position
				width = width*1;
				height = height*1;
				var win_w = document.viewport.getWidth() / 2;
				var pop_w = width / 2;		
				if (pop_w <= win_w){
					ovip.style.left = "50%";		
					ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
				}else{
					ovip.style.left = "0px";		
					ovip.style.marginLeft =  "0px";
				}
				ovip.style.width = width + "px";
				ovip.style.maxWidth = width + "px";
				ovip.show();
								
				/* real gaggenau flash player path */
        var flashvars = {};
          flashvars.file = flash_url;
          flashvars.type = 'flv';
          flashvars.linkfromdisplay = 'true';
          flashvars.lightcolor = '0x557722';
          flashvars.searchbar = 'false';
          flashvars.shuffle = 'true';
          flashvars.overstretch = 'true';
          flashvars.width = width;
          flashvars.height = height;
        var params = {};
        var attributes = {};
          attributes.bgcolor = '#282828'
          attributes.allowfullscreen = 'true'
        swfobject.embedSWF('flash/mediaplayer.swf', popup_id + '_flashcontent', width, height, "9", false, flashvars, params, attributes);
            
/*				so.addParam('allowfullscreen', 'true');
				so.addParam('bgcolor', '#000000');
				so.addVariable('file', flash_url);
				so.addVariable('type', 'flv');
				so.addVariable('linkfromdisplay', 'true');
				so.addVariable('lightcolor', '0x557722');
				so.addVariable('searchbar', 'false');
				so.addVariable('shuffle', 'true');
				so.addVariable('overstretch', 'true');
				so.addVariable('width', width);
				so.addVariable('height', height);
				so.write(popup_id + '_flashcontent');*/
				$("overlay").show();
				
				//calculate overlay dimensions if popup is bigger than overlay//
				var bigger = false;
				var ov = $('overlay');
			    var ov_width = ov.offsetWidth;
			    var ov_height = ov.offsetHeight;
				if (ov_width < width){
					ov.style.width = width + "px";
					bigger = true;
				}
				if (ov_height < height){
					ov.style.height = height + "px";
					bigger = true;
				}
				if (bigger === true){
					if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){	
					}else{
						ov.className = 'disableScreen disableScreenExt';
					}
				}
				//calculate overlay dimensions if popup is bigger than overlay//
				
	};
	
	this.renderFrenchRecipeVideos = function(popup_id, title, flash_url, width, height, flash_width, flash_height){
        window.scrollTo(0,0);
		var ovip = document.createElement("div");
		ovip.id = popup_id;
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			ovip.className = "overlayFPopupIE6";
		}else{
			ovip.className = "overlayFPopup";	
		}
		if ($(popup_id) === null){
			document.body.appendChild(ovip);
	    }  
		if ($('overlay').innerHTML === null){
			this.createOverlayNoTransparency();
            this.setOverlayDimensions();
		}
		$('overlay').className = ""; //remove transparency
		$('overlay').innerHTML = "<div style='left: 50%; margin-left: -320px; width: 640px; max-width: 640px; display: none;' class='" + ovip.className + "' id='" + ovip.id + "'></div>";
		ovip = $(popup_id);
		ovip.innerHTML = "<div class='overlayLayerMenue'  style='background-color:#141416;height:30px;width:" + width + "px;overlfow:hidden;'>" +
						     "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
							 title + 
							 "</label>" +
							 "<button id='" + popup_id + "_close' class='overlayPopupButton' " + " onclick='GaggenauEffects.closeFlashPopupNoTransparency();'>" + 
							 "</button>" +
						 "</div>" +
						 "<div style='margin:50px 0 0 0;width:" + width + "px;height:" + height + "px;overflow:hidden;text-align:center;'>" +
			             	"<div id='" + popup_id + "_flashcontent'>" + 
							"</div>" + 
						 "</div>";
		//calculate popup position
		width = width*1;
		height = height*1;
		var win_w = document.viewport.getWidth() / 2;
		var pop_w = width / 2;		
		if (pop_w <= win_w){
			ovip.style.left = "50%";		
			ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
		}else{
			ovip.style.left = "0px";		
			ovip.style.marginLeft =  "0px";
		}
		ovip.style.width = width + "px";
		ovip.style.maxWidth = width + "px";
		ovip.show();
						
		/* real gaggenau flash player path */
var flashvars = {};
  flashvars.file = flash_url;
  flashvars.type = 'flv';
  flashvars.linkfromdisplay = 'true';
  flashvars.lightcolor = '0x557722';
  flashvars.searchbar = 'false';
  flashvars.shuffle = 'true';
  flashvars.overstretch = 'false';
  flashvars.width = flash_width;
  flashvars.height = flash_height;
  flashvars.autostart = 'true';
  flashvars.shownavigation = 'true';
var params = {};
var attributes = {};
  /*attributes.bgcolor = '#282828'*/
  attributes.bgcolor = '#000000'
  attributes.allowfullscreen = 'true'
swfobject.embedSWF('flash/mediaplayer.swf', popup_id + '_flashcontent', flash_width, flash_height, "9", false, flashvars, params, attributes);
    
/*				so.addParam('allowfullscreen', 'true');
		so.addParam('bgcolor', '#000000');
		so.addVariable('file', flash_url);
		so.addVariable('type', 'flv');
		so.addVariable('linkfromdisplay', 'true');
		so.addVariable('lightcolor', '0x557722');
		so.addVariable('searchbar', 'false');
		so.addVariable('shuffle', 'true');
		so.addVariable('overstretch', 'true');
		so.addVariable('width', width);
		so.addVariable('height', height);
		so.write(popup_id + '_flashcontent');*/
		$("overlay").show();
		
		//calculate overlay dimensions if popup is bigger than overlay//
		var bigger = false;
		var ov = $('overlay');
	    var ov_width = ov.offsetWidth;
	    var ov_height = ov.offsetHeight;
		if (ov_width < width){
			ov.style.width = width + "px";
			bigger = true;
		}
		if (ov_height < height){
			ov.style.height = height + "px";
			bigger = true;
		}
		//calculate overlay dimensions if popup is bigger than overlay//
		
};

////////////////

this.renderConfiguratorPopup = function(popup_id, title, flash_url, width, height){
              window.scrollTo(0,0);
            var ovip = document.createElement("div");
            ovip.id = popup_id;
            if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
               ovip.className = "overlayFPopupIE6";
            }else{
               ovip.className = "overlayFPopup";   
            }
            if ($(popup_id) === null){
               document.body.appendChild(ovip);
             }  
            if ($('overlay').innerHTML === null){
               this.createOverlay();
                   this.setOverlayDimensions();
            }
            $('overlay').innerHTML = "<div style='left: 50%; margin-left: -320px; width: 640px; max-width: 640px; display: none; top: 0px;' class='" + ovip.className + "' id='" + ovip.id + "'></div>";
            $('overlay').setAttribute("style","-moz-opacity:1.0;opacity:1.0;filter:alpha(opacity=100);");
            ovip = $(popup_id);
            ovip.innerHTML = "<div class='overlayLayerMenue'  style='background-color:#29292C;height:30px;width:" + width + "px;overlfow:hidden;'>" +
                             "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
                            title + 
                            "</label>" +
                            "<button id='" + popup_id + "_close' class='overlayPopupButton' " + " onclick='GaggenauEffects.closeFlashPopup();'>" + 
                            "</button>" +
                         "</div>" +
                         "<div style='width:" + width + "px;height:" + height + "px;overflow:hidden;'>" +
                              "<div id='" + popup_id + "_flashcontent'>" + 
                           "</div>" + 
                         "</div>";
            //calculate popup position
            width = width*1;
            height = height*1;
            var win_w = document.viewport.getWidth() / 2;
            var pop_w = width / 2;     
            if (pop_w <= win_w){
               ovip.style.left = "50%";      
               ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
            }else{
               ovip.style.left = "0px";      
               ovip.style.marginLeft =  "0px";
            }
            ovip.style.width = width + "px";
            ovip.style.maxWidth = width + "px";
            ovip.show();
            
            /* real gaggenau flash player path */
            var flashvars = {};
			      var params = {};
		          params.quality = 'high';
			      var attributes = {};
		          attributes.bgcolor = '#000000'
            swfobject.embedSWF(flash_url, popup_id + '_flashcontent', width, height, "6.0.0", false, flashvars, params, attributes);
            $("overlay").show();
			
			//calculate overlay dimensions if popup is bigger than overlay//
				var bigger = false;
				var ov = $('overlay');
			    var ov_width = ov.offsetWidth;
			    var ov_height = ov.offsetHeight;
				if (ov_width < width){
					ov.style.width = width + "px";
					bigger = true;
				}
				if (ov_height < height){
					ov.style.height = height + "px";
					bigger = true;
				}
				if (bigger === true){
					if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){	
					}else{
						ov.className = 'disableScreen disableScreenExt';
					}
				}
			//calculate overlay dimensions if popup is bigger than overlay//
   };

////////////////

	/**
	 * renders overlay image popup
	 * @param {Object} title - popup title
	 * @param {Object} content_url - iframe content url
	 */
	this.renderImagePopup = function(popup_id, title, content_url){
		window.scrollTo(0,0);
		var width = 0;	
		var im = new Image();
		im.src = content_url;
		if (im.width === 0){
	        Event.observe(im, 'load', function(event){
				width = im.width;		
				Element.show("overlay");
				var ovip = document.createElement("div");
				ovip.id = popup_id;
				if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
					ovip.className = "overlayFPopupIE6";
				}else{
					ovip.className = "overlayFPopup";	
				}
				if ($(popup_id) === null){
					document.body.appendChild(ovip);
			    }
				ovip = $(popup_id);
				ovip.hide();
				ovip.innerHTML = "<div class='overlayLayerMenue'  style='width:" + 
				                 width + 
								 "px;overlfow:hidden;'>" +
								     "<div class='overlayLayerMenueTitle' style='width:" + 
				                     (width - 40) + 
								     "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
									 title + 
									 "</div>" +
									 "<img src='image/common/close.gif' class='close'" + 
									 " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
									 "</img><div class='clear'></div>" +
								 "</div>" +
								 "<div style='width:" + 
								 width + 
								 "px;overflow:hidden;'>" +
								 
							     "<table width=100% height=100% border='0' " + 
							     " cellpadding='0' cellspacing='0'>" +
		                         "<tr>" +
		                         "<td align='center' valign='middle'>" +
								 
					                 "<img id='ovip_frame' name='ovip_frame' src='" + 
									 content_url + 
									 "' />" +
								 "</td></tr></table></div>";
		
		
				//calculate popup position
				var win_w = document.viewport.getWidth() / 2;
				var pop_w = width / 2;
						
				if (pop_w <= win_w){
					ovip.style.left = "50%";		
					ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
				}else{
					ovip.style.left = "0px";		
					ovip.style.marginLeft =  "0px";
				}
				ovip.style.width = width + "px";
				ovip.style.maxWidth = width + "px";
		
				Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});			
			
			});
		}else{
				width = im.width;		
				Element.show("overlay");
				var ovip = document.createElement("div");
				ovip.id = popup_id;
				if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
					ovip.className = "overlayFPopupIE6";
				}else{
					ovip.className = "overlayFPopup";	
				}
				if ($(popup_id) === null){
					document.body.appendChild(ovip);
			    }
				ovip = $(popup_id);
				ovip.hide();
				ovip.innerHTML = "<div class='overlayLayerMenue'  style='width:" + 
				                 width + 
								 "px;overlfow:hidden;'>" +
								     "<div class='overlayLayerMenueTitle' style='width:" + 
				                     (width - 40) + 
								     "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
									 title + 
									 "</div>" +
									 "<img src='image/common/close.gif' class='close'" + 
									 " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
									 "</img><div class='clear'></div>" +
								 "</div>" +
								 "<div style='width:" + 
								 width + 
								 "px;overflow:hidden;'>" +
								 
							     "<table width=100% height=100% border='0' " + 
							     " cellpadding='0' cellspacing='0'>" +
		                         "<tr>" +
		                         "<td align='center' valign='middle'>" +
								 
					                 "<img id='ovip_frame' name='ovip_frame' src='" + 
									 content_url + 
									 "' />" +
								 "</td></tr></table></div>";
		
		
				//calculate popup position
				var win_w = document.viewport.getWidth() / 2;
				var pop_w = width / 2;
						
				if (pop_w <= win_w){
					ovip.style.left = "50%";		
					ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
				}else{
					ovip.style.left = "0px";		
					ovip.style.marginLeft =  "0px";
				}
				ovip.style.width = width + "px";
				ovip.style.maxWidth = width + "px";
		
				Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
		}		
	};
	

	/**
	 * renders features popup
	 */
	this.renderFeaturesPopup = function(popup_id, width, content_id){
		window.scrollTo(0,0);		
		Element.show("overlay");
		var ovip = document.createElement("div");
		ovip.id = popup_id;		
	    if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			ovip.className = "overlayFPopupIE6";
		}else{
			ovip.className = "overlayFPopup";	
		}
		if ($(popup_id) === null){
			document.body.appendChild(ovip);
			ovip = $(popup_id);
			ovip.hide();
			ovip.innerHTML = "<div  class='overlayLayerMenue'  style='height:30px;width:" + 
			                 width + 
							 "px;overlfow:hidden;'>" +
							     "<label id='ovHeader' class='overlayLayerMenueTitle' style='width:" + 
			                     (width - 100) + 
							     "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
								 "</label>" +
								 "<button class='overlayPopupButton' " + 
								 " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
								 "</button>" +
							 "</div>" +
							
							 "<div style='width:" + 
							 width + 
							 "px;overflow:hidden;'>" +
							 						 						 
								 "<div style='width:" + 
								 width +
								 "px;overflow:hidden;margin-bottom:-3px;'>" +				
							    	 "<table width=100% height=100% border='0' " + 
									 " cellpadding='0' cellspacing='0'>" +
				                     "<tr>" +
				                     "<td align='center' valign='middle'>" +
								     	"<img id='ovImage' name='ovip_frame' src='' />" +
								     "</td></tr></table>" + 
							     "</div>" +	
							 
								 "<div class='smallLayerTitle'><p id='ovTitle' style='margin-left:207px;' ></p></div>" +
								
								 "<div class='smallLayerContent'>" +
								 
								    "<span style='float:left;width:173px;max-width:173px;overflow:hidden;'>" +
								    	"<ul id='ovNavigation' class='downloadsLi'></ul>" +
									"</span>" +
								    
									"<span id='ovContentWrapper'>" +
								    "<span style='float:left;width:368px;max-width:368px;padding-left:20px;'>" +
										"<p id='ovContent' ></p>" +
								    "</span>" +
									"</div>" +
																	
									"<div style='height:16px;max-height:16px'></div>" +
								
							"</div>";
		}	
		ovip = $(popup_id);	
		//fill the contents according given content_id
		var contents = $(content_id).childElements();
		$('ovHeader').innerHTML = contents[0].innerHTML;
			
		if ((contents[1].src != '')&&
			(contents[1].src != 'undefined')&&
			(contents[1].src != undefined)&&
			(contents[1].src != null)){
			$('ovImage').src = contents[1].src;
			$('ovImage').show();
		}else{
			$('ovImage').hide();
		}
				
		$('ovTitle').innerHTML = contents[2].innerHTML;
		$('ovNavigation').innerHTML = contents[3].innerHTML;
		//$('ovContent').innerHTML = contents[4].innerHTML;
		$('ovContentWrapper').innerHTML = "<span style='float:left;width:368px;max-width:368px;padding-left:20px;'>" +
										  "<p id='ovContent' >" + contents[4].innerHTML + "</p>" +
								          "</span>";		

		//calculate popup position
		var win_w = document.viewport.getWidth() / 2;
		var pop_w = width / 2;		
		if (pop_w <= win_w){
			ovip.style.left = "50%";		
			ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
		}else{
			ovip.style.left = "0px";		
			ovip.style.marginLeft =  "0px";
		}
		ovip.style.width = width + "px";
		ovip.style.maxWidth = width + "px";

		if (ovip.visible() === false){
			Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
		}
		
	};
	
	/**
	 * renders success popup with given width, text
	 * @param {Object} width
	 * @param {Object} text
	 * @param {Object} button_text
	 */
	this.renderSuccessPopup = function(popup_id, width, header_text, text, button_text, action){
		window.scrollTo(0,0);		
		Element.show("overlay");		
		var ovip = document.createElement("div");	
		ovip.id = popup_id;
		if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
			ovip.className = "overlayFPopupIE6";
		}else{
			ovip.className = "overlayFPopup";
		}		
		if ($(popup_id) === null){
			document.body.appendChild(ovip);
		}
		ovip = $(popup_id);
		ovip.hide();		
		ovip.innerHTML = "<div id='layerSmall1' class='InnerFreezePaneLayer' style='width:" + width + "px;overflow:hidden; background-color:#000000; top: 0px;'>" + 
      "<div class='layermenue' style='background-color:#000; border-bottom:2px solid #282828;'>" +
      "  <div class='menuetitle'>" + header_text + "</div>" +
      "  <img class='close' src='image/common/close.gif' onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});" + 
                        "Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});" +
                    action +  
                    "'/></div>" +
      "<img id='zoomImg' src='image/common/blank.gif' width='" + width + "' height='1' />" +
      "<div class='loginformBox' id='formTeaser' style='padding-right: 15px;'>" +
      "  <p>" + text + "</p>" +
          "<div style='width:" + (width - 15) + "px;overflow:hidden;'>" + 
			"<button style='float:right;margin-right:5px;margin-bottom:5px;' " + 
			" id='ovipSuccessPopupCloseBtn' " + 
			" onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});" + 
			          "Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});" +
					  action +  
					  "' " +
			" >" + button_text + "</button>"
		  "</div></div></div>";
		 	 
		//calculate popup position
		var win_w = document.viewport.getWidth() / 2;
		var pop_w = width / 2;		
		if (pop_w <= win_w){
			ovip.style.left = "50%";		
			ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
		}else{
			ovip.style.left = "0px";		
			ovip.style.marginLeft =  "0px";
		}
		ovip.style.width = width + "px";
		ovip.style.maxWidth = width + "px";
		Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
	};
	
//	this.saveFile = function(fname)
//	{
//		document.execCommand('SaveAs',null,fname)
//	};
	
	/**
	 * renders popup with a list of links with given width, text
	 * @param {Object} width
	 * @param {Object} text
	 * @param {Object} button_text
	 * @param {String} prefix locale
	 */
	this.renderLinksListPopup = function(popup_id, title, prefix, v1Name, v2Name, v3Name, v4Name, v5Name, v6Name, v7Name, width, height) {
		    window.scrollTo(0,0);		
			Element.show("overlay");
			var ovip = document.createElement("div");
			ovip.id = popup_id;
			if ((BrowserDetect.browser === "Explorer")&&(BrowserDetect.version <= 6)){
				ovip.className = "overlayFPopupIE6";
			}else{
				ovip.className = "overlayFPopup";	
			}
			if ($(popup_id) === null){
				document.body.appendChild(ovip);
		    }
			ovip = $(popup_id);
			ovip.hide();
			ovip.innerHTML = "<div class='overlayLayerMenue'  style='height:30px;width:" + width + "px;overlfow:hidden;'>" +
							     "<label class='overlayLayerMenueTitle' style='width:" + (width - 40) + "px;overlfow:hidden;float:left;font-weight:bold;'>" + 
								 title + 
								 "</label>" +
								 "<button class='overlayPopupButton' " + " onclick='Effect.Fade(\"" + popup_id + "\",{duration:GaggenauEffects.animationSpeed});Effect.Fade(\"overlay\",{duration:GaggenauEffects.animationSpeed});'>" + 
								 "</button>" +
							 "</div>" +
							 "<div class=\"smallLayerContent\"><span style=\"overflow: hidden; float: left; width: 173px; max-width: 173px;\">" +
					 		 "<ul class=\"navleftLinks\" id=\"ovNavigation\">" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/01_Installation_in_general.wmv&name=01_Installation_in_general.wmv&mime=video/x-msvideo&attachfile=true\'>" + v1Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/02_Side_by_side_combination.wmv&name=02_Side_by_side_combination.wmv&mime=video/x-msvideo&attachfile=true\'>" + v2Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/03_Change_of_door_hinge.wmv&name=03_Change_of_door_hinge.wmv&mime=video/x-msvideo&attachfile=true\'>" + v3Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/04_Ice_and_water_dispenser.wmv&name=04_Ice_and_water_dispenser.wmv&mime=video/x-msvideo&attachfile=true\'>" + v4Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/05_Wine_cooler.wmv&name=05_Wine_cooler.wmv&mime=video/x-msvideo&attachfile=true\'>" + v5Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/06_Additional_heating_element.wmv&name=06_Additional_heating_element.wmv&mime=video/x-msvideo&attachfile=true\'>" + v6Name + "</a></li>" +
							 "<li style='margin-bottom:7px;'><a class=\"naviLink\" style=\"display: block;\" href=\'videos/file.send?file=" + prefix + "/07_Particle_filter_and_activated_charocal.wmv&name=07_Particle_filter_and_activated_charocal.wmv&mime=video/x-msvideo&attachfile=true\'>" + v7Name + "</a></li>" +
							"</ul></span>" +
							"<span id=\"ovContentWrapper\"><span style=\"float: left; width: 382px; max-width: 382px; padding-left: 20px; padding-bottom: 8px;\">" +
							"<img style=\"display: block; width: 382px; height: 250px;\" src=\"image/common/installationvideo/vario-cool.jpg\"/>" +
							"</div>"
							;
					
			//calculate popup position
			var win_w = document.viewport.getWidth() / 2;
			var pop_w = width / 2;
					
			if (pop_w <= win_w){
				ovip.style.left = "50%";		
				ovip.style.marginLeft =  "-" + Math.floor(width / 2) + "px";
			}else{
				ovip.style.left = "0px";		
				ovip.style.marginLeft =  "0px";
			}
			ovip.style.width = width + "px";
			ovip.style.maxWidth = width + "px";

			Effect.Appear(ovip,{duration:GaggenauEffects.animationSpeed});
	};

	
	/**
	 * toggles extender object
	 * @param {Object} bid_1
	 * @param {Object} cid_1
	 * @param {Object} bid_2
	 * @param {Object} cid_2
	 */
	this.toggleExtenderObject = function(bid_1, bid_2, cid_1, cid_2){
		Element.hide(bid_1);
		Element.show(bid_2);
		Effect.BlindUp(cid_1,{duration:GaggenauEffects.animationSpeed});
		Effect.BlindDown(cid_2,{duration:GaggenauEffects.animationSpeed});
	};
	
	/**
	 * renders showroom gallery element
	 * @param {Object} target_id - gallery target element
	 * @param {Object} images_array - gallery array of images url
	 * @param placeholder - placeholder image url
	 * @param interval - time interval between image change (in seconds)
	 */
	this.renderShowroomGallery = function(target_id, images_array, placeholder, interval){
		var slideShow = new Slideshow(target_id,images_array,placeholder,interval);		
	};
		
	/***************************************************************************
	 * Private functions
	 **************************************************************************/	

}

/**
 * GaggenauEffects object
 */
var ge = new GaggenauEffects();

/**
 * add default onload event, that will try to load our page-related settings
 * @param {Object} event
 */
Event.observe(window, 'load', function(event){
    ge.createOverlay();
	ge.setOverlayDimensions();
	try{
		gePageLoad();
	}catch(error){
		//alert('Grr... No gePageLoad() found');
	}
	//Effect.Appear('overlay',{duration:GaggenauEffects.animationSpeed});
});