/**
 * 動画プレイヤー埋め込み用Utility
 */
var tgMovieUtil = {
	
	embedMoviePlayerByID : function( id, width, height, options, loop ){
		
		if ( !this.$xmlData ) {
			
			if ( loop ) return;
			
			$.get(this.xmlURL, null, function(data){
				
				tgMovieUtil.$xmlData = $(data);
				tgMovieUtil.embedMoviePlayerByID( id, width, height, options, true );
				
			});
		}
		else {
			if ( !id ) {
				id = $("movie:eq(0)", this.$xmlData).attr("id");
			}
			$("#" + id, this.$xmlData).each(function(){
				var op = tgMovieUtil.xmlToOptionData(this);
				tgMovieUtil.embedMoviePlayer(width, height, $.extend({}, options, op));
			});
		}
	},
	
	embedMoviePlayer : function( width, height, options, targetID ){
		
		var tg = ( targetID ) ? targetID : this.targetID;
		var w = ( width ) ? width : 272;
		var h = ( height ) ? height : 152;
		
		var op = $.extend( {}, this.options, options );
		
		swfobject.embedSWF( this.swf, tg, w, h, this.version, "/common/swf/expressInstall.swf", op, this.params, this.attr );
	},
	
	loadMovieXML : function( func ) {
		
		$.get(this.xmlURL, null, function(data){
			tgMovieUtil.$xmlData = $(data);
			func();
		});
	},
	
	//xmlToOptionData
	xmlToOptionData : function( xml ) {
		
		var op = {};
		
		var flv = $("flv",xml).text();
		var thmb = $("thmb",xml).text();
		var comment = $("comment",xml).text();
		var date = $(xml).attr("date");
		
		if ( flv ) op.flvFile = flv;
		if ( thmb ) op.thmb = thmb;
		if ( comment ) {
			if ( date )	op.comment = "【" + date + "】 " + comment;
			else		op.comment = comment;
		}
		
		this.nowMovieData = op;
		
		return op;
	},
	
	//movie data cache
	nowMovieData : {},
	
	//xml data cache
	$xmlData : "",
	
	//XML file URL
	xmlURL : "/video/xml/moviedata.xml",
	
	//default target id
	targetID : "tg_movieplayer",
	
	//movieplayer file URL
	swf : "/common/swf/tgMoviePlayer.swf",
	
	//target version
	version : "9",
	
	//default params
	params : {
		menu: "false",
		wmode: "opaque",
		allowFullScreen: "true"
	},
	
	//default attributes
	attr : {
		bgcolor : "#000000"
	},
	
	//default movie option
	options : {
		autoPlay: "false",
		fullScreen: "true",
		toolbar: "false"
	}
	
}

