/*
	Arterium Teaser
*/
var Banners = new Class({

	// constructor
	initialize: function(wrapper, prevButton, nextButton){

		// init properties
		this.items = wrapper.getElements('img').length;
		//this.step = wrapper.getElements('img')[0].getSize().x + 20;
		this.step = 257 + 20;
		this.cursor = 1;
		this.fx = new Fx.Tween(wrapper, {
			fps: 60,
			unit: 'px',
			duration: 300,
			link: 'chain',
			transition: Fx.Transitions.Circ.easeOut
		});

		// init button events
		try {
			prevButton.addEvent('click', this.prev.bind(this));
			nextButton.addEvent('click', this.next.bind(this));
		} catch(e) {
			return this;
		}
		return this;
	},

	// method slides ribbon to previous position
	prev: function(){
		if (this.cursor > 1) {
			this.cursor--;
		} else {
			this.cursor = (this.items-1);
		}
		this.fx.start('margin-left', -(this.cursor-1)*this.step);
		
		return false;
	},

	// method slides ribbon to next position
	next: function(){
		if (this.cursor < (this.items-1) ) {
			this.cursor++;
		} else {
			this.cursor = 1;
		}
		this.fx.start('margin-left', -(this.cursor-1)*this.step);
		
		return false;
	}
});









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



	// run markup hacks
	new Exm();



	// release Teaser for banners on home
	try {
		if ($('banners')) {
			new Banners($('banners-wrapper'), $('banners-prev'), $('banners-next') );
		}
	} catch(e) {}



	// print links
	try {
		$$('a[rel=print]').addEvent('click', function(){
			Document.print('body');
			return false;
		});
	} catch(e){}



	// milkbox init
	try {
		new Milkbox({
			overlayOpacity: 0.8
		});
	} catch(e){}



	// tabs 
	try {
		$$('dl.sys-tabs').each(function(i){
			i.getElements('dt').addEvents({
				'click': function(){
					if(this.getNext().get('tag')=='dd') {
						this.getParent('dl').getElements('dt, dd').removeClass('this');
	
						this.addClass('this');
						this.getNext().addClass('this');
					}
					return false;
				}
			});
		});
	} catch(e){}



	// offset for nav2models menu
	try {
		$$('#nav2models > div > div').each(function(item){
			var itemWidth = 440;
			var root = item.getParent('div').getParent('nav');
			var rootWidth = root.getSize().x.toInt();
			var parentItemX = item.getParent('div').getPosition(root).x.toInt();
			if (parentItemX + itemWidth > rootWidth ) {
				item.setStyle('left', rootWidth - (parentItemX + itemWidth) + 'px');
			}
		});
	} catch(e){}


	// release BUTTON as LINKS
	try {
	$$('button.ui-link').addEvent('click', function(){
	window.location.href = this.get('name');
	return false;
	});
	} catch(e){}
	
	// subscribe form buttons fix
	try {
		var buttonElements = $$('#article_subscribe button[type="submit"]');
		buttonElements.each(function(e){
			e.addEvent('click' , function(){
				$('article_subscribe_mode').set('value', e.get('val'))
				this.getParent('form').submit();
			});
		});
	} catch(e){}


});
