var g_strMovieBoxClose = '/Images/MovieBox_X.png';
var g_strMovieBoxBalk = '/Images/MovieBox_Balk.png';
var g_intPageScroll = 0;
var g_intPageWidth = 0;
var g_intPageHeight = 0;
var g_intWindowWidth = 0;
var g_intWindowHeight = 0;
var g_intXScroll = 0;
var g_intYScroll = 0;
var g_intStanWidth = 364;
var g_intStanHeight = 314;

function isIE()
{
    var strBrowser = navigator.userAgent.toLowerCase();

    if(strBrowser.indexOf("msie") > -1 && strBrowser.indexOf("mac") < 0)
        return true;
    else
        return false;
}

//Set g_intPageScroll Y page scroll value
function getPageScrollMovie()
{
	if (self.pageYOffset) {
		g_intPageScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		// Explorer 6 Strict
		g_intPageScroll = document.documentElement.scrollTop;
	} else if (document.body) {
	    // all other Explorers
		g_intPageScroll = document.body.scrollTop;
	}
	return g_intPageScroll;
}

//Set page width, height and window width, height
function getPageSizeMovie()
{
	if (window.innerHeight && window.scrollMaxY) {	
		g_intXScroll = document.body.scrollWidth;
		g_intYScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
	    // all but Explorer Mac
		g_intXScroll = document.body.scrollWidth;
		g_intYScroll = document.body.scrollHeight;
	} else { 
	    // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		g_intXScroll = document.body.offsetWidth;
		g_intYScroll = document.body.offsetHeight;
	}
	
	//var g_intWindowWidth, g_intWindowHeight;
	if (self.innerHeight) {
	    // all except Explorer
		g_intWindowWidth = self.innerWidth;
		g_intWindowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
	    // Explorer 6 Strict Mode
		g_intWindowWidth = document.documentElement.clientWidth;
		g_intWindowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
	    // other Explorers
		g_intWindowWidth = document.body.clientWidth;
		g_intWindowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(g_intYScroll < g_intWindowHeight){
		g_intPageHeight = g_intWindowHeight;
	} else { 
		g_intPageHeight = g_intYScroll;
	}

	// for small pages with total width less then width of the viewport
	if(g_intXScroll < g_intWindowWidth){	
		g_intPageWidth = g_intWindowWidth;
	} else {
		g_intPageWidth = g_intXScroll;
	}
	
	var l_aryPageSize = new Array(g_intPageWidth,g_intPageHeight,g_intWindowWidth,g_intWindowHeight) 
	return l_aryPageSize;
}

function SetMovieBox()
{
    if (!document.getElementsByTagName){ return; }
    var l_objAnchors = document.getElementsByTagName("a");
    var l_intCounter = 0;
    var l_intCounter2 = 0;
    
    while(l_intCounter < l_objAnchors.length)
    {
        var l_objAnchor = l_objAnchors[l_intCounter];
        if(l_objAnchor.getAttribute('href') && l_objAnchor.getAttribute('href').indexOf('.flv') > -1)
        {
            l_objAnchor.onclick = function () {return ShowMovieBox(this);}
            l_intCounter2++;
        }
        l_intCounter++;
    }
    if(l_intCounter2 > 0)
    {
        var l_objBody = document.getElementsByTagName("body").item(0);
        var l_objOverlay = document.createElement("div");
        l_objOverlay.setAttribute('id','OverlayMovieBox');
        l_objOverlay.style.display = 'none';
        l_objOverlay.style.top = '0';
        l_objOverlay.style.left = '0';
        l_objBody.insertBefore(l_objOverlay, l_objBody.firstChild);
        l_objOverlay.onclick = function () {HideMovieBox(); return false;}
        
        // create LightBox
        var l_objMovieBox = document.createElement("div");
	    l_objMovieBox.setAttribute('id','MovieBox');
	    l_objMovieBox.style.display = 'none';
	    l_objMovieBox.style.position = 'absolute';
	    l_objBody.insertBefore(l_objMovieBox, l_objOverlay.nextSibling);
	    
	    var l_objMovieBalk = document.createElement("img");
	    l_objMovieBalk.setAttribute('id','MovieBoxBalk');
	    l_objMovieBalk.src = g_strMovieBoxBalk;
	    l_objMovieBox.appendChild(l_objMovieBalk);
	    
	    var l_objMovieClose = document.createElement("img");
	    l_objMovieClose.setAttribute('id','MovieBoxClose');
	    l_objMovieClose.src = g_strMovieBoxClose;
	    l_objMovieClose.onclick = function(){HideMovieBox()};
	    l_objMovieBox.appendChild(l_objMovieClose);
	   
	    var l_objMovieContainer = document.createElement("div");
	    l_objMovieContainer.setAttribute('id','MovieBoxContainer');
	    l_objMovieBox.appendChild(l_objMovieContainer);
	}
}

function ShowMovieBox(p_objObject)
{
    getPageSizeMovie();
	getPageScrollMovie();
    var l_objOverlay = document.getElementById('OverlayMovieBox');
    var l_objMovieBox = document.getElementById('MovieBox');
    var l_objMovieContainer = document.getElementById('MovieBoxContainer');

    var l_strFlashValue = 'http://Web3.smartobjects.nl/Public/W3sFlvplayer.swf?file=##file##&autoStart=true';
    
    var l_strHref = p_objObject.href;

    var l_intOriginalWidth = 0;
    var l_intOriginalHeight = 0;
    var l_intNewHeight      = 290;
    if (l_strHref.indexOf ('width=') > 0) {
        l_strHref = l_strHref.substring (l_strHref.indexOf ('width='));
        try {
            l_intOriginalWidth = l_strHref.substring (l_strHref.indexOf ('width=') + 6, l_strHref.indexOf ('&'));
        } catch (error) { }
        if (l_strHref.indexOf ('height=') > 0) {
            try {
                l_intOriginalHeight = l_strHref.substring (l_strHref.indexOf ('height=') + 7);
            } catch (error) { }
        }
    }
    if (l_intOriginalWidth != 0 && l_intOriginalHeight != 0) {
        l_intNewHeight = l_intOriginalHeight * (360 / l_intOriginalWidth)
    }
    document.getElementById ('MovieBoxContainer').style.height = l_intNewHeight + 'px';
	var l_objFlashEmbed = document.createElement('embed');
    l_objFlashEmbed.setAttribute('src', l_strFlashValue.replace('##file##', p_objObject.href));
    l_objFlashEmbed.setAttribute('quality','High');
    l_objFlashEmbed.setAttribute('bgcolor','#ffffff');
    l_objFlashEmbed.setAttribute('type','application/x-shockwave-flash');
    l_objFlashEmbed.setAttribute('quality','High');
    l_objFlashEmbed.setAttribute('menu','false');
    l_objFlashEmbed.setAttribute('width', '360');
    l_objFlashEmbed.setAttribute('height', l_intNewHeight);
    l_objFlashEmbed.setAttribute('PLUGINSPAGE','http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash');
    l_objMovieContainer.appendChild(l_objFlashEmbed);

    l_objOverlay.style.height = (g_intPageHeight + 'px');
	l_objOverlay.style.display = 'block';
    
    if (navigator.appVersion.indexOf("MSIE")!=-1){
        //Wait(50);
    }
    var l_strFlash = '';
    var LightBoxTop = g_intPageScroll + ((g_intWindowHeight - g_intStanHeight) / 2);
    var LightBoxLeft = ((g_intPageWidth - g_intStanWidth) / 2);
    l_objMovieBox.style.top = (LightBoxTop < 0) ? "0px" : LightBoxTop + "px";
	l_objMovieBox.style.left = (LightBoxLeft < 0) ? "0px" : LightBoxLeft + "px";
    l_objMovieBox.style.display = 'block';
    return false;
}

function HideMovieBox()
{
	// get objects
	document.getElementById('OverlayMovieBox').style.display = 'none';
    document.getElementById('MovieBox').style.display = 'none';
    document.getElementById('MovieBoxContainer').innerHTML = '';
	document.onkeypress = '';
}

function addLoad(p_objFunc)
{	
	var l_objOldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = p_objFunc;
	} else {
		window.onload = function(){
		l_objOldonload();
		p_objFunc();
		}
	}
}

var dom = document.getElementById?1:0;

function op(o) { 
      return dom?document.getElementById(o).style:ie4?eval('document.all.'+o+'.style'):eval('document.'+o); 
}

addLoad(SetMovieBox);

window.defaultStatus = "";