var core = {
	
	tabContainer		: null,
	tabContainerWidth	: 0,
	tabContainerHeight	: 0,
	tabCount			: 0,
	tabActive			: 1,
	tabDuration			: 0.5,
	
	initialize: function(container,tabCount){
		core.tabContainer = $(container);
		core.tabContainerWidth = core.tabContainer.getWidth();
		core.tabCount = tabCount;	

		tabitems = Array();
		
		for(i=tabCount;i>0;i--){
			tabItem 			= $('tabItem'+i);
			tabitems[tabitems.length] = tabItem;
			tabitemWidth 		= tabItem.getWidth();
			tabContainerHeight	= tabItem.getHeight();
			tabContent			= $('tabContent'+i);			
			tabButton			= $('tabButton'+i);
			tabButtonWidth 		= tabButton.getWidth();
			
			width = tabitemWidth-(tabButtonWidth*core.tabCount)-(parseInt(tabContent.getStyle('paddingLeft').replace("px",""))+parseInt(tabContent.getStyle('paddingRight').replace("px","")));

			tabContent.style.width = width+"px";
			tabItem.style.left = (core.tabContainerWidth-tabitemWidth-(tabButtonWidth*(core.tabCount-i)))+"px";		
			tabItem.style.zIndex = core.tabCount-i;
			Event.observe(tabButton, 'click', core.displayTab); 
		}		
		/*new Effect.DelayedChain('SlideDown', tabitems, { duration: 0.5,afterUpdate: function(obj){obj.element.style.visibility ='visible';} }, 500);*/		
	},
	
	displayTab: function(event,id){
		if(event != false){
			tabButton = $(event.currentTarget || event.srcElement);
			// action when tab moves
			// aditional close tabs, caused by an error of the youtube movie
			
			$('content_contact_3').style.display = 'none';
			$('content_contact_2').style.display = 'none';
			$('content_contact_1').style.display = 'block';
			$('contact_link_3').className = 'knop43';
			$('contact_link_2').className = 'knop42';
			$('contact_link_1').className = 'knop41Active';
			
			
		}else{
			tabButton = $(id);
		}
		tabNr = tabButton.id.replace('tabButton','');
		
		if(tabNr > core.tabActive){
			for(i=1;i<tabNr;i++){
				core.tabActive = tabNr;
				core.moveToLeft(i);
			}
		}else{
			for(i=core.tabCount;i>tabNr-1;i--){
				core.tabActive = tabNr;
				core.moveToRight(i);
			}
		}
		
		
	},
	
	moveToLeft: function(tabNr){
		tabItem 		= $('tabItem'+tabNr);
		tabitemWidth 	= tabItem.getWidth();
		tabButton		= $('tabButton'+tabNr);
		tabButtonWidth 	= tabButton.getWidth();
		left = (0-tabitemWidth)+(tabButtonWidth+(tabButtonWidth*(tabNr-1)));
		new Effect.Move (tabItem,{ 
						 			x: left, y: 0, mode: 'absolute', duration:core.tabDuration,
									beforeStart: function(){
										if(core.tabActive != 3){
														if($('person_unit') != null){
															$('person_unit').style.display = 'none';
														}
													}
										
									},
									afterFinish: function(){
													if(core.tabActive == 3){
														if($('person_unit') != null){
															$('person_unit').style.display = 'block';
														}
													}										
												}
									}
						);		
	},
	
	moveToRight: function(tabNr){
		tabItem 		= $('tabItem'+tabNr);
		tabitemWidth 	= tabItem.getWidth();
		tabButton		= $('tabButton'+tabNr);
		tabButtonWidth 	= tabButton.getWidth();
		left = (core.tabContainerWidth-tabitemWidth-(tabButtonWidth*(core.tabCount-tabNr)));
		new Effect.Move (tabItem,{ x: left, y: 0, mode: 'absolute', duration:core.tabDuration,
									beforeStart: function(){
										if(core.tabActive != 3){
														if($('person_unit') != null){
															$('person_unit').style.display = 'none';
														}
													}
										
									},
									afterFinish: function(){
													if(core.tabActive == 3){
														if($('person_unit') != null){
															$('person_unit').style.display = 'block';
														}
													}										
												}
						 
						 
						 		}
						);		
	}
}



Effect.DelayedChain = Class.create();
Object.extend(Effect.DelayedChain.prototype, {
    initialize: function(effect, elements, options, timeout){
        this.elements = elements;
        this.effect = effect;
        this.timeout = timeout || 100;
        this.options = Object.extend({}, options || {});

        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = Prototype.emptyFunction;
        setTimeout(this.action.bind(this),1);
    },
    action: function() {
        if(this.elements.length){ 
            new Effect[this.effect](this.elements.shift(), this.options);
            setTimeout(this.action.bind(this), this.timeout);
        } else {
            if(this.afterFinish) this.afterFinish();
        }
    }
});

Effect.Chain = Class.create();
Object.extend(Effect.Chain.prototype, {
    initialize: function(effect, elements, options){
        this.elements = elements || [];
        this.effect = effect;
        this.options = options || {};
        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = this.nextEffect.bind(this);
        setTimeout(this.nextEffect.bind(this), 1);
    },
    nextEffect: function(){
        if(this.elements.length)
            new Effect[this.effect](this.elements.shift(), this.options);
        else
            this.afterFinish();
    }
});

