Array.prototype.inArray = function(value) {
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
    for (var i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
}
//Element.extend({
//	log:function(msg){
//		console.log("%s: %o", msg, this);
//    	return this;
//	}
//});

function mail(who, domain) {
	window.location.href='mailto:' + who + '@' + domain;
	return false;
}

function open_window(url, plat, augst, scroll) {
	var l = 16, t = 16;
	var props = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + (scroll ? "1" : "0") + ",resizable=1,copyhistory=0,";
	props += "width=" + plat + ",height=" + augst;
	if (window.screen && window.screen.availWidth) {
		l = Math.floor(((screen.availWidth - plat)/2) + 5);
		t = Math.floor((screen.availHeight - augst)/2);
		if (l < 0) l = 0;
		if (t < 0) t = 0;
		props += ",left=" + l + ",top=" + t;
	}
	window.open(url, 'win', props);
	return false;
}

var MartinisMenu = new Class({
	options: {
		slider: false,
		container: false,
		prev: false,
		next: false
	},
	
    initialize: function(options){
        this.setOptions(options);
        
        this.slider = $(this.options.slider);
        this.container = $(this.options.container);
		this.prev = $$(this.options.prev);
		this.next = $$(this.options.next);
		
		this.direction;
		this.elementsWidth = 996;
		
		this.slider.scrollTo(0);
		
		this.slideFx = new Fx.Scroll(this.slider, {
			duration: 1000,
			transition: Fx.Transitions.Cubic.easeOut,
			onComplete: function() {
				if (this.direction == 'next') {
					for (i=1; i <= 3; i++) {
						this.container.getFirst().injectInside(this.container);
					}
					this.slider.scrollTo(0);
				}
			}.bind(this)
		});
		
		this.prev.addClass('inactive').addEvent('click', function(e) {
			new Event(e).stop();
		});
		
		this.next.addClass('inactive').addEvent('click', function(e) {
			new Event(e).stop();
		});
		
		window.addEvent('load', function() {
			this.prev.removeClass('inactive').removeEvent('click').addEvent('click', function(e) {
				new Event(e).stop();
				this.slideTo('prev');
				$clear(this.autoSlide);
			}.bind(this));
			
			this.next.removeClass('inactive').removeEvent('click').addEvent('click', function(e) {
				new Event(e).stop();
				this.slideTo('next');
				$clear(this.autoSlide);
			}.bind(this));
			
			this.autoSlide = this.slideTo.periodical(8000, this, 'next');
		}.bind(this));
    },

	slideTo: function(direction) {
		this.direction = direction;

		if (this.direction == 'prev') {
			for (i=1; i <= 3; i++) {
				this.container.getLast().injectTop(this.container);
			}
			this.slider.scrollTo(this.elementsWidth);
			this.slideFx.scrollTo(0);
		} else {
			this.slideFx.scrollTo(this.elementsWidth);
		}
	}
});
MartinisMenu.implement(new Options);