var campaign = new Array();

var Campaign = Class.create();
Object.extend(Campaign.prototype, {
	initialize:function(id)
	{
		this.listElements = $$('#' + id + ' li a');
		this.listElements.each(function(link) {
			Event.observe(link, 'click', function(event) {
				event.stop();
				this.listElements.each(function(links) {
					Element.removeClassName(links, 'active');
					$$('#motiveView ul li').each(function(stage) {
						stage.hide();
					});
				});
				var element = Event.element(event);
				Element.addClassName(element, 'active');
				$('view_' + element.parentNode.id.split('_')[1]).show();
				$('campaignName').innerHTML = element.innerHTML;
				return false;
			}.bind(this));
		}.bind(this)); 
	}
});

var eMOTIVeSlider = Class.create();
Object.extend(eMOTIVeSlider.prototype, {
	initialize:function(id, type)
	{
		this.id = id;
		this.sliderGroup = $(id);
		this.sliderWrapper = this.sliderGroup.parentNode;
		this.wrapper = this.sliderWrapper.parentNode;
		this.slides = $$('#' + this.sliderGroup.id + ' li');
		this.type = type;
		
		this.maxWidth = 0;
		this.counter = 0;
		this.slides.each(function(slide) {
			this.maxWidth += slide.offsetWidth;
			this.counter++;
		}.bind(this));
		this.slideWidth = this.maxWidth / this.counter;
		
		this.sliderGroup.style.width = this.maxWidth + "px";
		
		if(this.counter > 1) {
		
			if(this.type == 'related') {
			
				this.jumpToCurrent();
			
			}
		
			this.reverseButton = new Element('a', {'href': 'javascript:void(0)', 'class': 'leftSliderNav sliderNav pngIE'}).update('zurück');
			this.forwardButton = new Element('a', {'href': 'javascript:void(0)', 'class': 'rightSliderNav sliderNav pngIE'}).update('vor');
			
			this.wrapper.appendChild(this.reverseButton);
			this.wrapper.appendChild(this.forwardButton);
		
			this.reverse = this.reverse.bindAsEventListener(this);
			this.forward = this.forward.bindAsEventListener(this);
		
			Event.observe(this.reverseButton, 'click', this.reverse);
			Event.observe(this.forwardButton, 'click', this.forward);
		}
		
	},
	reverse:function(event)
	{
		Event.stopObserving(this.reverseButton, 'click', this.reverse);
		
		fx = new Effect.Move(this.sliderGroup, {
			x: this.slideWidth, 
			mode: 'relative', 
			duration: 0.5, 
			beforeStart:function() {
				this.sliderGroup.style.left = "-" + this.slideWidth + "px";
				Element.insert(this.sliderGroup, {top: $$('#' + this.sliderGroup.id + ' li')[this.counter - 1]});
			}.bind(this),
			afterFinish:function() {
				Event.observe(this.reverseButton, 'click', this.reverse);
			}.bind(this)
		});
	},
	forward:function(event)
	{
		Event.stopObserving(this.forwardButton, 'click', this.forward);
		
		fx = new Effect.Move(this.sliderGroup, {
			x: -this.slideWidth,
			mode: 'absolute', 
			duration: 0.5,
			afterFinish:function() {
				Event.observe(this.forwardButton, 'click', this.forward);
				this.sliderGroup.appendChild($$('#' + this.sliderGroup.id + ' li')[0]);
				this.sliderGroup.style.left = "0px";
			}.bind(this)
		});
	},
	jumpToCurrent:function()
	{
		var flag = false;
		
		this.slides.each(function(elm) {
			if(elm.id.split("_")[1] != elm.className.split("_")[1] && flag === false) {
				this.sliderGroup.appendChild($$('#' + this.sliderGroup.id + ' li')[0]);
			} else {
				flag = true;
			}
		}.bind(this));
	}
});