setBackground();

var resumeAudio = true;
var currentPhotoNo = -1;
/*audioOffImage = new Image();
audioOffImage.src = 'images/teaser/Sound_OFF.png';
audioOnImage = new Image();
audioOnImage.src = 'images/teaser/Sound_ON.png';*/
closeImage = new Image();
closeImage.src = 'images/trailer/Close_1.png';
closeOverImage = new Image();
closeOverImage.src = 'images/trailer/Close_2.png';

function getFlashMovieObject(movieName){
  if (window.document[movieName]){
	return window.document[movieName];
  }else{
//      if (navigator.appName.indexOf("Microsoft Internet")==-1){
//        if (document.embeds && document.embeds[movieName])
//          return document.embeds[movieName];
//      }
//      else{ // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	return document.getElementById(movieName);
  }
}
function muteSound(byHand){
  if (byHand == 1){
	resumeAudio = false;
  }
	var flashMovie=getFlashMovieObject('teaserTop');
	if (flashMovie!=null){
	 flashMovie.GotoFrame(2);
  }
	var audioButton = document.getElementById('audioButton');
	if (audioButton!=null){
		audioButton.src = audioOffImage.src;
	}
	var audioLink = document.getElementById('audioLink');
	if (audioLink!=null){
		audioLink.href = 'javascript:unMuteSound(true)';
	}
}
function unMuteSound(byHand){
	if (resumeAudio || byHand){
		var flashMovie=getFlashMovieObject('teaserTop');
		if (flashMovie!=null){
			flashMovie.Rewind();
		}
		var audioButton = document.getElementById('audioButton');
		if (audioButton!=null){
			audioButton.src = audioOnImage.src;
		}
		var audioLink = document.getElementById('audioLink');
		if (audioLink!=null){
			audioLink.href = 'javascript:muteSound(true)';
		}
		resumeAudio = true;
	}
}
// get the event object with compatibility for IE and FireFox
function getEvent() {
	return window.event || arguments.callee.caller.arguments[0];
}
function goRegistration(){
  window.location = 'index.php?ac=main';
}
function checkEssentials(alertBoxTitle, alertBoxOK, TeaserFCName,TeaserFCPwd){
  var isValid = true;
  if (document.teaserForm.user.value.trim()==''){
	alertBox(alertBoxTitle ,TeaserFCName, alertBoxOK);
	document.teaserForm.user.value = '';
	setTimeout('document.teaserForm.user.focus()',10);
	isValid = false;
  }else if (document.teaserForm.password.value.trim()==''){
	alertBox(alertBoxTitle ,TeaserFCPwd, alertBoxOK);
	document.teaserForm.password.value = '';
	setTimeout('document.teaserForm.password.focus()',10);
	isValid = false;
  }
  if (isValid){
	document.teaserForm.submit();
	document.getElementById('BtnSendCell').style.visibility = 'hidden';
	document.getElementById('BtnSendClick').onclick='';
	return true;
  }else{
	return false;
  }
}
function showDetails(section, photoNo, serverurl, language){
	if (section == 'trailer'){
		w = 600;
		h = 440;
	}else if (section == 'photo'){
		w = 600;
		h = 890;
	}

	var popup = document.getElementById('popup');
	var wholeBody = document.getElementById('wholeBody');
	var trailer = document.getElementById('trailer');
	var photo = document.getElementById('photo');
	var mask = document.getElementById('mask');
	if (photoNo==0 && photo!=null && trailer==null){
	//Switch to Trailer section
	document.body.removeChild(popup);
	popup = null;
	currentPhotoNo = -1;
	}else if (photoNo==0 && trailer!=null){
	//Watch Trailer button is pressed again
	document.body.removeChild(popup);
	if (mask!=null){
		mask.style.cssText = '';
	}
	currentPhotoNo = -1;
	unMuteSound(resumeAudio);
	}else if (photoNo!=0 && photo==null && trailer!=null){
	//Switch to Photo section
	document.body.removeChild(popup);
	popup = null;
	currentPhotoNo = -1;
	unMuteSound(resumeAudio);
	}else if (photoNo!=0 && currentPhotoNo == photoNo){
	//Photo sections with same photo
	document.body.removeChild(popup);
	if (mask!=null){
		mask.style.cssText = '';
	}
	currentPhotoNo = -1;
	unMuteSound(resumeAudio);
	}else if (photo!=null){
	//Photo sections with different photos
	currentPhotoNo = photoNo;
	unMuteSound(resumeAudio);
	photo.setAttribute('src','teaser/teaser_screenshot.php?shot='+photoNo);
	}

	var titleheight = '22px'; // popup window - table title height
//	var titlebgcolor = "#ff0000"; // popup window - table title bgcolor
	var bordercolor = '#000000'; // popup window - table border color
	var titlecolor = '#FFFFFF'; // popup window - table border title
//			var bgcolor = "transparent"; // popup window - table bgcolor
	var bgcolor = '#000000'; // popup window - table bgcolor

	var iWidth = 1024, iHeight = 768;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		iWidth = window.innerWidth;
		iHeight = window.innerHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		iWidth = document.body.clientWidth;
		iHeight = document.body.clientHeight;
	}

	//Create the mask
	if (mask==null || mask.style.cssText==''){
		var bgObj = document.createElement('div');
		bgObj.id = 'mask';
		bgObjHeight = document.documentElement.scrollHeight;
//				alert(bgObjHeight);
		bgObj.style.cssText = 'position:absolute;left:0px;top:0px;width:100%;height:'+bgObjHeight+'px;filter:Alpha(Opacity=60);opacity:0.6;background-color:#000000;z-index:101;margin: 0px; padding: 0px';
		document.body.appendChild(bgObj);
		mask = bgObj;
	}

	//Create the popup
	if (popup==null){
		var msgObj=document.createElement('div');
		msgObj.id = 'popup';

		//frame for trailer and photos
		msgObj.style.cssText = 'position:absolute;font:11px;top:21px;left:'+((iWidth-w)/2)+'px;width:'+w+'px;height:15px;text-align:center;border:1px solid '+bordercolor+';background-color:'+bgcolor+';line-height:22px;z-index:102;margin:0px;padding:0px;';
		document.body.appendChild(msgObj);
		for (var i=16;i<=h;i++){
			setTimeout('document.getElementById(\''+msgObj.id+'\').style.height = \''+i+'px\'', 1000+i*2);
		}
		var table = document.createElement('table');
		msgObj.appendChild(table);
		table.style.cssText = 'margin:0px;border:0px;padding:0px;';
		table.cellSpacing = 0;
		//Create the popup title bar
		var tr = table.insertRow(-1);
		var titleBar = tr.insertCell(-1);
		titleBar.style.cssText = 'width:100%;height:'+titleheight+'px;margin:0px;border:0px solid ' + bordercolor + ';cursor:move;background-image:url(images/trailer/Loop_Video_bar.png);background-position:top center';//background-color:" + titlebgcolor;
		titleBar.style.paddingLeft = '10px';
		//	titleBar.innerHTML = title;
		var moveX = 0;
		var moveY = 0;
		var moveTop = 0;
		var moveLeft = 0;
		var moveable = false;
		var docMouseMoveEvent = document.onmousemove;
		var docMouseUpEvent = document.onmouseup;
		titleBar.onmousedown = function() {
			var evt = getEvent();
			moveable = true;
			moveX = evt.clientX;
			moveY = evt.clientY;
			moveTop = parseInt(msgObj.style.top);
			moveLeft = parseInt(msgObj.style.left);

			document.onmousemove = function() {
				if (moveable) {
					var evt = getEvent();
					var x = moveLeft + evt.clientX - moveX;
					var y = moveTop + evt.clientY - moveY;
					if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) {
						msgObj.style.left = x + 'px';
						msgObj.style.top = y + 'px';
					}
				}
			};
			document.onmouseup = function () {
				if (moveable) {
					document.onmousemove = docMouseMoveEvent;
					document.onmouseup = docMouseUpEvent;
					moveable = false;
					moveX = 0;
					moveY = 0;
					moveTop = 0;
					moveLeft = 0;
				}
			};
		}
		//Create the popup close button
		var closeBtn = tr.insertCell(-1);
		closeBtn.style.cssText = 'cursor:pointer; padding:0px;';//background-color:" + titlebgcolor;
		closeBtn.style.backgroundImage = 'url(images/trailer/Loop_Video_bar.png)';
		closeBtn.style.textAlign = 'right';
		closeBtn.innerHTML = "<img onmouseover='this.src=\"" + closeOverImage.src + "\"' onmouseout='this.src=\"" + closeImage.src + "\"' src='images/trailer/Close_1.png' alt='' border='0'/>";
		closeBtn.onclick = function(){
			document.body.removeChild(msgObj);
			if (mask!=null){
				mask.style.cssText = '';
			}
			unMuteSound(resumeAudio);
			currentPhotoNo = -1;
		}

		//create the box
		var msgBox = table.insertRow(-1).insertCell(-1);
		msgBox.id = 'msgBox';
		msgBox.style.cssText = 'font:10pt;background-color:#000000;';
		msgBox.colSpan  = 2;
		if (section == 'trailer'){
			msgBox.innerHTML = "<iframe id='trailer' name='trailer' src='teaser/trailer.php?serverurl="+serverurl+"&language="+language+"' scrolling='no' allowTransparency='true' frameBorder='0' width='"+w+"' height='0'></iframe>";
			for (var i=1;i<=h;i++){
				setTimeout("document.getElementById('trailer').style.height = '"+i+"px'", 1000+i*1.5);
			}
			muteSound(0);
		}else if (section == 'photo'){
			msgBox.innerHTML = "<iframe id='photo' name='photo' src='teaser/teaser_screenshot.php?shot="+photoNo+"' scrolling='no' allowTransparency='true' frameBorder='0' width='"+w+"' height='0'></iframe>";
			currentPhotoNo = photoNo;
			for (var i=1;i<=h;i++){
				setTimeout("document.getElementById('photo').style.height = '"+i+"px'", 1000+i);
			}
		}
	}
}