/**
* @author Marius
*/
var mainmenu_open = true;
window.addEvent('domready', function(){
	attachTabsToAll();
});
function toggleMenu(){
	if (!mainmenu_open){
		var fx = new Fx.Styles($('mainmenu_shifter'), {duration:300, wait:false});
	$('mainmenu_bg').setStyle('opacity',0);
	fx.options.transition = Fx.Transitions.Sine.easeOut;
	fx.start({
	}).chain(function(){
		this.start.delay(0, this, {
			'margin-left': 0
		});
	}).chain(function(){
		var fx2 = new Fx.Styles($('mainmenu_bg'), {duration:100, wait:false});
		fx2.start({
			'opacity': 1
		});
		this.start.delay(50, this, {
			'opacity': 0
		});
		});
		mainmenu_open = true;
	}
	else {
		var fx = new Fx.Styles($('mainmenu_shifter'), {duration:300, wait:false});
	fx.options.transition = Fx.Transitions.Sine.easeIn;
	fx.start({
	}).chain(function(){
		var fx2 = new Fx.Styles($('mainmenu_bg'), {duration:100, wait:false});
		
		fx2.start({
		}).chain(function(){
			this.start.delay(50, this, {
				'opacity': 0
			});
		});
		fx2.start({
			
		});
		this.start.delay(0, this, {
			'opacity': 1
		});
		
	}).chain(function(){
		this.start.delay(0, this, {
			'margin-left': 770
		});
		});
		mainmenu_open = false;
	}
}

function attachTabsToAll(){
	$$('.box_dynamic').each(function(box_dynamic) {
		attachTabsToBox(box_dynamic);
	});	
}

function attachTabsToBox(elem){
	var layers = elem.getChildren();
	var tabsHeader = layers[0];
	var tempTabsButtons = tabsHeader.getChildren();
	layers[1].getChildren()[0].setStyle('display','block');
	layers[0].getChildren()[0].addClass('active');
	tempTabsButtons.each(function(tempTabsButton){
		if (tempTabsButton.hasClass('tab')){
			tempTabsButton.addEvent('click', function(event){
    		tabClick(tempTabsButton);
			});
			tempTabsButton.setProperty('href','javascript:void(1);');
		}
	});
}

function tabClick(target){
	var actIndex = 0;
	var tabsHeader = target.getParent();
	var tabButtons = Array();
	var tempTabsButtons = tabsHeader.getChildren();
	tempTabsButtons.each(function(tempTabsButton){
		if (tempTabsButton.hasClass('tab'))
			tabButtons.push(tempTabsButton);			
	});
	for (var i = 0; i < tabButtons.length; i++) {
		if (tabButtons[i] == target) {
			actIndex = i;
			target.addClass('active');
		}
		else {
			tabButtons[i].removeClass('active');
		}
	}
	var tabsContent = tabsHeader.getParent().getChildren()[1].getChildren();
	for (var i=0;i< tabsContent.length;i++){
		if (i==actIndex)
			tabsContent[i].setStyle('display','block');
		else
			tabsContent[i].setStyle('display','none');
	}
} 





function changeLang(langId){

 	var langId;
	var actLocation = document.location.href;
	var locationArray = actLocation.split("?");
	var loc = locationArray[0]; 
	var request = locationArray[1];
	
 	if(request == undefined){
		document.location = loc + '?langid=' + parseInt(langId);	
	}
	else{ 
		document.location = loc + '?' + request + '&langid=' + parseInt(langId);
	}
	 
} 
