var IE = document.all?true:false;
var TemplatePath;
var YCoord;
var overlayDIV;
var flashInstalled;
var newwindow = '';

if(!IE){
window.captureEvents(Event.RESIZE);
document.captureEvents(Event.ONMOUSEDOWN);
}
window.onresize = repositionDemo;
document.onmousedown = findDemoY;



function trackWindow(url) {
		newwindow=window.open(url,'trackWindow','height=1,width=1, menubar=no, toolbar=no');
		if (window.focus) {newwindow.close()}
	return false;
}


function repositionDemo(){
    if(document.getElementById('transparentOverlay').innerHTML != "")
        document.getElementById('flashObject').style.left = document.getElementById('shellFrame').offsetLeft;
}

function findDemoY(e){
    if(IE){
        YCoord = document.body.scrollTop;
    }else{
        YCoord = window.pageYOffset;
    }
}

function demoPlayerWT(WTID, title){
    if(WTID != null || WTID != '')
        dcsMultiTrack('DCSext.wt_evtid',WTID,'WT.dl','1')
}

function detectIE(ClassID){
    result = false;
    document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n');     
    return result;
}

function detectNS(ClassID){
    if(navigator.mimeTypes[ClassID].enabledPlugin != null)
        return true;
    else
        return false;
}

if (IE){
    flashInstalled = detectIE("ShockwaveFlash.ShockwaveFlash");
}else{
	flashInstalled = detectNS("application/x-shockwave-flash");
}

function launchDemo(defaultDemo,demoPlayerURL,templatePath){
    TemplatePath    = templatePath;
    mastheadHeight  = document.getElementById('msviMasthead').offsetHeight;
    pageHeight      = document.getElementById('page').offsetHeight;
    pageWidth       = document.getElementById('page').offsetWidth;
    footerHeight    = document.getElementById('msviFooter').offsetHeight;
    overlayDIV      = document.getElementById('transparentOverlay').innerHTML;
    
//    if(flashInstalled){
    
        document.getElementById('transparentOverlay').style.height=pageHeight + mastheadHeight + footerHeight + 20;
        document.getElementById('transparentOverlay').style.top=-(mastheadHeight + 20);
        document.getElementById('transparentOverlay').style.display='inline';
        document.getElementById('transparentOverlay').style.zIndex='100';
        
        demoString = ' <object id="flashObject" style="position:relative;top:'+ (mastheadHeight+30+YCoord) + ';" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="960" height="700">\n';
        demoString = demoString + ' <param name="movie" value="' + demoPlayerURL + '?defaultDemo='+defaultDemo+'">\n';
        demoString = demoString + ' <param name="quality" value="high">\n';
        demoString = demoString + ' <param name="wmode" value="transparent">\n';
        demoString = demoString + ' <embed src="'+ demoPlayerURL + '?defaultDemo='+defaultDemo+'" width="960" height="700" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>\n';
        demoString = demoString + ' </object>\n';
        document.getElementById('transparentOverlay').innerHTML = overlayDIV + demoString;
        
//    }else{
    
        //document.getElementById('demoPlayer').innerHTML = "<p>" + document.getElementById('demoPlayer').innerHTML + "&nbsp;(Flash required.)</p>";
        
//    }
}

function closePlayer(){
    document.getElementById('transparentOverlay').style.zIndex='-1';
    document.getElementById('transparentOverlay').style.display='none';
    document.getElementById('transparentOverlay').innerHTML = overlayDIV;
}