/**
 * @author L815
 * Feel free to use as you please
 */


//Elemtns for the buttons & black background
//To change transparency, where it says "opacity", change the value you wish [higher = darker]
var the_div = document.createElement("div");
	the_div.style = "opacity:.90;width:100%;height:100%;background-color: #000;position:absolute;top:0;display:none;";


var linker = document.createElement('div');
	linker.innerHTML="<a href='Javascript:youtube()'>Screen On</a>";
	linker.style="position:absolute;top:0;";
	
var unlinker = document.createElement('div');
	unlinker.innerHTML="<a href='Javascript:undoer()' style='color:#fff;'>Screen Off</a>";
	unlinker.style="position:absolute;top:0;display:none;";

var div_vid = document.createElement('div');
	div_vid.style="position:absolute;top:0;";
	
	
	

setTimeout('checkYoutube()',500);

function checkYoutube(){
	if(document.getElementById('masthead'))
	{
		//Timeout to execute creation of the elements. You can change the value (ex: 1s = 1000)
		setTimeout('appendit()', 800);
	}
	
}




function appendit(){
	
	//Insert the 3 elements
	document.body.appendChild(the_div);
	document.body.appendChild(linker);
	document.body.appendChild(unlinker);
	
}


function youtube(){
	
	//Hide click link
	linker.style.display = "none";

	//Display black background
	the_div.style.display = "";

	//Show undo button
	unlinker.style.display = "";
	
	
	//Get Video element
	var vid_html = document.getElementById('watch-player-div').innerHTML;
	var vid = document.getElementById('watch-player-div');
	
	
	
	
	document.body.appendChild(div_vid);
	div_vid.style="position:absolute;top:70px;left:50%;margin-left:-237.5px;";
	div_vid.innerHTML = vid_html;
	vid.style.display="none";

		
}


function undoer(){
	
	//Hide all the elements
	the_div.style.display="none";
	unlinker.style.display="none";
	linker.style.display="";
	
	//Reset video pos
	document.getElementById('watch-player-div').style.display="";
	document.body.removeChild(div_vid);
	

}
