
innerBoxName = "innerBox";
outerBoxName = "outerBox";

function getHTTObject(){
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}
// Change the value of the outputText field
function setFlash(){
	if(httpObject.readyState == 4){
		document.getElementById(innerBoxName).innerHTML = httpObject.responseText;
		throwBox();
		opening = false;
	}
}

opening = false;
function showWork(workId,throwBoxValue){
	if(!opening){
		opening = true;
		httpObject = getHTTObject();
		if (httpObject != null) {
			httpObject.open("GET", "showVideo.html", true);	
			httpObject.send(null);
			httpObject.onreadystatechange = setFlash;
			document.getElementById(innerBoxName).style.display = "none";
		}
	}
	return false;
	
}


boxVisible = false;

function throwBox(){
	
	ab = document.getElementById(outerBoxName);
	abox = document.getElementById(innerBoxName);

	ab.style.display = "block";
	ab.style.width = getWindowWidth() +"px";
	ab.style.height = getWindowHeight() +"px";
	ab.style.width = Viewport()[0] +"px";
	
	if(Viewport()[1] < getWindowHeight()){
		ab.style.height = getWindowHeight() +"px";
	}else{
		ab.style.height = Viewport()[1] +"px";
	}
	abox.style.visibility = "hidden";
	abox.style.display = "block";
	abox.style.visibility = "visible";
	boxVisible = true;

	checkBox();
}

function hideBox(){
	boxVisible = false;
	opening = false;
	ab = document.getElementById(outerBoxName);
	abox = document.getElementById(innerBoxName);
	ab.style.display = "none";
	abox.style.display = "none";
	movieName = "etusivu";
		
  	if (movieIsLoaded(thisMovie(movieName))) {
    	thisMovie(movieName).playMovie();
  	}
		
}


function checkBox(){
	if(boxVisible){
		ab = document.getElementById(outerBoxName);
		abox = document.getElementById(innerBoxName);
		
		ab.style.width = getWindowWidth() +"px";
		ab.style.height = getWindowHeight() +"px";
		
		ab.style.width = Viewport()[0] +"px";
		ab.style.height = Viewport()[1] +"px";
		
		abox.style.left = getWindowWidth()/2 - getOff(innerBoxName)[0]/2 +"px";
		abox.style.top = getWindowHeight()/2 - getOff(innerBoxName)[1]/2 +"px";
		
		if(abox.style.top.substring(0, abox.style.top.length-2) < 0){
			
			abox.style.top 	= 0;
		}
		if(abox.style.left.substring(0, abox.style.left.length-2) < 0){
			abox.style.left 	= 0;
		}
		
		if(Viewport()[1] < getWindowHeight()){
			ab.style.height = getWindowHeight() +"px";
		}else{
			ab.style.height = Viewport()[1] +"px";
			
			ab.style.width = Viewport()[0] +"px";
			
		}
		
		movieName = "etusivu";
		
  		if (movieIsLoaded(thisMovie(movieName))) {
    		thisMovie(movieName).pauseMovie();
  		}
		

		

	}
}

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (document.all) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}


// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined") {
    // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  } else {
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}


window.onresize = checkBox;

