/*Produkt Menu*/
var ProductMenu =  {
	layer : false,
	layercontent : false,
	loading : '&nbsp;',
	init : function(){
		
		this.layer = document.createElement("div");		
		$(".top-menue-teaser").append(this.layer);
		$(this.layer).addClass("product-menu-layer");
		$(this.layer).attr('id','product-menu-layer');
		$(".product-menu-layer").css({'display':'none'});
		//$(this.layer).bind("mouseout", ProductMenu.close);
		$(this.layer).bind("mouseleave", ProductMenu.close);	
		
	},
	open : function(e){
		if(!this.layercontent){
			ProductMenu.layer.innerHTML = this.loading;	
			$.get("index.php?siteid=productmenu", function(data){
				
				ProductMenu.layer.innerHTML = data;
				ProductMenu.layercontent = true;
				$("a.product_preview_img").each(function(){
			 		$(this).bind('mouseover', function(){
			 			var pre_img = $(this).attr("rel"); 
			 			
			 			var first_parent = $(this).parents("div:eq(1)"); 
			 					
						if(first_parent.attr("class") == "teaser-horizont")
			 			{
			 				$("#Horizont-Schranksysteme").attr("src",pre_img);
			 			}
			 			else if (first_parent.attr("class") == "teaser-trend")
			 			{
			 				$("#Trend-Collection").attr("src",pre_img);
			 			}
			 			else if (first_parent.attr("class") == "teaser-classic")
			 			{
			 				$("#Classic-Collection").attr("src",pre_img);
			 			}
			 			
			 		});
				});
		
				
			});
			
		}
		$(ProductMenu.layer).slideDown();
		return true;
		
	},
	close : function(e){
		$(ProductMenu.layer).slideUp();
		return false;
		/*
		window.setTimeout(function(){
				$(ProductMenu.layer).slideUp();
			},
			500
		);*/
	}
}


var Flash = {
	stage : false,
	header : false,
	check : false,
	init : function(){
		this.stage = $(".header-swf");
		this.header = $(".header");
		this.flash = $("#flash-content");
		$(window).resize(function(){	
			Flash.centerStage();
		});

	},
	centerStage : function(){
		/*console.log($(window).width());
		console.log(this.stage.width());
		console.log("left= "+(($(window).width()- this.stage.width()) /2));*/
		this.stage.css('left', ($(window).width() - this.stage.width())/2);
	},
	checkPosition : function(){
		this.centerStage();
		if(this.check){
			window.setTimeout(function(){
					Flash.checkPosition();
				},
				20
			)
		}
	},
	resizeStage : function(height, width){
		var options = {};
		
		var headerOptions = {};
		
		var flashoptions = {};
		
		this.check = true;
		
		if(height){
			options.height = (parseInt(height)+59)+"px";
			headerOptions.height = height+"px";
			flashoptions.height = height+"px";
			
		}
	
		if(width){
			
			var widthoptions = {};
			widthoptions.width = width;
			
			
			
			if($.browser.msie == true){
				$(this.stage).resize(function(){
					Flash.centerStage();
				});
			}else{
				Flash.checkPosition();
			}
			
			this.stage.animate(widthoptions, 0, "linear", function(){
				Flash.centerStage();
				Flash.check = false;
			});
		}
		
		
		
		this.stage.animate(options, 500);
		
		this.header.animate(headerOptions, 500);
		
		this.flash.animate(flashoptions, 500);
		
		
		if($.browser.msie == true) {
			$("#flash-content").animate(
			{ 
				height: flashoptions.height 
			}, 500);
		}
		
	}
}

var Site = {
	goTo : function(url){
		document.location.href = url;
	}
}

var Effects = {
	accordion : function(className, head){		 			    
	    if($(head).next().css('display') == 'none'){	    	
	    	
	    	$('.' + className).each(function() {
	    		$(this).removeClass(className+'-open').children('p').hide(300);
	    		$(this).removeClass(className+'-open').children('dl').hide(300);
	    		$(this).find('img').remove();
	        });	
	    	
	    	
	    	$(head).parent().addClass(className+'-open');
	    	
	    	/**
	    	 * add content img
	    	 */
	    	var classOpen = $('.'+className+'-open');
	    	var exhibitionimg = classOpen.find('span.exhibitionimg').text();
	    	var createImg = (exhibitionimg != '0') ? '<img src="'+exhibitionimg+'" class="exhibitionimg" />' : '';
	    	
	    	if(exhibitionimg.length > 0 && exhibitionimg != '0')
	    	{
	    		
	    		classOpen.prepend( createImg );
	    		$('img.exhibitionimg').hide(0);
	    		$('img.exhibitionimg').fadeIn(200);
	    	}
	    	$(head).next().slideDown(700);
	    	
	    	
	    	
	    }
    }

}
var isResized = false;
function resizeFlashStage(hoehe) {
	var hoeheFlash;
	var hoeheSWF;
	if (!isResized) {
		if (hoehe < 100) {
			Flash.resizeStage(hoehe);
			document.getElementById('header-swf').style.background = "none";
		}
		else 
			if ((hoehe > 100) && (hoehe < 500)) {
				Flash.resizeStage(hoehe);			
			}
			else {				
				Flash.resizeStage(hoehe);
			}
			isResized = true;
	}
}

function popupLink (el) {
	var w 		= $(window);
	var wWidth  = w.width();
	var wHeight = w.height();
	var link 	= el.attr('href');
	var pH		= (wHeight - 80);
	var pW		= (wWidth - 100);
	var nW      = ( (wWidth - pW ) / 2 ); 
	var nH      = ( (wHeight - pH ) / 2 ); 
	// console.log( w.width() );
	
	window.open(link, "newWindow", "width="+pW+",height="+pH+",left="+nW+",top="+nH);
	return false;
}

