/* escapeOverlay's construction is a bit hard to grasp. It is needed to be able to
stop the event listener. See the prototype API docs for more information:
http://www.prototypejs.org/api/event
*/
var escapeOverlay = {
	fx: function(e) 
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
		
		// If keypressed is escape and the new entry field is empty
/*		if(kC==Esc && ($F('newvalue') == '' || $F('newvalue') == null) )
			closeDialogue();
		else if(kC==Esc && window.confirm('Are you sure you wish to close the dialogue box?') )
			closeDialogue(); */
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup($which)
{
    	// Show the overlay (disables rest of page)
	showOverlay();

	switch($which)
	{
		case 1:
			show_movie1();
			//centerElement($('dialogue-movie1'));
			$('dialogue-movie1').show();
			break;
		
		case 2:
			show_movie2();
			//centerElement($('dialogue-movie2'));
			$('dialogue-movie2').show();
			break;
		
		case 3:
			show_movie3();
			centerElement($('dialogue-movie3'));
			$('dialogue-movie3').show();
			break;

		case 4:
			show_movie4();
			centerOtherElement($('dialogue-movie4'));
			$('dialogue-movie4').show();
			break;

		case 5:
			show_movie5();
			centerLastElement($('dialogue-movie5'));
			$('dialogue-movie5').show();
			break;

		case 6:
			show_movie6();
			centerLastElement($('dialogue-movie6'));
			$('dialogue-movie6').show();
			break;
		
		default:
			break;
	}
}
 
// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	$('overlay').show();
	
	Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	$('overlay').hide();
	
	Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue()
{
	hideOverlay();
	// Hide dialogue
	if($('dialogue-movie1')) {
		$('dialogue-movie1').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie1');
  		d.removeChild(olddiv);
	}
	if($('dialogue-movie2')) {
		$('dialogue-movie2').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie2');
  		d.removeChild(olddiv);
	}
	
	if($('dialogue-movie3')) {
		$('dialogue-movie3').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie3');
  		d.removeChild(olddiv);
	}

	if($('dialogue-movie4')) {
		$('dialogue-movie4').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie4');
  		d.removeChild(olddiv);
	}

	if($('dialogue-movie5')) {
		$('dialogue-movie5').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie5');
  		d.removeChild(olddiv);
	}

	if($('dialogue-movie6')) {
		$('dialogue-movie6').hide();
		var d = document.getElementById('movie');
  		var olddiv = document.getElementById('dialogue-movie6');
  		d.removeChild(olddiv);
	}
}

function show_movie1()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';
	thediv += '<div style="width:807px; height: 605px; margin-left: auto; margin-right:auto;">';
	thediv += '<div style="width: 807px;">';
	thediv += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="807" height="605" id="buying" align="middle">';
	thediv += '<param name="allowScriptAccess" value="sameDomain" />';
	thediv += '<param name="allowFullScreen" value="false" />';
	thediv += '<param name="movie" value="flash/XSH_Benefits_Tutorial.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="flash/XSH_Benefits_Tutorial.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="807" height="605" name="buying" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	thediv += '</object>';
	thediv += '</div>';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';

	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie1');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
	
}

function show_movie2()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';
	thediv += '<div style="width:807px; height: 605px; margin-left: auto; margin-right:auto;">';
	thediv += '<div style="width: 807px;">';
	thediv += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="807" height="605" id="buying" align="middle">';
	thediv += '<param name="allowScriptAccess" value="sameDomain" />';
	thediv += '<param name="allowFullScreen" value="false" />';
	thediv += '<param name="movie" value="flash/XSH_Features_Tutorial.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="flash/XSH_Features_Tutorial.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="807" height="605" name="buying" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	thediv += '</object>';
	thediv += '</div>';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';
	
	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie2');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
}

function show_movie3()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';
	thediv += '<div style="width: 961px; height: 870px; margin-left: auto; margin-right:auto;">';
	thediv += '<div style="width: 961px;">';
	thediv += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="961" height="870" id="login" align="middle">';
	thediv += '<param name="allowScriptAccess" value="sameDomain" />';
	thediv += '<param name="allowFullScreen" value="false" />';
	thediv += '<param name="movie" value="flash/login.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="flash/login.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="961" height="870" name="login" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	thediv += '</object>';
	thediv += '</div>';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Movie" onClick="closeDialogue()" /></div>';
	
	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie3');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
}

function show_movie4()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Presentation" onClick="closeDialogue()" /></div>';
	thediv += '<div style="width: 700px; height: 594px; margin-left: auto; margin-right:auto;">';
	thediv += '<div style="width: 700px;">';
	thediv += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="700" height="594" id="pres" align="middle">';
	thediv += '<param name="allowScriptAccess" value="sameDomain" />';
	thediv += '<param name="allowFullScreen" value="false" />';
	thediv += '<param name="movie" value="flash/new-pres.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="flash/new-pres.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="700" height="594" name="pres" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	thediv += '</object>';
	thediv += '</div>';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Presentation" onClick="closeDialogue()" /></div>';
	
	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie4');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
}

function show_movie5()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Diagram" onClick="closeDialogue()" /></div>';
	thediv += '<div style="margin-left: auto; margin-right:auto; width: 600px;">';
	thediv += '<img src="images/xs1.jpg" alt="XSDirect Sourcing Strategy Diagram" width="600" />';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Diagram" onClick="closeDialogue()" /></div>';
	
	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie5');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
}

function show_movie6()
{
	var thediv;
	thediv = '<div id="close"><input type="button" value="Close Diagram" onClick="closeDialogue()" /></div>';
	thediv += '<div style="margin-left: auto; margin-right:auto; width: 600px;">';
	thediv += '<img src="images/xs2.jpg" alt="XSDirect Excess Strategy Diagram" width="600" />';
	thediv += '</div>';
	thediv += '<div id="close2"><input type="button" value="Close Diagram" onClick="closeDialogue()" /></div>';
	
	var cont = document.getElementById("movie");
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','dialogue-movie6');
	newdiv.style.display='none';
	newdiv.innerHTML = thediv;
	
	cont.appendChild(newdiv);
}
