window.addEvent('domready', function() {
    ImageLayer.init();
    TabContent.init();
    FooterPos.init();
});

window.onresize=function() {
 
    FooterPos.init();
};


var FooterPos = new function(){

	this.init = function(){
		//footer
		//$('footer').style.height = "10px";
		//$('footer').style.height = (document.getScrollSize().y-$('footer').getPosition().y)+"px";
		var _pos = $('container').getPosition().y+$('container').getSize().y;
	//	$('footer').style.width = (document.getSize().x-92*2)+"px";
		
		var _h = document.getSize().y-_pos;
		if(_h<120) _h = 120;
		if(_h>200){
			_h = 200
			_pos = document.getSize().y-200
		}
		$('footer').style.height = _h+"px";
		$('footer').style.top = _pos+"px";
		$('footer').style.display = "block";
	}
}



var TabContent = new function(){
	this.init = function(){
		var mySmoothScroll = new Fx.Scroll("tab-mask", {}).set(0, 0);
		register();
	}	
	var register = function(){

		$$('#tab-head li a').each(function(el){
    		// Link
    		el.addEvents({
    			'click': function(){
    				TabContent.scrollToElem(this.getProperty("id").replace("tab-", ""));
    			}
    		});	
		});
	}
	
	this.scrollToElem = function(elem){
		TabContent.IERelativeBug(false);
		var mySmoothScroll = new Fx.Scroll("tab-mask", {duration:200, onComplete:function(){
		TabContent.IERelativeBug(true);
		}}).start(elem*900-900, 0);		
		// SET ACTIVE
		$$('#tab-head li a').each(function(el){
    		// Link
			var _id = el.getProperty("id");
			el.getParent().className = ""
			if(_id == "tab-"+elem) el.getParent().className = "act"
			
		});
		
	}
	
	this.IERelativeBug = function(bool){
		$$('.image').each(function(el){
			el.style.position = bool ? "relative" : "static";
		});
		$$('div.resize-icn').each(function(el){
			el.style.display = bool ? "block" : "none";
		});
		
		
	}

}






var ImageLayer = new function(){
	this.init = function(){
		register();
		$('deactive').addEvent('click', function(){
			ImageLayer.close();
		});
	}	
	var register = function(){
		$$('div.image').each(function(el){
    		// Link
    		el.getElement('a.resize').addEvents({
    			'click': function(){
    				ImageLayer.open(this.getProperty("href"))
    				return false;
    			}
    		});	
		});
	}
	
	this.open = function(src){	
		
		
		$('deactive').style.display = "block";
		$('deactive').style.height = window.getScrollSize().y+"px";
		var myFx = new Fx.Elements($('deactive'), {duration:100}).start({'0': {'opacity': [0,.75] }});
		$('layer').style.display = "block";
		
		var closeBtn = new Element("a", {id:"close-img"});
		closeBtn.inject($('layer'));

		closeBtn.addEvent('click', function(){
			ImageLayer.close();
		});

		if(src=="../content/flash/1772_Ani_de.swf" || src=="../content/flash/1772_Ani_en.swf"){
				
				var myFx = new Fx.Elements($('layer'), {
					onComplete: function(){
						var bigSwf = new Element("div", {id:"bigImg"});
						bigSwf.inject($('layer'));
						
						var bigSwfCnt = new Element("div", {id:"bigSwf"});
						bigSwfCnt.inject(bigSwf);
						//bigImg.style.display = "block";
						//var myFx = new Fx.Elements(bigImg, {duration:500}).start({'0': {'opacity': [0,1] }});
						swfobject.embedSWF(src, "bigSwf", "800", "500", "8", "expressInstall.swf", {}, {"wmode":"transparent", "allowFullscreen":"true", "AllowScriptAccess":"always", "bgcolor":"#cccccc"})

						
					}
				}).start({
				    '0': {
				        'height': [500],
						'width': [800],
						'margin-top': [-Math.round(500/2)],
						'margin-left': [-Math.round(800/2)]
				    }
				});
		}else{
			var jetzt = new Date();
			src += "?"+jetzt.getTime()
			var bigImg = new Element("img", {id:"bigImg", src:src, style:"visibility:hidden"});
			bigImg.inject($('layer'));				
			bigImg.addEvent('load', function(){
    			//alert(bigImg.getSize().y);
    			var size = bigImg.getSize()
		
    			bigImg.setStyle('opacity', '0')
    			bigImg.style.visibility = "visible";
    			bigImg.style.display = "none";
    			var myFx = new Fx.Elements($('layer'), {
					onComplete: function(){
						bigImg.style.display = "block";
						var myFx = new Fx.Elements(bigImg, {duration:500}).start({'0': {'opacity': [0,1] }});
		
						
					}
				}).start({
				    '0': {
				        'height': [size.y],
						'width': [size.x],
						'margin-top': [-Math.round(size.y/2)],
						'margin-left': [-Math.round(size.x/2)]
				    }
				});
			});
		}
		
		
	}
	
	this.close = function(){
		if($('bigImg')) $('bigImg').dispose();
		var myFx = new Fx.Elements($('deactive'), {duration:1000}).start({'0': {'opacity': [1,0] }});
		var myFx = new Fx.Elements($('layer'), {
				onComplete: function(){
					$('deactive').style.display = "none";
					$('layer').style.display = "none";
					if($('close-img')) $('close-img').dispose();
				}
			}).start({
			    '0': {
			        'height': [50],
					'width': [50],
					'margin-top': [-25],
					'margin-left': [-25]
			    }
			});	
	}
}
