/*
$.video = {
	init: function() {
		for (module in $.video) {
			if ($.video[module].init)
				$.video[module].init();
		}
	}
};
$(document).ready($.video.init);

*/
$.video = {

	init: function() {
		$('.video_everybody')
			.each(this.preload)
			.bind('click', this.click);
	},

	preload: function() {
		var name_poster = $(this).attr('poster');
		var name_3gp = $(this).attr('poster').replace(/.jpg/,'.3gp');
		var name_m4v = $(this).attr('poster').replace(/.jpg/,'.m4v');
		var name_ogg = $(this).attr('poster').replace(/.jpg/,'.ogv');
//		var c = $(this).attr('controls');
		var w = $(this).attr('width');
		var h = $(this).attr('height');
		var c = $(this).attr('controls');
		var a = $(this).attr('autoplay');
		var id = $(this).attr('id');
		if(!$.browser.safari){
			if($.browser.msie){
				c=(c==undefined)?false:true;
				a=(a==undefined)?false:true;
			}else{
				c=(c)?true:false;
				a=(a)?true:false;
			}
			$(this).before('<div class="'+id+'"></div>');
	    var params = {wmode:"transparent",allowfullscreen:"true",allowscriptaccess:"always"};
	    var flashvars = {file:name_m4v,image:name_poster,width:w,height:h,controls:c,autoplay:a};
//	    alert(name_m4v+":"+name_poster+":"+w+":"+h+":"+c+":"+a);
	    var nowDate = new Date();
	    swfobject.embedSWF("/assets/apps/player.swf?"+nowDate.getTime(), id, w, h, "9.0.0", "/assets/apps/expressInstall.swf", flashvars, params);
		}else{
//			if(!$(this).find('#play_'+id).length){
//				$(this).insertBefore('<div style="display:block;position:absolute;width:'+w+'px;height:'+h+'px;background: transparent url(/assets/images/player.png) 50% 50% no-repeat;"></div>');
//			}
//			$(document).find('#play_'+id).bind('click', this.click);
//			$(document).find('#play_'+id)).click(console.log("!!"));
//			$(this).
//			alert(name_m4v);
/*
			$(this).append('<source src="'+name_m4v+'" type="video/mp4" />');
			$(this).append('<source src="'+name_ogg+'" type="video/ogg" codec="theora, vorbis" />');
			$(this).append('<source src="'+name_3gp+'" type="video/3gpp"" />');
*/
/*
			this.addEventListener('ended', function(){
			  this.play();
			});
*/
		}
	},
	click: function() {
		if($.browser.safari){
			if(this.paused){
				if(!$(this).find('source').length){
					var name_poster = $(this).attr('poster');
					var name_3gp = $(this).attr('poster').replace(/.jpg/,'.3gp');
					var name_m4v = $(this).attr('poster').replace(/.jpg/,'.m4v');
					var name_ogg = $(this).attr('poster').replace(/.jpg/,'.ogv');
					$(this).append('<source src="'+name_m4v+'" type="video/mp4" />');
					$(this).append('<source src="'+name_ogg+'" type="video/ogg" codec="theora, vorbis" />');
					$(this).append('<source src="'+name_3gp+'" type="video/3gpp"" />');
				}
			  this.play();
			}else{
			  this.pause();
			}
			this.addEventListener('ended', function(){
			});
		}
	}
};

function videoClick(id) {
	alert(id);
}
