/**
 * @author Greg
 */
function loadVideoButtons()
{
	videoButtonObj = document.getElementById("videoButton");
	if(!videoButtonObj) return;
	addEvent(videoButtonObj, "mouseover", rollButton, false);
	addEvent(videoButtonObj, "mouseout", rollButton, false);
	addEvent(videoButtonObj, "click", loadVideo, false);
}

function rollButton(e)
{
	target = fetchTarget(e);
	currImg = target.src.match(/_(on|off)/)[1];
	//alert(currImg);
	if (currImg == "on")
	{
		target.src = target.src.replace(/_on/, "_off");
	}
	else
	{
		target.src = target.src.replace(/_off/, "_on");
	}
}

/*
 * 
 * <img src="images/video_off.gif" alt="Ver vídeo" videoSrc="pandynair.flv" name="videoButton" 
 * id="videoButton" width="188" height="47" border="0" class="button">
 * 
 */
var myvideoObj = null;

function loadVideo(e)
{
	target = fetchTarget(e);
	myPos = findPos(target);
	//alert(myPos);
	myvideosrc = target.getAttribute("videoSrc");
	
	
	closeButtonObj = document.createElement("img");
	closeButtonObj.src = "images/video_close_off.gif";
	closeButtonObj.setAttribute("videoSrc", myvideosrc);
	closeButtonObj.className = "button";
	addEvent(closeButtonObj, "mouseover", rollButton, false);
	addEvent(closeButtonObj, "mouseout", rollButton, false);
	addEvent(closeButtonObj, "click", closeVideo, false);
	
	//videoBlockObj = document.getElementById("videoBlock");
	videoPopupObj = document.createElement("div");
	videoPopupObj.id = "videoPopup";
	videoPopupObj.className = "videoPopup";
	videoPopupObj.style.left = myPos[0] + "px";
	videoPopupObj.style.top = myPos[1] + "px";
	videoContainerObj = document.createElement("div");
	videoContainerObj.id = "videoPopupContainer";
	videoPopupObj.appendChild(videoContainerObj);
	videoPopupObj.appendChild(closeButtonObj);
	document.body.appendChild(videoPopupObj);
	myvideoObj = new FAVideo("videoPopupContainer", "video/" + myvideosrc, 420, 360, {autoPlay:true, autoLoad:true, skinVisible:true, skinAutoHide:true, volume:0});
}

function closeVideo(e)
{
	target = fetchTarget(e);
	myvideosrc = target.getAttribute("videoSrc");
	
	videoPopupObj = document.getElementById("videoPopup");
	myvideoDiv = document.getElementById("videoContainer");
	myvideoObj.stop();
	setTimeout("document.body.removeChild(videoPopupObj);", 1000)
	//setTimeout("removeVideoElements(videoPopupObj, myvideoDiv, target);", 1000);
	//videoBlockObj.removeChild(target);
	/*
	videoContainerObj = document.createElement("div");
	videoContainerObj.id = "videoContainer";
	videoBlockObj.appendChild(videoContainerObj);
	videoButtonObj = document.createElement("img");
	videoButtonObj.src = "images/video_off.gif";
	videoButtonObj.setAttribute("videoSrc", myvideosrc);
	videoButtonObj.id = "videoButton";
	videoButtonObj.className = "button";
	addEvent(videoButtonObj, "mouseover", rollButton, false);
	addEvent(videoButtonObj, "mouseout", rollButton, false);
	addEvent(videoButtonObj, "click", loadVideo, false);
	setTimeout("videoContainerObj.appendChild(videoButtonObj);", 1000);
	*/
}


function XcloseVideo(e)
{
	target = fetchTarget(e);
	myvideosrc = target.getAttribute("videoSrc");
	
	videoBlockObj = document.getElementById("videoBlock");
	myvideoDiv = document.getElementById("videoContainer");
	myvideoObj.stop();
	setTimeout("removeVideoElements(videoBlockObj, myvideoDiv, target);", 1000);
	//videoBlockObj.removeChild(target);
	
	videoContainerObj = document.createElement("div");
	videoContainerObj.id = "videoContainer";
	videoBlockObj.appendChild(videoContainerObj);
	videoButtonObj = document.createElement("img");
	videoButtonObj.src = "images/video_off.gif";
	videoButtonObj.setAttribute("videoSrc", myvideosrc);
	videoButtonObj.id = "videoButton";
	videoButtonObj.className = "button";
	addEvent(videoButtonObj, "mouseover", rollButton, false);
	addEvent(videoButtonObj, "mouseout", rollButton, false);
	addEvent(videoButtonObj, "click", loadVideo, false);
	setTimeout("videoContainerObj.appendChild(videoButtonObj);", 1000);
}

function removeVideoElements(videoBlockObj, myvideoDiv, button)
{
	videoBlockObj.removeChild(myvideoDiv);
	videoBlockObj.removeChild(button);
	return true;
}

addEvent(window, "load", loadVideoButtons, false);
