/*
	Monk Media Popup v.1 - a script to open window with videoplayer
	(c) 2010 Adam Randlett : monkdevelopment.com
*/  

(function($){
	$.fn.monkmediapopup = function(settings){ 
	   						// "this" is the jQuery object $this.text('0'); / 
		var defaults = {
			file:"href",
			image:"",
			width:"400",
			height:"300",
            playlist:"false",
			template:"/_player/videoplayer.php",
			previewimage:"",
			autostart:"true",
			fullscreen:"true",
			controlbar:"over",
			stretching:"uniform",
			bufferlength:"1",
			smoothing:"true",
			volume:"90",
			type:"video",
			screencolor:"#000000", 
			backcolor:"#000000",
			frontcolor:"#ffffff",
			skin:"/_player/default.swf"
		}

        var options = $.extend(defaults, settings); 
        return this.each(function(){ 
		    var $this = $(this); 
	        var playeroptions ={
				file:$this.attr(options.file),
				image:"",
				width:options.width,
				height:options.height,
				playlist:options.playlist,
				autostart:options.autostart,
				fullscreen:options.fullscreen,
				controlbar:options.controlbar,
				stretching:options.stretching,
				type:options.type,
				volume:options.volume, 
				screencolor:options.screencolor,
				bufferlength:options.bufferlength,
				smoothing:options.smoothing,
				backcolor:options.backcolor,
				frontcolor:options.frontcolor,
				skin:options.skin
			   
			} 
		
			if(options.image.indexOf('.') !=-1){
			   playeroptions.image = options.image;
			}else{
			   playeroptions.image = $this.attr(options.image); 
			}
		
			var globalwidth;
			var pheight =  Number(options.height) + 24;
			var globalheight = String(pheight);
			
		
			if(options.playlist =="true"){
				var pwidth = 240;
				var width = Number(options.width) + pwidth;
				globalwidth = String(width); 
			}else{
				globalwidth = options.width;
			}
		 
			 //if object is not anchor and has anchor as child disable anchor
			 if($this.find("a").length > 0){
				 $this.find("a").click(function(e){e.preventDefault();});
			 }
		
		    //$this.data({video: $this.attr(options.attribute)});
			$this.click(function(e){ 
				var attr = $.param(playeroptions);
				var url = options.template +"/?"+attr+"&target=MediaPlayer";
				window.open(url,"MediaPlayer","menubar=no,resizable=no,width="+globalwidth+",height="+globalheight+",scrollbars=no,status=no");
				if($this.is("a")){
					e.preventDefault();
				}
			 });      
	  });
	};

})(jQuery);