dojo.provide("Z2h.Slide.Video");

dojo.require("dojo.fx");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");

dojo.require("Z2h.Slide");

dojo.declare("Z2h.Slide.Video", [Z2h.Slide], {
	templateString: null,
	templatePath: dojo.moduleUrl("Z2h","Slide/templates/Video.html"),
	widgetsInTemplate : true,

	/**
	 * Public variables
	 */
	author_avatar: '',
	author_url: '',
	author_username: '',
	author_level: '',
	author_title: '',
	author_last_online: '',
	comment_author_url: '',
	comment_author_avatar: '',
	comment_author_name: '',
	comment: '',
	comment_id: '',
	video_likes: '',
	video_comments: '',
	video_views: '',
	video_url: '',
	video_title: '',
	video_file: '',
	video_thumb: '/flash/history/history_vid.jpg',

	/**
	 * Private variables
	 */
	_currentlyShown: false,
	_swfPlayer: null,
	_videoPlayerId: '',
	_slideshow: null,
	/**
	 * Methods
	 */

	postCreate: function(){
		this.inherited("postCreate",arguments);
		if ( this.comment == '' ) {
			dojo.style(this.videoTopComment,'display','none');
			dojo.style(this.videoNoComments,'display','block');
		}
	},

	show: function(slideshow){
		this._videoPlayerId = this.videoPlayerContainer.id;
		if ( swfobject.hasFlashPlayerVersion("9.0.0") ){
			var attributes = {
					"name": this._videoPlayerId,
					"id"  : this._videoPlayerId
			};
			var flashvars = {
				"file" : this.video_file[0],
				"bufferlength" : "1",
				"image" : this.video_thumb,
				"namge" : this._videoPlayerId,
				"id"    : this._videoPlayerId
			};
			var parameters = {
					"wmode" : "opaque",
					"allowFullScreen" : "true",
					"allowscriptaccess" : "always",
					"swliveconnect":"true"
			};
			this._swfPlayer = swfobject.embedSWF("/flash/player.swf",this._videoPlayerId,"520","312","9.0.0",null,flashvars,parameters,attributes);
			this._currentlyShown = true;
		}
	},

    okayToSlide: function(){
    	var player = dojo.byId(this._videoPlayerId);
    	if ( player.getConfig ){
    		if ( player.getConfig().state == "IDLE" ){
    			return true;
    		} else {
    			return false;
    		}
    	}
    	return true;
    },

	hide: function(){
		if ( this._swfPlayer ) {
			this._swfPlayer = null;
			this._currentlyShown = false;
			swfobject.removeSWF(this._videoPlayerId);
			var playerContainer = dojo.create('div');
			dojo.attr(playerContainer,'id',this._videoPlayerId);
			var imgPlaceholder = dojo.create('img');
			dojo.attr(imgPlaceholder,'src',this.video_thumb);
			dojo.attr(imgPlaceholder,'alt','Hot Pink Shorts');
			dojo.place(imgPlaceholder,playerContainer,'last');
			dojo.place(playerContainer,this.videoPlayerDiv,'last');
		}
	}

});