/**
 * @author Riccardo Canalicchio
 */
function selectTeam(id){
	new Effect.ScrollTo('menu-left');  
}
var Scroller = Class.create({
	initialize: function(name){
		this.scroller_container = $(name);
		this.scroller = this.scroller_container.select('#scroller').first();
		this.scroller_width = this.scroller_container.getWidth();
		this.loop();
	},
	loop: function(){		
		this.scroller.setStyle({'left': this.scroller_width + 'px'});

			new Effect.Morph(this.scroller, {
				style: "left: "+ (-1)*this.scroller.getWidth() + "px",
				transition: Effect.Transitions.linear,
				duration: 10,
				afterFinish: this.loop.bind(this)
			});
	}

});

var Flag = Class.create({
    initialize: function(element){
		this.buttonelement = $(element);
        this.buttonelement.observe('click', this.clickhandler.bind(this));
        this.contentElement = $(element).next('.flag');
		this.initWidth = this.contentElement.getWidth();
        this.contentElement.setStyle({
            width: '0px'
        });
        this.opened = false;
    },
    clickhandler: function(event){
        if (!this.opened) {
            this.open();
        }
    },
    open: function(){
		this.flags.closeall();
		this.buttonelement.setStyle('background-position: '+ this.buttonelement.getWidth()+ 'px');
		new Effect.Morph(this.contentElement, {
			style: {
				width: this.initWidth + 'px'
			},
			transition: Effect.Transitions.sinoidal
		});

        this.opened = true;
    },
    close: function(){
		if (this.opened) {
			this.buttonelement.setStyle('background-position: 0px');			
			new Effect.Morph(this.contentElement, {
				style: {
					width: '0px'
				},
				transition: Effect.Transitions.sinoidal
			});
			this.opened = false;
		}
    },
	setFlags: function(f){
		this.flags = f;
	}
});
var Flags = Class.create({
	initialize:function(classname){
		this.classname = classname;
		this.flags = new Array();
		$$(classname).each(function(flag){
			flag = new Flag(flag);
			flag.setFlags(this);
			this.flags.push(flag);
		}.bind(this));
		if(this.flags.first())
			this.flags.first().open();
	},
	closeall: function(){
		this.flags.each(function(flag){
			flag.close();
		});
	}
});


Event.observe(window, 'load', function() {
	if($('article')){
		if($('article').getHeight()<800)
			$('article').setStyle('height:800px;');
	}
	if($('article2')){
		if($('article2').getHeight()<800)
			$('article2').setStyle('height:800px;');
	}

});

function CSS3(selector, style){
	$$(selector).each(function(element) {
			element.setStyle(style);
	});
}
