/*
	Main banner rotator
*/
var Rotator = new Class({

	// properties
	elems: new Array,
	navlinks: new Array,
	timer: new Object,
	position: new Number,
	delay: 5000,
	delayAfterClick: 25000,
	
	
	// method poses teaser to an aimed state
	goto: function(to){
		this.position = to;
		this.elems.fade('hide');
		this.elems[to-1].fade('in');
		this.navlinks.removeClass('this');
		this.navlinks[to-1].addClass('this');
		return this;
	},
	
	
	// method shifts teaser to next position
	step: function(){
		var next = (this.position >= this.navlinks.length) ? 1 : this.position+1;
		this.goto(next);
	},


	// method starts shifting
	start: function(){
		this.timer = this.step.periodical(this.delay, this);
	},


	// method stops shifting
	stop: function(){
		clearInterval(this.timer);
	},


	// constructor
	initialize: function(elems, navlinks){
		var _this_ = this;

		this.elems = elems;
		this.navlinks = navlinks;

		this.elems
			.fade('hide')
			.setStyle('display', 'block');

		this.navlinks.addEvent('click', function(){
			_this_.goto(_this_.navlinks.indexOf(this).toInt()+1);
			_this_.stop();
			//_this_.start.delay(_this_.delayAfterClick, _this_);
			return false;
		});
		this.goto(1);
		return this.start();
	}
});



window.addEvent('domready', function(){
	
	// release rotator
	try {
		new Rotator($$('#canvas a img'), $$('#canvas nav a'));
	} catch(e) {}

	// milkbox init
	try {
		new Milkbox({
			overlayOpacity: 0.8
		});
	} catch(e){}


	// print links
		try {
			$$('a[rel=print]').addEvent('click', function(){
				Document.print('body');
				return false;
			});
		} catch(e){}

		
	/*
		Faq
	*/
	try {
		$$('#faq .faq-list dl.accordion dt, #menu dl.accordion dt, #system-links dl.accordion dt, #director-index .i dl.accordion dt').addEvent('click', function(){
			this.getNext().toggleClass('open');
			return false;
		});
	} catch(e){}
	
	try {
		$$('#system-link dl.accordion dd').makeResizable({modifiers: {x: false, y: 'height'},limit: {y: [50, 150]}
	});
	} catch(e){}
	
	/*
	 	Realese Tabs
	*/
		try {
			$$('dl.sys-tabs').each(function(i){
				i.getElements('dt').addEvents({
				'mouseover': function(){
					this.addClass('hover');
					return false;
					},
				'mouseout': function(){
					this.removeClass('hover');
					return false;
					},
			'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){} 
			
			
	// subscribe form buttons fix
	try {
		var buttonElements = $$('#article_subscribe-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){} 
	
	// milkbox init
	try {
		new Milkbox({
			overlayOpacity: 0.8
		});
	} catch(e){}

    try {
    new Exm;
    } catch(e){}
    
});
