var newNavi  = false;
var newDelay = false;
var newLangDelay = false;
var languages = false;
var toggle = false;

var navi = 300; /* Sagt wie lang(Millisekunden) die navi stehen bleiben soll nach Mouseout */

window.addEvent('domready', function(){

	new Accordion($$('.left .toggler'), $$('.left .accordion'), {
		display:-1,
		alwaysHide: true,
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('background-image','url("tl_files/diotec/system/images/link_down.gif")');
	    },
	    onBackground: function(toggler, element){
			toggler.setStyle('background-image','url("tl_files/diotec/system/images/link.gif")');
	    }
	});
	
	new Accordion($$('.right .toggler'), $$('.right .accordion'), {
		alwaysHide: true,
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('background-image','url("tl_files/diotec/system/images/link_down.gif")');
	    },
	    onBackground: function(toggler, element){
			toggler.setStyle('background-image','url("tl_files/diotec/system/images/link.gif")');
	    }
	});
	
	
	/* NAVIGATION */

	var border = '<div class="corner left"></div>';
	border 	  += '<div class="corner right"></div>';
	border 	  += '<div class="corner left-corner"></div>';
	border 	  += '<div class="corner right-corner"></div>';
	border 	  += '<div class="corner bottom"></div>';

	newNavi = new Element('div',{
		'class': 'customNavigation',
		'html': border+'<div class="border">'+$$('#header .mod_navigation').get('html')+'</div>'
	}).inject('wrapper','bottom').setStyles({
		'display':'none','opacity':0
	}).clone().inject('wrapper','bottom').set('class','customNavigation second');
	
	$$('.customNavigation').addEvents({
		'mouseenter': function(event){
			newDelay = $clear(newDelay);
			$$(newNavi).setStyles({'display':'block'});
		},'mouseleave': function(event){
			newDelay = hideNavi.delay(navi,$$(newNavi));
	    }
	});

	$$('#header .mod_navigation li').addEvents({
		'mouseenter': function(event){
			if(this.getChildren('ul')[0] != undefined){
				newDelay = $clear(newDelay);
				$$('.customNavigation').set('html', border+'<div class="border">'+this.get('html')+'</div>')
					.setStyles({
						'opacity':0,
						'display':'block',
						'left':this.getPosition().x+"px"
					})
					.set('tween', {duration: navi})
			    	.tween('opacity',0.93);
			}
		},
        'mouseleave': function(event){
			newDelay = hideNavi.delay(navi,$$(newNavi));
        }
	});
	
	$$('.mod_changelanguage .languages').addEvents({
		'mouseenter':function(){
			this.getParent('.mod_changelanguage').setStyles({
				'height':'auto',
				'overflow':'visible'
			});
			this.getChildren('.change').setStyles({
				'display':'block',
				'visibility':'visible'
			});
		},
		'mouseleave':function(){
			this.getChildren('.change').setStyles({
				'display':'none',
				'visibility':'hidden'
			});
			this.getParent('.mod_changelanguage').setStyles({
				'height':'32px',
				'overflow':'hidden'
			});
		}
	});

	if($('subForm') != null){
		$('subForm').reset();
		$$('#subForm select').addEvent('change',function(){
			var w = this.selectedIndex;
			this.setAttribute('title',this.options[w].text);
			this.getPrevious().set('text',this.options[w].text);
		});
		$$('#subForm input[type=text]').addEvents({
			'focus':function(e){
				if(this.value == this.title)
					this.value = "";
			},'blur':function(e){
				if(this.value == "")
					this.value = this.title;
			}
		});
		
		var color = "#680C0F";
		$$('#subForm .button').addEvent('mouseover',function(){
			color = this.getStyle('color');
			this.setStyle('background-image','url("tl_files/diotec/system/images/newsletter_submit_hover.png")');
			this.setStyle('color','#680C0F');
		}).addEvent('mouseout',function(){
			this.setStyle('color',color);
			this.setStyle('background-image','url("tl_files/diotec/system/images/newsletter_submit.png")');
		});
	}
	
	$$('.all_languages').addEvent('change',function(){
		var w = this.selectedIndex;
		if(w != undefined){
			window.location.href = window.location.pathname+"?land="+this.options[w].value;

			
			/*
			 * Anker
			 * window.location.hash = this.options[w].get('value');
			document.getElementsByName(anchorName)[0].scrollIntoView(true);*/
		}
	});
	
	/* Image Map */
	
	if($$('map#Continents')){
		var continents = $$("img[usemap&='Continents']").get('src')[0];
		$$('map#Continents area').addEvent('mouseenter',function(){
			$$("img[usemap&='Continents']").set('src','tl_files/diotec/system/images/worldmaps/'+this.get('class')+'_worldmap.png');
		}).addEvent('mouseleave',function(){
			$$("img[usemap&='Continents']").set('src',continents);
		});
	}
	
}); 

function hideNavi(){
	$$('.customNavigation').setStyle('display','none');
}
function hideLangNavi(){
	this.setStyles({
		'display':'none'
	});
}
