var currentDivID = '';

function $e(id) {
	return document.getElementById(id);
}

function divSwap(obj)
{
	var el;
	if ((currentDivID != '') && (currentDivID != obj)) {
		el = $e(currentDivID);
		el.style.display = 'none';
		currentDivID = '';
	}
	
	if (obj == '') return false;
	
	el = $e(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		currentDivID = '';
	} else {
		el.style.display = '';
		currentDivID = obj;
	}
	
	return false;
}

function sendAjaxGet(obj)
{
	var targetURL = obj['url'];
	var successFunction = obj['success'];
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX. Please try with a different browser; most modern web browsers are AJAX-capable.");
		return;
	}
	
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState == 4) return successFunction(xmlHttp.responseText);
	};
	xmlHttp.open("GET",targetURL,true);
	xmlHttp.send(null);
	return true;
}

function showVideoData(responseText) {
	var obj = eval("("+responseText+")");
	var formattedData = "<p><b>"+obj['title']+"</b> "+obj['description']+"<span style=\"float: right; text-align: right;\"><a href=\"#\" onclick=\"$e('"+obj['playDivId']+"').innerHTML=''; $e('"+obj['playDivId']+"').style.display='none';\">close</a></span></p>";
	if (obj['url']) formattedData += "<p style=\"text-align: center;\"><object width=\"425\" height=\"344\"><param name=\"movie\" value=\""+obj['url']+"\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\""+obj['url']+"\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object></p>";
	$e(obj['playDivId']).innerHTML = formattedData;
	$e(obj['playDivId']).style.display = 'block';
}

function video(id) {
	return sendAjaxGet({
		url: "videodata.php?video="+id,
		success: function(rt) {
			showVideoData(rt);
		}
	});
}