/* 
Title: Deloitte TTP Campaign
Author: Michael "Spell" Spellacy, Senior UI Developer
Email: michael.spellacy@tmp.com
Company: TMP Worldwide Advertising and Communications, LLC
*/

function prepmedia() {

	// Create the media containers
	
	var cssstyle = "player";
	var body = document.getElementById("ttp");
	
	var mediadiv_a = document.createElement("div");
	mediadiv_a.setAttribute("id", "mediafile-a")
	mediadiv_a.className = cssstyle;
	
	body.appendChild(mediadiv_a);
	
	// Hide players if script comes across them
	
	var container = document.getElementsByTagName("div");

	for (var i=0; i < container.length; i++) {

		if (container[i].className == "player") {
		container[i].style.display = "none";
		}
	}
	
	// Locate links with media attached to them and append onclick event
	
	var medialink_a = document.getElementById("medialink-a");
	
	medialink_a.onclick = function() {
	showhide('mediafile-a', 'video-a', '../../../landing/media/video/ttp/video.flv', 'My Deloitte Journey');
	return false;
	}	
		
}
	
addLoadEvent(prepmedia); //Fire!

// Flash functions used by SWFObject. We simply pass in the path and ID to run appropriate file

function createplayer(path, swf) {

	var flashvars = {};
	var params = {menu: "false", wmode: "transparent", quality: "high", flashvars: "filepath=" + path + "&autoplay=false&previewImage=/global/_media/video/images/del_global_widescreen_scr.jpg"};
	var attributes = {};

	swfobject.embedSWF("../global/_media/skins/videoplayerwide.swf", swf, "322", "225", "8", "../global/_flash/flash_expressinstall.swf", flashvars, params, attributes);

}

// Toggle Elements (unobtrusive)
	
function showhide(id, swf, path, title){ 

	var elementid = document.getElementById(id)
	var flash = elementid;
	var obj = elementid; 

	if (obj.className == "player"){ 

		var newdiv = document.createElement("div");
		newdiv.setAttribute("id", swf);
		
		var header = document.createElement("h4");
		header.title = "Move player";
		var hdrtxt = document.createTextNode(title);

		header.appendChild(hdrtxt);

		var para = document.createElement("p");
		var anchor = document.createElement("a");
		var strtxt = document.createTextNode("Close");
		para.appendChild(anchor);
		anchor.title = "Close player";
		anchor.appendChild(strtxt);
		anchor.onclick = function() {
		showhide(id, swf, path)
		return false;
		}

		obj.appendChild(header);
		flash.appendChild(newdiv);
		createplayer(path, swf);
		flash.appendChild(para);
		
		obj.className += " active"; 
		
		new Draggable(id, {handle:header});

	} else { 

		obj.className = "player"; 
		flash.innerHTML = "";
	} 
} 