/**
* jquery.media.js - replaces div tags with the respective player.
* Author: Kim Richardson - krichardson@viewdaleit.com.au
* Licence: Copyright 2010 PAW Media and Communications
*********************
* Usage:
<script type="text/javascript">
$(document).ready( function(){
	$('.class').pawmedia();
});
**/

jQuery.fn.pawmedia = function(){
	this.each(function(index){
		var self=$(this);
		//
		var tmp=this.id.split('-');
		var id=tmp[1];
		var type=tmp[0];
		//
		var args=$(this).attr('args');
		if(args!='')
		{
			var data=$.parseJSON(args);
		}
		switch(type)
		{
			case 'video':
			{
				self.html('<p style="text-align:center;padding-top:100px;"><img src="/images/ajax-loader.gif" /><br /><br />Loading PAW Media Video</p>');
				// get the code for the player and insert it
				if(data&&data.width) $(this).css('width',data.width);
				if(data&&data.height) $(this).css('height',data.height);
				self.load('/utilities/videoplayer/'+id,data);
				break;
			}
			case 'audio':
			{
				self.load('/utilities/audioplayer/'+id+'/'+index,data);
				break;
			}
			case 'image':
			{
				if(id.match('_'))
				{
					var flashvars = {
						id: "ssp",
						loadParams: "false",
						galleryAppearance:'Hidden',
						captionAppearance:'Fixed',
						xmlFilePath: '/utilities/imageslideshow/'+id+'.rss',
						xmlFileType: "Media RSS",
						initialURL: escape(document.location)
					}
					var params = { 
						bgcolor: "#000000",   
						allowfullscreen: "true"
					}                
					var attributes = {id: "ssp"};
					swfobject.embedSWF("/js/slideshowpro/slideshowpro.swf", this.id, "550", "400", "10.0.0", false, flashvars, params, attributes);  
				}
				else
				{
					self.load('/utilities/imageplayer/'+id+'/'+index,data,function(){
						$('.fb').fancybox();
					});
				}
				break;
			}
		}
		
	});
};
