//************************************************************************************
// Copyright (C) 2006, Massimo Beatini
//
// This software is provided "as-is", without any express or implied warranty. In 
// no event will the authors be held liable for any damages arising from the use 
// of this software.
//
// Permission is granted to anyone to use this software for any purpose, including 
// commercial applications, and to alter it and redistribute it freely, subject to 
// the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not claim 
//    that you wrote the original software. If you use this software in a product, 
//    an acknowledgment in the product documentation would be appreciated but is 
//    not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be 
//    misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//************************************************************************************

//
// global variables
//
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;




//
// dinamically add a div to 
// dim all the page
//
function buildDimmerDiv()
{	

  	var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	if(navigator.userAgent.match(/iPhone/i)){
		width = 590;
		height = 420;
	}

    document.write('<div id="dimmer" class="dimmer" style="width:'+width + 'px; height:' + height +'px"></div>');
	
}

//
//
//

function mouseOver()
{
	document.closeb.src ="video/closeb_down.png";
}
function mouseOut()
{
	document.closeb.src ="video/closeb.png";
}

function mouseOver1()
{
	document.hugelink.src ="video/visit_huge_logo_6_down.png";
}
function mouseOut1()
{
	document.hugelink.src ="video/visit_huge_logo_6.png";
}

function displayFloatingDiv(divId, title, width, height, left, top) 
{	
	
	DivID = divId;
	
	document.getElementById('dimmer').style.width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	document.getElementById('dimmer').style.height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	if(navigator.userAgent.match(/iPhone/i)){
		document.getElementById('dimmer').style.width = 590;
		document.getElementById('dimmer').style.height = 420;
	}

    document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';
	document.getElementById('dimmer').style.visibility = "visible";
	
	var addHeader;
	
	if (originalDivHTML == "")
	    originalDivHTML = document.getElementById(divId).innerHTML;
	
	
	addHeader = '<table style="width: 535px; position:absolute; top:10px;" class="floatingHeader">' +
				'<td style="width:18px;" align="right"><a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);" onmouseover="mouseOver()" onmouseout="mouseOut()">' + 
				'<img alt="Close" title="Close" src="video/closeb.png" name="closeb" border="0"></a></td></tr></table>';
	

    // add to your div an header	
	document.getElementById(divId).innerHTML = addHeader + originalDivHTML;
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.visibility = "visible";
	//alert("play");
	document.getElementById('trailer').innerHTML = '<embed src="video/trailer.m4v" width="480" height="285" name="trailer" autostart="true" enablejavascript="true" pluginspage="http://www.apple.com/quicktime/download/">' +
													'<div class="website" align="center"><a href="http://www.hugetheshow.com" onmouseover="mouseOver1()" onmouseout="mouseOut1()"><img src="video/visit_huge_logo_6.png" width="170" height="12" name="hugelink"></a></div>';
	//document.trailer.Play();

	


}

//
//
//
function hiddenFloatingDiv(divId) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById('dimmer').style.visibility = 'hidden';
	
	DivID = "";
}

function resizeHandler()
{
	var w, h, l, t;
	w = 520;
	h = 360;
	l = window.innerWidth/2-w/2;
	t = 45;
               
	displayFloatingDiv('windowcontent', '', w, h, l, t);	
}
//
//
//
function init()
{

	buildDimmerDiv();
	window.onresize = resizeHandler;
}

// call init
init();
