var skinH=62;
var skin_id=1;
var skin_name='full';
var sp;

(function($){
	$.fn.StreamPlug = function(url,width,height,skin_name) {

		  this.each(function() {
		  	var $this = $(this);
	if(skin_name=='lite')
    {
	skinH=32;
	}
	if(skin_name=='black')
    {
	skinH=32;
	}
	if(skin_name=='full')
    {
	skinH=62;
	}

    var v_height=height+skinH;

    if(url.length>0)
    {
        document.write  ('<OBJECT src="'+url+'"  CLASSID="CLSID:2019DC25-D1C0-11D6-97B3-0008A124F542" id="StreamPlugIe" name="StreamPlugIe" width="'+width+'" height="'+v_height+'" >');
        document.write  ('<param name="src" value="'+url+'"></param>');
    }
    else
    {
        document.write  ('<OBJECT  CLASSID="CLSID:2019DC25-D1C0-11D6-97B3-0008A124F542" id="StreamPlugIe" name="StreamPlugIe" width="'+width+'" height="'+v_height+'" >');
    }



    document.write  ('<param name="width"  value="'+width+'"></param>');
    document.write  ('<param name="height" value="'+height+'"></param>');


    if(url.length>0)
    {
        document.write  ('<EMBED src="'+url+'" pluginspage="http://messagefromme.com/streamplug/StreamPlug_installer.exe" type="application/x-OGM" id="StreamPlugNs" name="StreamPlugNs" width="'+width+'" height="'+v_height+'" >');
    }
    else
    {
        document.write  ('<EMBED pluginspage="http://messagefromme.com/streamplug/StreamPlug_installer.exe" type="application/x-OGM" id="StreamPlugNs" name="StreamPlugNs" width="'+width+'" height="'+v_height+'" >');
    }
    document.write  ('</EMBED>');
    document.write  ('</object>');
			
		  });

		  setTimeout      ('StreamPlug_OnReady_1 ('+width+','+height+',"'+skin_name+'");',200);

		  return this;
	}
})(jQuery);


function StreamPlug_OnReady_1   (width,height,skin_name)
{
    sp=$().SpGetInterface();
    $().SpResizeVideo(width,height);
    $().SpSetSkin(skin_name);

}

$.fn.SpGetInterface = function() 
{
	if(navigator.appName=="Microsoft Internet Explorer")
	{
     sp=document.getElementById('StreamPlugIe');
    }
	else 
	{
	    if(document.embeds['StreamPlugNs'])
	    {
	     sp=document.embeds['StreamPlugNs'];
	    }
	}
	return sp;
}

//Get Attributes
/////////////////

//Get Plugin Window Width
$.fn.SpvideoWindowWidth = function()
{
 if(sp)
	return sp.videoWindowWidth();
}

//Get Plugin Window Height
$.fn.SpvideoWindowHeigth = function()
{
 if(sp)
	return sp.videoWindowHeigth();
}

//Get Plugin Skin Width
$.fn.SpskinW = function()
{
 if(sp)
	 return sp.skinW();
}

//Get Plugin Skin Height
$.fn.SpskinH = function()
{
 if(sp)
	return sp.skinH();	
}

//Get Plugin Version Number
$.fn.Spcurversion = function()
{
 if(sp)
	return sp.curversion;
}

//Get current volume
$.fn.Spvolume = function()
{
 if(sp)
	return sp.volume;
}

//Get current play position in kb
$.fn.SpplayPositionKb = function()
{
 if(sp)
	return sp.playPositionKb;
}

//Get current play position in ms
$.fn.SpplayPositionMs = function()
{
 if(sp)
	return sp.playPositionMs;
}

//Get current received stream kb amount
$.fn.SpstreamPositionKb = function()
{
 if(sp)
	return sp.streamPositionKb;
}

//Get current file lenght in kb
$.fn.SpfileLenKb = function()
{
 if(sp)
	return sp.fileLenKb;
}

//Get Current File Url 
$.fn.SpgetUrl = function()
{
 if(sp)
	return sp.src;
}

//Test if StreamPlug is Playing
$.fn.SpisPlaying = function()
{
 if(sp)
	return sp.isPlaying;
}

//Playlists
///////////

//Add an url in the playlist	   
$.fn.SpaddUrl = function(url)
{
 if(sp)
	sp.addUrl(url);
}

//Add pls to the Playlist
$.fn.SpaddPl = function(url)
{
 if(sp)
	sp.addPl(url);
}

//Add An Url With Name        
$.fn.SpaddUrlName = function(url,title)
{
 if(sp)
	sp.addUrlName(url,title);
}

//Add Crypted Playlist
$.fn.SpaddCryptedPl = function(url)
{
 if(sp)
	sp.addCryptedPl(url);
}

//Add Subtitle File/Url     
$.fn.SpaddSrt = function(file,title)
{
 if(sp)
	sp.addSrt(file,title);
}

//Add Saveable url to playlist
$.fn.SpaddSaveAblePl = function(url)
{
 if(sp)
	sp.addSaveAblePl(url);
}

//Add .plc to the Playlist
$.fn.SpaddCryptedPl2 = function(url,key)
{
 if(sp)
	sp.addCryptedPl2(url,key);
}

//Empty the Playlist
$.fn.SpresetPl = function()
{
 if(sp)
	sp.resetPl();
}

//Load specified skin 
$.fn.SploadSkin = function(url,Name)
{
 if(sp)
	sp.loadSkin(url,Name);      
}

//Move Playlist Window	 
$.fn.SpmovePlWin = function(x,y)
{
 if(sp)
	sp.movePlWin(x,y);
}

//Pause Current Stream        
$.fn.Sppause = function()
{
 if(sp)
	sp.pause();       
}

//Play An Url	              
$.fn.SpplayUrl = function(url)
{
 if(sp)
	sp.playUrl(url);	
}

//Play Item # in Playlist
$.fn.SpplayPlItem = function()
{
 if(sp)
	sp.playPlItem(id);
}

//Play Current Stream         
$.fn.Spplay = function()
{
 if(sp)
	sp.play();
}

//Play and Save Url         
$.fn.SpplaySaveableUrl = function(url)
{
 if(sp)
	sp.playSaveableUrl(url);
}

//Play Prev Item
$.fn.Spprev = function()
{
 if(sp)
	sp.prev	();
}

//Play Next Item
$.fn.Spnext = function()
{
 if(sp)
	sp.next();
}

//Start After n Kb
$.fn.SpstartAfterKb = function(KB)
{
 if(sp)
	sp.startAfterKb(KB);
}

//Stop Current Stream        
$.fn.Spstop = function()
{
 if(sp)
	sp.stop();	
}

//Play Item  From db
$.fn.SpplayUrlFromDb = function(id)
{
 if(sp)
	sp.playUrlFromDb(id);
}

//Play a cgi sec file
$.fn.Spplaycgi2 = function(url,fid,user,pass)
{
 if(sp)
	sp.playcgi2(url,fid,user,pass);
}

//Play a cgi file
$.fn.SpplayCGi = function(url,id)
{
 if(sp)
	sp.playCGi(url,id);
}

//Play Multiple (audio/video separated)
$.fn.SpplayMutiple = function(VideoFile,AudioFile)
{
 if(sp)
	sp.playMutiple(VideoFile,AudioFile);
}

//Set Video Size         
$.fn.SpsetVideoSize = function(w,h)
{
 if(sp)
	sp.setVideoSize(w,h);
}

//Set Original Size            
$.fn.SpsetVideoSizeOrig = function()
{
 if(sp)
	sp.setVideoSizeOrig();    
}

//Set Loop mode         
$.fn.SpsetLoop = function(state)
{
 if(sp)
	 sp.setLoop(state);
}

//Set BackGround Color 
$.fn.SpsetBKColor = function(R,G,B)
{
 if(sp)
	sp.setBKColor(R,G,B);
}

//Set Video Ratio	 
$.fn.SpsetRatio = function(w,h)
{
 if(sp)
	sp.setRatio(w,h);
}

//Set Volume
$.fn.SpsetVolume = function(vol)
{
 if(sp)
	sp.setVolume(vol);	
}

//Set Play-on-Start Attribute         
$.fn.SpplayOnStart = function(state)
{
 if(sp)
	 sp.playOnStart(state);
}

//Set Full Screen  
$.fn.SpsetFullScreen = function(state)
{
 if(sp)
	sp.setFullScreen(state);
}

//Set if user Can Resize	
$.fn.SpcanResize = function(state)
{
 if(sp)
	sp.canResize(state);
}
//Set if user Can Download 
$.fn.SpCanDownload = function(state)
{
 if(sp)
	sp.CanDownload(state);
}

//Set Border Size
$.fn.SpsetBorderSize = function(size)
{
 if(sp)
	setBorderSize(size);
}

//Set Border Color
$.fn.SpsetBorderColor = function(R,G,B)
{
 if(sp)
	sp.setBorderColor	(R,G,B);
}

//Set Active Srt (-1 none)
$.fn.SpsetActiveSrt = function(id)
{
 if(sp)
	sp.setActiveSrt(id);
}

//Reset Srt
$.fn.SpresetSrt = function()
{
 if(sp)
	sp.resetSrt();
}

//Set playmode
$.fn.SpsetPlayMode = function(mode)
{
 if(sp)
	sp.setPlayMode(mode);
}

//Set Video Url
$.fn.SpsetVideoUrl = function(url)
{
 if(sp)
	sp.setVideoUrl(url);
}

//Set Video Url Ms
$.fn.SpsetVideoUrlMs = function(url,ms,endplay)
{
 if(sp)
	sp.setVideoUrlMs	(url,ms,endplay);
}

//Set Video Url Ms +ID
$.fn.SpsetVideoUrlMsWithId = function()
{
 if(sp)
	sp.setVideoUrlMsWithId (url,TimeStart,TimeEnd,Id);
}

//Set Event Grid Pos
$.fn.SpsetEventGridPos = function(x,y,Id)
{
 if(sp)
	sp.setEventGridPos(x,y,Id);
}

//Set Event Grid Size
$.fn.SpsetEventGridSize = function(w,h)
{
 if(sp)
	setEventGridSize(w,h);
}

//Set Event Js
$.fn.SpsetEventJS = function(ID)
{
 if(sp)
	setEventJS(ID);
}

//Set pos kb	
$.fn.SpsetPositionKb = function(KB)
{
 if(sp)
	sp.setPositionKb(KB);
}

//Set pos ms	
$.fn.SpsetPositionMs = function(ms,endplay)
{
 if(sp)
	sp.setPositionMs(ms,endplay);
}

//Set color of A/V buffers	  
$.fn.SpsetBufferColor = function(R,G,B)
{
 if(sp)
	sp.setBufferColor(R,G,B);
}

//Windows
/////////

//Show Pluggle Version        
$.fn.SpshowVersion = function(state)
{
 if(sp)
	sp.showVersion(state);
}

//Show the playlist window	
$.fn.SpshowPlaylist = function(state)
{
 if(sp)
	sp.showPlaylist(state);
}

//Show Option Window 
$.fn.SpshowOption = function(state)
{
 if(sp)
	sp.showOption(state)
}

//Show Server Version
$.fn.Spservversion = function()
{
 if(sp)
	 return sp.servversion;
}

$.fn.SpResizeVideo = function(x,y) 
{
    if(sp)
    {
        sp.setVideoSize(x,y);
        sp.setRatio(x,y);
	}
}

$.fn.SpSetSkin = function(skin_name) 
{
    if(sp)
    {
    var theight=0;
	    if(skin_name=='lite')
	    {
	    sp.setSkin(3);
	    theight=32;
	    }
	    if(skin_name=='black')
	    {
	    sp.setSkin(4);
	    theight=32;
	    }
	    if(skin_name=='full')
	    {
	    sp.setSkin(1);
    	theight=62;
	    }
        var video_height= sp.height-skinH;
        skinH=theight;
        sp.height=video_height+skinH;	
    }
}
