// JavaScript Document
var lastPath;
function addEvents(flashPlugin){
	var els = $$('#videos .preview .image_container');
	els.each(function(el){
    	//el.setStyle('color', 'red');
		var a = el.getFirst('a');
		var img = a.getFirst('img');
		var path = getPath(img.src)+getNamePart(getName(img.src));
		el.setStyle('background','url('+path+'_thumb.jpg) no-repeat top left');
		a.addEvents({
			mouseenter: function(){
				img.morph({
					opacity: 0.1
				});   
			},
			 mouseleave: function(){
				//Morphes back to the original style
				img.morph({
					opacity: 1
				});
			}
		});
		if(flashPlugin){
			a.removeProperty('onclick');
			a.addEvents({
				click: function(event){
					event.stop();
					switchVideo(this);
					this.blur();
				}
	
			});
		}
	});
}
function switchVideo(a) {
	el = a.getParent();
	var img = a.getFirst('img');
	var path = getPath(img.src)+getNamePart(getName(img.src));
	el.setStyle('background','url('+lastPath+'_thumb.jpg) no-repeat top left');
	img.setProperty('src', lastPath+'_thumb.gif');
	lastPath = path;
	//replaceVideo(lastPath);
	replaceVideo($('player'), lastPath+"_video.jpg", lastPath+"_video.f4v", 640, 360);
}
function getNamePart(name) {
	return name.substring(0, name.lastIndexOf('_'));
}
function modifyNews(){
	var els = $$('#right .mod_newslist .layout_latest');
	var pos = 0;
	els.each(function(el){
		el.addClass('pos'+pos);
		pos++;
	});
}
//-----------------------------------------------
window.addEvent('domready', function(){
	if (Browser.Plugins.Flash.version > 9){
		var el = $$('#player .image_container a img');
		if(el.length){
			img = el[0];
			lastPath = getPath(img.src)+getNamePart(getName(img.src));
			addEvents(true);
			replaceVideo($('player'), lastPath+"_video.jpg", lastPath+"_video.f4v", 640, 360);
		}
	}else{
		addEvents();
	}
	modifyNews();
});
