/*MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006-2007 Valerio Proietti, <http://mad4milk.net>, MIT Style License.||CNET Libraries Copyright (c) 2006-2008, http://clientside.cnet.com/wiki/cnet-libraries#license*/
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 || 240;
		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 || 7000;
		this.autoPlay = params.autoPlay || false;
		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:500,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));
			}
		}
	}
	
});
var PESSwiff = new Class({
	Extends: Swiff,
	initialize: function(file, path) {
		if(!path) path = 'http://78.151.130.107/dev/flash/mediaplayer.swf';
		var options = {
			'width': '529px',
			'height': '404px',
			'container': $('videoContainer'),
			'params': {
				allowFullScreen: true,
				allowScriptAccess: true
			},
			'vars': {
				image: false,
				searchbar: 'false',
				screencolor: '0x000000',
				logo: 'false',
				overstretch: 'false',
				showeq: 'false',
				showicons: 'true',
				shownavigation: 'true',
				showstop: 'false',
				showdigits: 'true',
				showdownload: 'false',
				usefullscreen: 'true',
				autoscroll: 'false',
				displayheight: '384', // 20px less than the height
				thumbsinplaylist: 'true',
				autostart: 'true',
				bufferlength: '3',
				repeat: 'false',
				rotatetime: '5',
				shuffle: 'false',
				smoothing: 'true',
				volume: '80',
				enablejs: 'true',
				linkfromdisplay: 'false',
				linktarget: '_self',
				searchlink: 'http://google.com/?q='
			}
		};
		options.vars.file = file;
		this.parent(path, options);
	}
});
// Thanks http://gregorytomlinson.com/encoded/2009/01/10/mootools-automated-external-links-class/
var ExternaliseLinks = new Class({
	Implements: [Options, Events],
	options: {
		currentServer : '', // override use of document.location.host
		extLnkClass : '',
		autoRun : true,
		onComplete : $empty // Event
	},
	initialize: function(options) {
		this.setOptions(options);
		if(this.options.autoRun) this.run();
	},
	run: function() {
		var b = $$('body')[0], lnks = b.getElements('a'), s = this.setServer();
		lnks.each(function(item) {
			this.setLink(item, s);
		}, this);
 
		this.fireEvent('complete', {"statusText":"ok", options: this.options});
		return true;
	},
	setServer: function() {
		var s = (this.options.currentServer !== '') ? this.options.currentServer : document.location.host;
		return {
			getServer : function() { return s; }
		}
	},
	setLink: function(el, server) {
		var h = el.get('href');
		if(h.indexOf('http') >= 0 && h.indexOf(server.getServer()) < 0) {
			el.set('target', '_blank');
			if(this.options.extLnkClass !== '') el.set('class', this.options.extLnkClass)
		}					
		return el;
	}
});