function Widget_CreateElements() {

	newDiv1 = document.createElement("div");
	newDiv1.id = "grayout";
	newDiv1.style.display = "none";
	newDiv1.style.visibility = "hidden";
	document.body.appendChild(newDiv1);

	newDiv2 = document.createElement("div");
	newDiv2.id = "popup";
	
	newDiv2.style.display = "none";
	newDiv2.style.visibility = "hidden";
	document.body.appendChild(newDiv2);

	newDiv3 = document.createElement("div");
	newDiv3.id = "temp_w";
	newDiv3.style.display = "none";
	newDiv3.style.visibility = "hidden";
	document.body.appendChild(newDiv3);

	newDiv4 = document.createElement("div");
	newDiv4.id = "temp_h";
	newDiv4.style.display = "none";
	newDiv4.style.visibility = "hidden";
	document.body.appendChild(newDiv4);

}

function Widget_RemoveElements(){
	if(document.getElementById("grayout")){
		document.body.removeChild(newDiv1);	
		document.body.removeChild(newDiv2);	
		document.body.removeChild(newDiv3);	
		document.body.removeChild(newDiv4);
	
	}
}



function Widget_GrayOut(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
	xScroll = document.body.scrollWidth;
	yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;
	} else {
	xScroll = document.body.offsetWidth;
	yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
	windowWidth = self.innerWidth;
	windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
	}
	if(yScroll < windowHeight){
	pageHeight = windowHeight;
	} else {
	pageHeight = yScroll;
	}
	if(xScroll < windowWidth){
	pageWidth = windowWidth;
	} else {
	pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)

	if (document.all){
	var xtraW = 0;
	var xtraH = 20;
	if (pageWidth - windowWidth == 21) {xtraW = -21};
	if (pageHeight - windowHeight == 4) {xtraH = -4};
	}
	else
	{
	var xtraW = 0;
	var xtraH = 0;
	}
		
	document.getElementById('temp_w').innerHTML = windowWidth;
	document.getElementById('temp_h').innerHTML = windowHeight;

	document.getElementById('grayout').style.display = 'block';
	document.getElementById('grayout').style.visibility = 'visible';
	document.getElementById('grayout').innerHTML = '<div style=background:black;margin:0px;position:absolute;left:0px;top:0px;width:'+(pageWidth+xtraW)+'px;height:'+(pageHeight+xtraH)+'px;overflow:hidden;filter:alpha(opacity=50);-moz-opacity:.5;opacity:0.5;></div>';

}


function Widget_BuildIt(w,h,widgetid,clipid) {
	popuphtml = "";

	<!--CALLING LAUNCHPAD SCRIPT--!>
	popuphtml = popuphtml + '<table bgcolor=white border=0 cellpadding=0 cellspacing=0>';
		<!--CALLING LAUNCHPAD SCRIPT--!>
	popuphtml = popuphtml + '<tr>';
	popuphtml = popuphtml + '<td><table bgcolor=white border=0 cellpadding=0 cellspacing=0 width=400px><tr><td width=370px><font style="font-family:Trebuchet MS;font-style:normal;font-size:16px;text-decoration:none;color:black;"><B>Grab it, Send it, Post it!</b></font></td><td width=30px><a style="font-family:arial;font-style:normal;font-size:20px;text-decoration:none;color:silver;" onmouseover=this.style.color="gray" onmouseout=this.style.color="silver" href="javascript:void(Widget_Restore())">[X]</a></p></td></tr></table></td>';
	popuphtml = popuphtml + '</tr>';

	popuphtml = popuphtml + '<tr>';

	<!--LAUNCHPAD--!>
	popuphtml = popuphtml +'<td><div id="launchpad"></div></td>';
	<!--LAUNCHPAD--!>
	popuphtml = popuphtml + '</tr>';
	popuphtml = popuphtml + '</table>';


	document.getElementById('popup').innerHTML = popuphtml;
}

function Widget_ScrollHeight() {
	var scroll_h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	return scroll_h ? scroll_h : 0;
}

function Widget_PopUp(w,h){
	document.getElementById('popup').style.display = 'block';
	document.getElementById('popup').style.visibility = 'visible';
	document.getElementById('popup').style.position = 'absolute';
	document.getElementById('popup').style.left = (document.getElementById('temp_w').innerHTML/2)-(w/2)+'px';
	document.getElementById('popup').style.top = (document.getElementById('temp_h').innerHTML/2)-(h/2)+(Widget_ScrollHeight()-(20))+'px';
}


function Widget_Overlay(widgetid,clipid,clipTitle){
	var w = 385;
	var h = 365;
	var vTitle=Widget_SiteName()
	if(clipTitle=="" || clipTitle==null || clipTitle=="undefined" || clipTitle==undefined){
	var cTitle=vTitle

	}else{
	var cTitle=vTitle +" - "+clipTitle
	}
	if (widgetid == '' || widgetid == null || widgetid == 0){
		widgetid = Widget_GetWidgetID()
	}
		
	Widget_CreateElements();
	Widget_GrayOut();
	Widget_BuildIt(w,h,widgetid,clipid,cTitle);
$Launchpad.ShowMenu({wid: widgetid, servicesInclude: ["myspace", "google", "facebook", "live", "livejournal", "spaces", "netvibes", "pageflakes", "xanga", "webwag", "friendster", "blogger", "typepad", "freewebs", "myyearbook", "eons", "tagged", "blackplanet", "multiply", "piczo", "hi5", "vox", "yahoowidgets", "jscode", "objectcode","send","desktop"], config : { "clipID" : clipid, "video_title": cTitle} , targetElement : "launchpad"});
	Widget_PopUp(w,h);
//launchpad.show();
	if (typeof EmbeddedPlayerManager != "undefined") {
		embeddedPlayerManager.getPlayer().pause();
		embeddedPlayerManager.getPlayer().hidePlayer();
	}
}

function Widget_Restore(){
	document.getElementById('grayout').style.display = 'none';
	document.getElementById('grayout').style.visibility = 'hidden';
	document.getElementById('popup').innerHTML = '';
	document.getElementById('popup').style.display = 'none';
	document.getElementById('popup').style.visibility = 'hidden';

	Widget_RemoveElements()
	 
	if (typeof EmbeddedPlayerManager != "undefined") {
		embeddedPlayerManager.getPlayer().play();
		embeddedPlayerManager.getPlayer().unHidePlayer();
	}
	
}


function Widget_GetWidgetID() {
	var fullDomainArray = new Array();
	var domainArray = new Array();
	var widgetid = "";
	fullDomainArray = String( window.location ).split("/");
	domainArray = fullDomainArray[2].split(".");
	domainName = domainArray[domainArray.length-2]+"."+domainArray[domainArray.length-1];
	switch (domainName)
	{
		case "dotcomedy.com":
			widgetid = "465703d43bf8ed1d";
			break;
		case "televisionwithoutpity.com":
			widgetid = "483dce16aa491e3d";
			break;
		case "ivillage.com":
			widgetid = Widget_getiVillageWidgetId(domainArray);
			break;
		case "accesshollywood.com":
			widgetid = "482a0d55893fbe3f";
			break;
		case "scifi.com":
			widgetid = "48e10f5e9dbb50aa";
			break;
		case "bravotv.com":
			widgetid = "4657041ec2a2cf53";
			break;
		case "nbc.com":
			widgetid = "465704e99b38fadc";
			break;
		case "nbcsports.com":
			widgetid = "46570546189e9e76";
			break;
		case "sionnbcsports.com":
			widgetid = "46570546189e9e76";
			break;
		case "usanetwork.com":
			widgetid = "4657059775fa3215";
			break;
		case "outzonetv.com":
			widgetid = "4692b44034eae007";
			break;
		case "reeltalktv.com":
			widgetid = "46d53a0a8ca871de";
			break;
		case "greenisuniversal.com":
			widgetid = "471ebd0654ae98f7";
			break;
			case "petside.com":
			widgetid = "47b61e8a785ed619";
			break;
		case "oxygen.com":
			widgetid = "486ba487be882f6f";
			break;
		case "hotchalk.com":					
			widgetid = "48a47d4b81a98ea2";
			break;
		case "ge.com":					
			widgetid = "482a0d55893fbe3f";
			break;			
		default:
			widgetid = "4644bb88b5677b70";
	}
	return widgetid;
}

function Widget_SiteName() {
	var fullDomainArray = new Array();
	var domainArray = new Array();
	var sitename = "";
	fullDomainArray = String( window.location ).split("/");
	domainArray = fullDomainArray[2].split(".");
	domainName = domainArray[domainArray.length-2]+"."+domainArray[domainArray.length-1];
	switch (domainName)
	{
		case "dotcomedy.com":
			sitename = "Dot Comedy Video";
			break;
		case "televisionwithoutpity.com":
			sitename = "TWoP Video";
			break;
		case "ivillage.com":
			sitename = "iVillage Video";
			break;
		case "accesshollywood.com":
			sitename = "Access Hollywood Video";
			break;
		case "scifi.com":
			sitename = "SCIFI Video";
			break;
		case "bravotv.com":
			sitename = "Bravo TV Video";
			break;
		case "nbc.com":
			sitename = "NBC Video";
			break;
		case "nbcsports.com":
			sitename = "NBC Sports Video";
			break;
		case "sionnbcsports.com":
			sitename = "Video";
			break;
		case "usanetwork.com":
			sitename = "USA Network Video";
			break;
		case "outzonetv.com":
			sitename = "Outzone Video";
			break;
		case "reeltalktv.com":
			sitename = "Reel Talk Video";
			break;
		case "greenisuniversal.com":
			sitename = "Green Is Universal Video";
			break;
			case "petside.com":
			sitename = "Petside.com Video";
			break;
		case "oxygen.com":
			sitename = "Oxygen Video";
			break;
		case "hotchalk.com":					
			sitename = "iCue Video";
			break;
		case "ge.com":					
			sitename = "GE Video";
			break;			
		default:
			sitename = "Video";
	}
	return sitename;
}

function Widget_getiVillageWidgetId(domainArray)
{
	var ivillagewidgetid = "4772a211f870b9a4";
	var intheloopwidgetId = "4657029c165aaaf4";
	domainName = domainArray[domainArray.length-3]+"."+ domainArray[domainArray.length-2]+"."+domainArray[domainArray.length-1];
	if(domainName == 'intheloop.ivillage.com')
	{
		return intheloopwidgetId;
	}else{
		return ivillagewidgetid;
	}
}

function Widget_GetDomain() {
	var fullDomainArray = new Array();
	var domainArray = new Array();
	fullDomainArray = String( window.location ).split("/");
	domainArray = fullDomainArray[2].split(".");
 	domainName = domainArray[domainArray.length-2]+"."+domainArray[domainArray.length-1];
		
 	switch (domainName) {
	
	case "dotcomedy.com": return domainName; break;
	case "ivillage.com": return domainName; break;
	case "accesshollywood.com": return domainName; break;
	case "scifi.com": return domainName; break;
	case "bravotv.com": return domainName; break;
	case "nbc.com": return domainName; break;
	case "nbcsports.com": return domainName; break;
	case "sionnbcsports.com": return domainName; break;
	case "usanetwork.com": return domainName; break;
	case "reeltalktv.com": return domainName; break;
	case "petside.com": return 'nbc.com'; break;
	case "oxygen.com": return 'nbc.com'; break;
	case "teacher.hotchalk": return 'nbc.com'; break;
	case "televisionwithoutpity.com": return 'bravotv.com'; break;
	case "ge.com": return 'nbc.com'; break;

	//case "greenisuniversal.com": return domainName; break;
	
	default: return 'clearspring.com'

	} 
	
}