// MediaSilo Viral Javascript
// Version 0.1, June 1, 2009
// Things to do: dynamically pass the width and the height along


// Define variables
var player = null;
var current = null;
var emailclip = null;

// Function that trigger mailto when user click on "Email Clip"
function sendemail(){
	document.location = "mailto:someone@somwhere.com?subject=I found this video&body="+emailclip;
}

// Call when player is ready
function playerReady(obj){
	player = gid(obj.id);
	displayFirstItem();
};

//Listener that monitors the playlist and populates the embed code text area with embed content, overrides email clip var
function itemMonitor(obj){
	var current = player.getPlaylist()[obj.index].file;
	var playlist = player.getPlaylist();
	var embedclip = "<object width=\"500\" height=\"311\"><param name=\"movie\" value=\"http://players.mediasilo.com/jwplayer.swf\?file=" + player.getPlaylist()[obj.index].file + "&image=" + player.getPlaylist()[obj.index].image + "&skin=http://players.mediasilo.com/black.swf\"></param><param name=\"allowFullScreen\" value=\"true\"</param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://players.mediasilo.com/jwplayer.swf\?file=" + player.getPlaylist()[obj.index].file + "&image=" + player.getPlaylist()[obj.index].image + "&skin=http://players.mediasilo.com/black.swf\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"500\" height=\"311\"></embed></object>";
	emailclip = escape("" + siteURL + embedPage +"?video="+ current + "&skin=http://players.mediasilo.com/black.swf&image="+player.getPlaylist()[obj.index].image);
	gid('embedcode_clip').value = embedclip; 
};

// Adds Listener
function displayFirstItem(){
	if(player.getPlaylist()){ 
  		itemMonitor({index:0});
  		player.addControllerListener('ITEM', 'itemMonitor');
	} else {
  	setTimeout("displayFirstItem()",100);
	}
};

// Get the DIV element
function gid(name){
	return document.getElementById(name);
};

// Toggle the embed code on and off
function toggledisplay(element){
	if (element.style.display == "none") {
		element.style.display = "block";
	} else {
		element.style.display = "none";
	}
}
