
function intros( swfName, swfWidth, swfHeight, swfBackground, swfURL ) {
	window.scrollTo(0,0);
	window.scrollTo(0,0);
	// create the div structure
	createintros( swfName, swfWidth, swfHeight, swfBackground, swfURL );
	// position the flash in the middle vertically 
	positionintros( swfName, swfWidth, swfHeight );
	// finally make the intros visible
	document.getElementById(swfName).style.display='block';
}

function createintros( swfName, swfWidth, swfHeight, swfBackground, swfURL ) {
	// get basic browser properties 
	var pageBody = document.getElementsByTagName("body").item(0);
	var userAgent = navigator.userAgent.toLowerCase();

	// start creating the div structure 
	var intros = document.createElement("div");
	intros.setAttribute('id',swfName);
	intros.className = 'intros';
	pageBody.appendChild(intros);

	var intros_back = document.createElement("div");
	intros_back.className = 'intros-back';
	// fix a bug with flickering flash over opacity on the firefox for Mac 
	if ( userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1 ) {
		intros_back.style.backgroundImage= "url(http://taipei03/test/intros_back.png)";
		intros_back.style.backgroundRepeat="repeat";
	} else {
		intros_back.style.backgroundColor = "#000";
		intros_back.style.MozOpacity = 0.8;
		intros_back.style.opacity = .80;
		intros_back.style.filter = "alpha(opacity=80)";
	}
	intros.appendChild(intros_back);

	var intros_container = document.createElement("div");
	intros_container.className = 'intros-container';
	intros.appendChild(intros_container);

	var intros_content = document.createElement("div");
	intros_content.className = 'intros-content';
	intros_container.appendChild(intros_content);
	
	windowDimensions = windowSize();
	voffset = 62; //(windowDimensions[1]-swfHeight);
	intros_content.innerHTML = '<img src="images/speace.gif" width="9" height="'+voffset+'" border="0"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+swfWidth+'" height="'+swfHeight+'" id="'+swfName+'-flash" class="intros-flash"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+swfURL+'" /><param name="quality" value="high" /><param name="bgcolor" value="'+swfBackground+'" /><param name="wmode" value="transparent"><embed src="'+swfURL+'" quality="high" bgcolor="'+swfBackground+'" width="'+swfWidth+'" height="'+swfHeight+'" name="'+swfName+'-flash" class="intros-flash" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" wmode="transparent" /></object>';

	intros.onclick = function(e){
							// fix a bug with Safari that passes the onclick event hierarchically inside the flash object 
							if( userAgent.indexOf('safari')!=-1 ) {
								if( e.target.className == 'intros-flash' ) return;
									hideintros(swfName);
							} else {
									hideintros(swfName);
							}
					}
	window.onscroll = function() { window.onscroll = null; hideintros(swfName); }
}

function positionintros( swfName, swfWidth, swfHeight ) {
	// find the browser's window dimensions
	windowDimensions = windowSize();
	pageScrolls = pageScroll();
	// get new positions for the intros divs so it appears in the middle vertically 
	positionDivs = new Array (); 
	positionDivs = {'intros-back-top' : String( pageScrolls[1] )+'px',
					'intros-back-height' : String( windowDimensions[1] )+'px',
					'intros-container-top' : String( pageScrolls[1] + (windowDimensions[1]/2) )+'px',
					'intros-content-top' : String(-(swfHeight/2))+'px' };
	// apply the new position of each div
	introsNodes = document.getElementById(swfName).childNodes;
	for ( var i=0; i<introsNodes.length; i++ ) { 
		if ( introsNodes[i].className == 'intros-container' ) { 
			introsNodes[i].style.top = positionDivs['intros-container-top'];
			// find the content div inside the container
			for ( var j=0; j<introsNodes[i].childNodes.length; j++ ) { 
				if ( introsNodes[i].childNodes[j].className == 'intros-content' ) { 
					introsNodes[i].childNodes[j].style.top = positionDivs['intros-content-top'];
				}
			}
		} 
		if ( introsNodes[i].className == 'intros-back' ) { 
			introsNodes[i].style.top = positionDivs['intros-back-top'];
			introsNodes[i].style.height = positionDivs['intros-back-height'];
		} 
	}
}

function hideintros(swfName) {
	// hide the intros
	var pageBody = document.getElementsByTagName("body").item(0);
	var intros =document.getElementById(swfName);
	intros.style.display = 'none';
	pageBody.removeChild(intros);
	MM_showHideLayers('Layer1','','show');
	MM_showHideLayers('Layer2','','show');
	MM_showHideLayers('Layer3','','show');
	MM_showHideLayers('Layer4','','show');
}

function windowSize() {
	var windowWidth = 0, windowHeight = 0, windowTop = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	return [windowWidth, windowHeight];
}

function pageScroll(){
	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	return [xScroll,yScroll];
}

function compareScroll( oldYScroll, swfName ){
	pageScrolls = pageScroll();
	if ( pageScrolls[1] != oldYScroll ) {
		hideintros(swfName);
	}
}

