if (top.location != location) {
    top.location.href = document.location.href ;
}
var MGFX=MGFX||{};
MGFX.Rotater=new Class(
	{
		Implements:[Options,Events],
		options:{
			slideInterval:4000,
			transitionDuration:1000,
			startIndex:0,
			autoplay:true
		},
		initialize:function(B,A){
			this.setOptions(A);
			this.slides=$$(B);
			this.createFx();
			this.showSlide(this.options.startIndex);
			if(this.slides.length<2){
				this.options.autoplay=false
			}
			if(this.options.autoplay){
				this.autoplay()
			}
			return this
		},
		toElement:function(){return this.container},
		createFx:function(){
			if(!this.slideFx){
				this.slideFx=new Fx.Elements(this.slides,{duration:this.options.transitionDuration})}
			this.slides.each(function(A){A.setStyle("opacity",0);
			//console.log('height is '+A.getHeight());
			})},
		showSlide:function(B){
			var A={};
			this.slides.each(function(C,D){
				if(D==B&&D!=this.currentSlide){A[D.toString()]={opacity:1};
				//console.log('IMPORTANT. We need to set up new height for .relative in this CASE. Height is: '+C.getHeight());
//				$$('.relative').setStyle('height',C.getHeight());
				}
				else{A[D.toString()]={opacity:0}}},this);
			this.fireEvent("onShowSlide",B);
			this.currentSlide=B;
			this.slideFx.start(A);
			return this
		},
		autoplay:function(){
			this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);
			this.fireEvent("onAutoPlay");
			return this
		},
		stop:function(){
			$clear(this.slideshowInt);
			this.fireEvent("onStop");
			return this},
		rotate:function(){
			current=this.currentSlide;
			next=(current+1>=this.slides.length)?0:current+1;
			this.showSlide(next);
			this.fireEvent("onRotate",next);
			return this
		}
});
var MGFX=MGFX||{};
MGFX.Tabs=new Class({
	Extends:MGFX.Rotater,options:{
		slideInterval:6000,
		transitionDuration:300,
		autoplay:false},
		initialize:function(B,C,A){
			this.tabs=$$(B+" li");
			this.tabsA=$$(B+" a");
			this.createTabs();
			this.parent(C,A);
			return this
		},
		createTabs:function(){
			this.tabsA.each(function(B,A){
				B.addEvent("click",function(C){
					//variable = B.getStyle();
					if (B.hasClass('current')) {
						//console.log("fucken bingo");
					}
					else
					{
					//console.log('i like A:'+A+'and B:'+B+'and C:'+C+'and this'+this); //+'and variable:'+variable
					C.stop();
					this.showSlide(A);
					this.stop()}}.bind(this))}.bind(this))
		},
		activateTab:function(A){
			this.tabs.removeClass("current");
			this.tabsA.removeClass("current");
			this.tabs[A].addClass("current");
			this.tabsA[A].addClass("current")
		},
		showSlide:function(A){
			this.activateTab(A);
			this.parent(A);
			return this
		}
});
var mooquee = new Class({
    initialize: function(element, options) {
		this.setOptions({
			marHeight: 15,
			marWidth: 495,
			steps: 1,
			speed: 2,
			direction: 'left',
			pauseOnOver: true
	    }, options);
	    this.timer = null;
	    this.textElement = null;
	    this.mooqueeElement = element;
	    this.constructMooquee();
	},
	constructMooquee: function() {
		var el = this.mooqueeElement;
		el.setStyles({
		    'width' : this.options.marWidth
		    ,'height' : this.options.marHeight		    
		});
        this.textElement = new Element('div',{
		    'class' : 'mooquee-text'
		    ,'id' : 'mooquee-text'
		}).set('html', el.innerHTML);
		el.set('html', '');//clear mooqueeElement inner html
		this.textElement.inject(el);
		//this.textElement = $('mooquee-text');
        if(!this.setStartPos()){return;}
        if(this.options.pauseOnOver){this.addMouseEvents();}
		//start marquee
		this.timer = this.startMooquee.delay(this.options.speed, this);
	},
	setStartPos: function(){
	    /* sod.hu Ext */
		if( this.options.direction == 'bottom' )
            this.textElement.setStyle('bottom', ( -1 * this.textElement.getCoordinates().height.toInt()));
        else if( this.options.direction == 'top' )
            this.textElement.setStyle( 'bottom', this.options.marHeight );
        else if( this.options.direction == 'left' )
            this.textElement.setStyle('left', ( -1 * this.textElement.getCoordinates().width.toInt()));
        else if( this.options.direction == 'right' )
            this.textElement.setStyle( 'left', this.options.marWidth );
        else{
            alert( 'direction config error: ' + this.options.direction );
            return false;
        }
        return true;
	},
	addMouseEvents : function(){
	    this.textElement.addEvents({
	        'mouseenter' : function(me){
	            this.clearTimer();
	        }.bind(this),
	        'mouseleave' : function(me){
	            this.timer = this.startMooquee.delay(this.options.speed, this);
	        }.bind(this)
	    });
	},
    startMooquee: function(){
        /* sod.hu Ext */
        if(this.options.direction == 'bottom' || this.options.direction == 'top')
            var pos = this.textElement.getStyle('bottom').toInt();
        else if(this.options.direction == 'left' || this.options.direction == 'right')
            var pos = this.textElement.getStyle('left').toInt();
        if(this.options.direction == 'bottom')
            this.textElement.setStyle( 'bottom', ( pos + -1 ) + 'px' );
        else if(this.options.direction == 'top')
            this.textElement.setStyle( 'bottom', ( pos + 1 ) + 'px' );
        else if(this.options.direction == 'left'){
            this.textElement.setStyle( 'left', ( pos + -1 ) + 'px' );
        }
        else if(this.options.direction == 'right')
            this.textElement.setStyle( 'left', ( pos + 1 ) + 'px' );
        /* sod.hu Ext end */
        this.checkEnd(pos);
        this.timer = this.startMooquee.delay(this.options.speed, this);
    },
    resumeMooquee: function(){
        this.stopMooquee();
        if(this.options.pauseOnOver){this.addMouseEvents();}
        this.timer = this.startMooquee.delay(this.options.speed, this);
    },
    stopMooquee: function(){
        this.clearTimer();
        this.textElement.removeEvents();
    },
    clearTimer: function(){
        $clear(this.timer);
    },
    checkEnd: function(pos){
        /* sod.hu Ext */
        if(this.options.direction == 'bottom'){
            if(pos < -1 * (this.textElement.getCoordinates().height.toInt()))
                this.textElement.setStyle('bottom', this.options.marHeight);
        } else if(this.options.direction == 'top'){
            if(pos > this.options.marHeight.toInt())
                this.textElement.setStyle('bottom', -1 * (this.textElement.getCoordinates().height.toInt()) );
        } else if(this.options.direction == 'left'){
            if(pos < -1 * (this.textElement.getCoordinates().width.toInt()))
                this.textElement.setStyle('left', this.options.marWidth);
        } else if(this.options.direction == 'right'){
            if(pos > this.options.marWidth.toInt())
                this.textElement.setStyle('left', -1 * (this.textElement.getCoordinates().width.toInt()) );
        }
        /* sod.hu Ext end */
    },
    setDirection: function(dir){
        this.options.direction = dir;
        this.setStartPos();
    }
    
});
mooquee.implement(new Options);
/*
window.addEvent('domready',function() {
	var tabs = new MGFX.Tabs('.tabs','.content',{
		autoplay: true,
		transitionDuration:500,
		slideInterval:6000
	});
});
*/
function rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // +   bugfixed by: Onno Marsman
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
    var argc = arguments.length;
    if (argc == 0) {
        min = 0;
        max = 2147483647;
    } else if (argc == 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
window.addEvent('domready',function(e){
	var rand2s = rand(0,3);
	if($$('.index_tab').length > 0) {
	MGFX.tabs = new MGFX.Tabs(
		'.index_tab',
		'.feature',
		{
		autoplay: true,
		slideInterval:6000, //6 secs 
		transitionDuration:850,
		startIndex: 0
		});
		//alert("stupid msie");
	}
		//console.log("is it working?");
//	if($('rotater-demo')) MGFX.rotater = new MGFX.Rotater('.slide');
if($('marguee')){
var obj;
obj = new mooquee($('marguee'));
}
});


/*
old Slide, removed by bibi request :(

var noobSlide = new Class({

	initialize: function(params){
		this.items = params.items;
		this.mode = params.mode || 'horizontal';
		this.modes = {horizontal:['left','width'], vertical:['top','height']};
		this.size = params.size || 639;
		this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
		this.button_event = params.button_event || 'click';
		this.handle_event = params.handle_event || 'click';
		this.onWalk = params.onWalk || null;
		this.currentIndex = null;
		this.previousIndex = null;
		this.nextIndex = null;
		this.interval = params.interval || 600000;
		this.autoPlay = params.autoPlay || true;
		this._play = null;
		this.handles = params.handles || null;
		if(this.handles){
			this.addHandleButtons(this.handles);
		}
		this.buttons = {
			previous: [],
			next: [],
			play: [],
			playback: [],
			stop: []
		};
		if(params.addButtons){
			for(var action in params.addButtons){
				this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
			}
		}
		this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:1000000,wait:false}),{property:this.modes[this.mode][0]}));
		this.walk((params.startItem||0),true,true);
	},

	addHandleButtons: function(handles){
		for(var i=0;i<handles.length;i++){
			handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
		}
	},

	addActionButtons: function(action,buttons){
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
				case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
				case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
				case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
				case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
			}
			this.buttons[action].push(buttons[i]);
		}
	},

	previous: function(manual){
		this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),manual);
	},

	next: function(manual){
		this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),manual);
	},

	play: function(interval,direction,wait){
		this.stop();
		if(!wait){
			this[direction](false);
		}
		this._play = this[direction].periodical(interval,this,[false]);
	},

	stop: function(){
		$clear(this._play);
	},

	walk: function(item,manual,noFx){
		if(item!=this.currentIndex){
			this.currentIndex=item;
			this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
			this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
			if(manual){
				this.stop();
			}
			if(noFx){
				this.fx.cancel().set((this.size*-this.currentIndex)+'px');
			}else{
				this.fx.start(this.size*-this.currentIndex);
			}
			if(manual && this.autoPlay){
				this.play(this.interval,'next',true);
			}
			if(this.onWalk){
				this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
			}
		}
	}
	
});

if (Browser.Engine.trident4) var size = 640;
else { var size = 639; }
window.addEvent('domready', function() { 
	var handles8_more = $$('.select a');
	var nS2 = new noobSlide({
			box: $('box2'),
			items: $$(('.select a')), //[0,1,2,3], // $$(('.select a')),
			interval: 9000,
			size: size,
			fxOptions: {
				duration: 1000,
				transition: Fx.Transitions.Quart.easeOut,
				wait: false
			},
			//addButtons: {play: $('play8') },

			onWalk: function(currentItem,currentHandle){
				//style for handles
				$$(this.handles,handles8_more).removeClass('current');
				$$(currentHandle,handles8_more[this.currentIndex]).addClass('current');
				//text for "previous" and "next" default buttons
				//$('prev8').set('html','&lt;&lt; '+this.items[this.previousIndex].innerHTML);
				//$('next8').set('html',this.items[this.nextIndex].innerHTML+' &gt;&gt;');
			}
		});
	nS2.addHandleButtons(handles8_more); 
});

*/
