function modifyMenu(){
	var els = $$('#header a');
	els.each(function(el){
		el.addEvents({
			focus: function(event){
				if(this.blur)this.blur();
			}
		});
	});
}
function replaceFlashImage(){
	var els = $$('.flash');
	els.each(function(el){
		var img = el.getElement('img');
		var img_src = img.src;
		var container = img.getParent();
		container.setStyles({
			width:img.width,
			height:img.height
		});
		//var path = img_src.substring(0, img_src.lastIndexOf('.'))+".swf";
		var path = getPath(img_src)+getName(img_src)+".swf";
		replaceFlash(container, path, img.width, img.height);
	});
}
function replaceVideoImage(){
	var els = $$('.video');
	els.each(function(el){
		var img = el.getElement('img');
		var a = el.getElement('a');
		a.removeProperty('onclick');
		a.addEvents({
			click: function(event){
				event.stop();
				this.blur();
			}
		});
		var img_src = img.src;
		var container = img.getParent();
		container.setStyles({
			width:img.width,
			height:img.height
		});
		//var path = img_src.substring(0, img_src.lastIndexOf('.'))+".swf";
		var path = getPath(img_src)+getName(img_src);
		replaceVideo(container, img_src, path+".f4v", img.width, img.height);
	});
}
function replaceFlash(el, swf, w, h, id){
	var obj = new Swiff(swf, {
		id: id,
		width: w,
		height: h,
		params: {
			wmode: 'opaque',
			bgcolor: '#FFFFFF',
			allowFullScreen: "true",
			allowScriptAccess: "always",
			swLiveConnect: "true"
		},
		properties: {
			name: "testName",
			bgcolor: "#FFFFFF"
		},
		container: el
	});	
}
function replaceVideo(container, image, video, width, height, autoplay) {
	if(!autoplay){
		autoplay = "false";
	}else{
		autoplay = "true";
	}
	var obj = new Swiff('plugins/mediabox/NonverBlaster.swf', {
		/*id: 'nonverblaster',*/
		width: width,
		height: height,
		params: {
			wmode: 'opaque',
			bgcolor: '#000000',
			allowFullScreen: "true",
			allowScriptAccess: "always",
			swLiveConnect: "true"
		},
		vars: {
			mediaURL: video,
			teaserURL: image,
			indentImageURL: "",
			autoPlay: autoplay,
			loop: "false",
			controlsEnabled: "true",
			controlColor: "ffffff",
			controlBackColor: "000000",
			showTimecode: "true",
			buffer: "",
			scaleIfFullScreen: "false",
			defaultVolume: "100",
			allowSmoothing: "true",
			showScalingButton: "true",
			crop: "false"
		},
		container: container
	});
}
//-----------------------------------------------
function getPath(path) {
	return path.substring(0, path.lastIndexOf('/'))+"/";
}
function getName(path) {
	return path.substring(path.lastIndexOf('/')+1, path.lastIndexOf('.'));
}
//-----------------------------------------------
window.addEvent('domready', function(){
	modifyMenu();
	if (Browser.Plugins.Flash.version > 9){
		replaceFlashImage();
		replaceVideoImage();
	}
});
