/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var Video = {
    videoSelect : null,
    videoObj : null,
	filename : null,
    init: function(videoSelectionId, feature){
		EventHandler.attachEvent(videoSelectionId,'onchange','Video.changeVideo');
		Video.videoSelect = $(videoSelectionId);
		Video.videoObj = feature;
    },
    changeVideo: function(){
		$('flash-wrapper').innerHTML = '';
		var fileName = Video.videoSelect.options[Video.videoSelect.selectedIndex].value;
		var feature = new SWFObject("/flash_flv_player/player.swf", "flashcontent", 208, 136, "6", "#000", true);
		//feature.addParam("flashvars", "&controlbar=none");
		feature.addParam("allowfullscreen","true");
		feature.addVariable("file", "/media/Video/" + fileName + '__150.flv');
		feature.addVariable("autostart", "flase");
		feature.write("flash-wrapper");
    },
	frontEndInit : function(fileName) {
		Video.fileName = fileName;
		$$('div.home-page img, div.home-page a').each(function(item) {
			$(item).addEvent('click', function() {
				Video.frontEndVideo();
			});
		});
		$('video-close').addEvent('click',Video.frontEndCloseVideo);
	},
	frontEndVideo : function() {
		$('video-placeholder-internal').innerHTML = '';
		$('screenOverlay').setStyle('display','block');
		$('screenOverlay').setStyle('width','100%');
		var size = window.getSize();
		var pos = window.getScroll();

		$('screenOverlay').setStyle('width',size.x+'px');
		$('screenOverlay').setStyle('height',size.y+'px');
		$('screenOverlay').setStyle('left',pos.x+'px');
		$('screenOverlay').setStyle('top',pos.y+'px');

		$('video-placeholder').setStyle('position','absolute');
		$('video-placeholder').setStyle('left',(pos.x+(size.x-565)/2)+'px');
		$('video-placeholder').setStyle('top',(pos.y+(size.y-335)/2)+'px');
		$('video-placeholder').setStyle('display','block');
		
		$('video-close').setStyle('left',(pos.x+(size.x-565)/2+553)+'px');
		$('video-close').setStyle('top',(pos.y+(size.y-335)/2+2)+'px');
		$('video-close').setStyle('display','block');

		var myDate = new Date();
		var himage = new Image();
		var startTime = myDate.getTime();
		himage.src = '/func/Content.image/' + startTime + '.jpg';

		var speed = "__150.flv";
		himage.onload = function(){
			var myDate = new Date();
			var endTime = myDate.getTime();

			var diffTimeSeconds = (endTime - startTime)/1000;
			var kbits = (87137*8)/1024;
			throughput = (kbits/(diffTimeSeconds));
			throughput = Math.round(throughput * (93/100));


			if (throughput >= 700 ) {
				speed = "__700.flv";
			} else if (throughput >= 350 ) {
				speed = "__350.flv";
			} else if (throughput >= 250 ) {
				speed = "__250.flv";
			} else if (throughput >= 150 ) {
				speed = "__150.flv";
			}
		}
		himage.onload();
		var feature = new SWFObject("/flash_flv_player/player.swf", "flashcontent", 565, 335, "6", "#000", true);
		//feature.addParam("flashvars", "&controlbar=none");
		feature.addParam("allowfullscreen","true");
		feature.addVariable("file", "/media/Video/" + Video.fileName + speed);
		feature.addVariable("autostart", "true");
		feature.write("video-placeholder-internal");
	},
	frontEndCloseVideo : function() {
		$('video-placeholder').setStyle('display','none');
		$('video-placeholder-internal').innerHTML = '';
		$('screenOverlay').setStyle('display','none');
		$('video-close').setStyle('display','none');
	}
}
