var webCamLayer =false;
function showNewObject(what){
	document.getElementById(what).style.display = 'block';
}
function hideNewObject(what){
	document.getElementById(what).style.display = 'none';
}

// get window inner Sizes
function getWindowInnerWidth(){
	//mozilla
	if (self.innerWidth){
		width = self.innerWidth;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		width = document.documentElement.clientWidth;
		}
	
	return width;
}
function getWindowInnerHeight(){
	//mozilla
	if (self.innerWidth){
		height = self.innerHeight;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		height = document.documentElement.clientHeight;
		}
	
	return height;
}

/* New Preloader scripts START ------------------------------------------------ */

// simulate preloading
function preloading(title,url){
addNewPreloaderBg();
addNewPreloader(title);

var rannum = Math.floor(Math.random()*1501);
setTimeout(function haveIt() {
 	removeNewPreloader();
	removeNewPreloaderBg();
	loadPage(url);
	},rannum);
}

function loadPage(url){
	window.location = url;	
}

// Add new preloader BG
function addNewPreloaderBg(){
	if(document.documentElement.scrollHeight>getWindowInnerHeight()){
		// for mozilla
		if (self.innerWidth){
			var w = getWindowInnerWidth()-17;
		}
		// for ie
		else if (document.documentElement && document.documentElement.clientWidth){
			var w = getWindowInnerWidth();
		}
		var h = document.documentElement.scrollHeight;
	}
	else{
		var w = getWindowInnerWidth();
		var h = getWindowInnerHeight();
	}
  	var newPreloaderBg = document.createElement('div');
  	newPreloaderBg.id = 'newPreloaderBg';
  	newPreloaderBg.className = 'newPreloaderBgClass';
  	newPreloaderBg.style.width = w+'px';
  	newPreloaderBg.style.height = h+'px';
  	document.body.appendChild(newPreloaderBg);
}

// Remove new preloader BG
function removeNewPreloaderBg(){
  var newPreloaderBg = document.getElementById('newPreloaderBg');
  if ( newPreloaderBg ) document.body.removeChild(newPreloaderBg);
  document.documentElement.scrollTop = 0;
}


// Add new preloader
function addNewPreloader(conti){
	if(!conti){
		conti = '<img src="img/loader4.gif" border="0" alt="" title="" /><br />Kis türelmet...';
	}
  var left = getWindowInnerWidth()/2-95;
  var top = getWindowInnerHeight()/2-45;
  var w = getWindowInnerWidth();
  var h = getWindowInnerHeight();
  var scTop = document.documentElement.scrollTop;
  
  var newPreloader = document.createElement('div');
  newPreloader.id = 'newPreloader';
  newPreloader.className = 'newPreLoaderBoxClass';
  newPreloader.style.left = left+'px';
  newPreloader.style.top = top+scTop+'px';
  newPreloader.innerHTML = '<img src="img/loader4.gif" border="0" alt="" title="" /><br /><span class="loadingItem">'+conti+'</span><br />betöltése folyamatban...';
  document.body.appendChild(newPreloader);
}
// remove Preloader
function removeNewPreloader(){
  var newPreloader = document.getElementById('newPreloader');
  if ( newPreloader ) document.body.removeChild(newPreloader);
}
/* New Preloader scripts END ----------------------------------------------------*/

function iover(image,num){
	image.src = 'img/menu/i'+num+'over.jpg';
}
function iout(image,num){
	image.src = 'img/menu/i'+num+'.jpg';
}

function iovereng(image,num){
	image.src = 'img/menu/i'+num+'engover.jpg';
}
function iouteng(image,num){
	image.src = 'img/menu/i'+num+'eng.jpg';
}

function iovernews(image,num){
	image.src = '../img/menu/i'+num+'over.jpg';
}
function ioutnews(image,num){
	image.src = '../img/menu/i'+num+'.jpg';
}

function ioverengnews(image,num){
	image.src = '../img/menu/i'+num+'engover.jpg';
}
function ioutengnews(image,num){
	image.src = '../img/menu/i'+num+'eng.jpg';
}

/* popup gallery SCRIPTS */
// get window Sizes
function getWindowWidth(){
	//mozilla
	if (self.innerWidth){
		var width = self.outerWidth;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		var width = document.documentElement.clientWidth+28;
		}
	
	return width;
}
function getWindowHeight(){
	//mozilla
	if (self.innerWidth){
		var height = self.outerHeight;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		var height = document.documentElement.clientHeight+134;
		}
	
	return height;
}

function getWindowLeft(){
	//mozilla
	if (self.innerWidth){
		var left = self.screenX;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		var left = self.screenLeft-4;
		}
	
	return left;
}
function getWindowTop(){
	//mozilla
	if (self.innerWidth){
		var top = self.screenY;
		}
	//ie
	else if (document.documentElement && document.documentElement.clientWidth){
		var top = self.screenTop-105;
		}
	
	return top;
}


// the popup script
function openPopupGallery(){
	winWidth = 600;
	winHeight = 500;
	winleft = getWindowLeft();
	wintop = getWindowTop();
	popwinLeft = winleft+getWindowWidth()/2-300;
	popwinTop = wintop+getWindowHeight()/2-250;
	window.open('popup_gallery.html', 'thepopup', 'width='+winWidth+', height='+winHeight+', left='+popwinLeft+', top='+popwinTop+', scrollbars=no');
}

function startWebcamLayer(){
	webCamLayer = true;
	/*winWidth = 660;
	winHeight = 315;
	winleft = getWindowLeft();
	wintop = getWindowTop();
	popwinLeft = winleft+getWindowWidth()/2-330;
	popwinTop = wintop+getWindowHeight()/2-157;
	window.open('webcams_buildingsite.html', 'thepopup', 'width='+winWidth+', height='+winHeight+', left='+popwinLeft+', top='+popwinTop+', scrollbars=no');
	*/
	webcamPos();
	var webcamsframe = document.getElementById('webcamsIframe');
	webcamsframe.src = 'webcams_buildingsite_big.html';	
}

function webcamPos(){
	var oC = document.getElementById('webcamPopup');
	
	if(webCamLayer){
	// get window sizes
	if(document.documentElement.scrollHeight>getWindowInnerHeight()){
		// for mozilla
		if (self.innerWidth){
			var w = getWindowInnerWidth()-17;
		}
		// for ie
		else if (document.documentElement && document.documentElement.clientWidth){
			var w = getWindowInnerWidth();
		}
		var h = document.documentElement.scrollHeight;
	}
	else{
		var w = getWindowInnerWidth();
		var h = getWindowInnerHeight();
	}
	
	oC.style.left = w/2-650+'px';
	oC.style.top = h/2-280+'px';
	oC.style.display = 'block';
	}
}

function hideWebcamLayer(){
	var oC = document.getElementById('webcamPopup');
	oC.style.display = 'none';
	var webcamsframe = document.getElementById('webcamsIframe');
	webcamsframe.src = '';
	webCamLayer = false;
	//window.setTimeout('clearCameras()',3000);
}

function pushCameraContent(num){
	
	if(num==5 || num==6){
	var camcenter = document.getElementById('camcenter');
	var menu5 = document.getElementById('menu5');
	var menu6 = document.getElementById('menu6');
	camcenter.style.display = 'none';
	}
	else{
	var camleft = document.getElementById('camleft');
	var camright = document.getElementById('camright');
	
	var menu1 = document.getElementById('menu1');
	var menu2 = document.getElementById('menu2');
	var menu3 = document.getElementById('menu3');
	var menu4 = document.getElementById('menu4');
	
	camleft.style.display = 'none';
	camright.style.display = 'none';
	}
	
	cameraLoader(true);
	
	if(num==1){
	menu1.src = 'img/webcammenu/i1bigactive.jpg';
	menu2.src = 'img/webcammenu/i2big.jpg';
	menu3.src = 'img/webcammenu/i3big.jpg';
	menu4.src = 'img/webcammenu/i4big.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camleft.innerHTML = getJavaAppletSource(1);
		camright.innerHTML = getJavaAppletSource(2);
		camleft.style.display = 'block';
		camright.style.display = 'block';
	},100);
	}
	else if(num==2){
	menu1.src = 'img/webcammenu/i1big.jpg';
	menu2.src = 'img/webcammenu/i2bigactive.jpg';
	menu3.src = 'img/webcammenu/i3big.jpg';
	menu4.src = 'img/webcammenu/i4big.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camleft.innerHTML = getJavaAppletSource(3);
		camright.innerHTML = getJavaAppletSource(4);
		camleft.style.display = 'block';
		camright.style.display = 'block';
	},100);
	}
	else if(num==3){
	menu1.src = 'img/webcammenu/i1big.jpg';
	menu2.src = 'img/webcammenu/i2big.jpg';
	menu3.src = 'img/webcammenu/i3bigactive.jpg';
	menu4.src = 'img/webcammenu/i4big.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camleft.innerHTML = getJavaAppletSource(5);
		camright.innerHTML = getJavaAppletSource(6);
		camleft.style.display = 'block';
		camright.style.display = 'block';
	},100);
	}
	else if(num==4){
	menu1.src = 'img/webcammenu/i1big.jpg';
	menu2.src = 'img/webcammenu/i2big.jpg';
	menu3.src = 'img/webcammenu/i3big.jpg';
	menu4.src = 'img/webcammenu/i4bigactive.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camleft.innerHTML = getJavaAppletSource(7);
		camright.innerHTML = getJavaAppletSource(8);
		camleft.style.display = 'block';
		camright.style.display = 'block';
	},100);
	}
	else if(num==5){
	//menu5.src = 'img/webcammenu/i5bigactive.jpg';
	//menu6.src = 'img/webcammenu/i6big.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camcenter.innerHTML = getJavaAppletSource(9);
		camcenter.style.display = 'block';
		},100);
	}
	else if(num==6){
	//menu5.src = 'img/webcammenu/i5big.jpg';
	//menu6.src = 'img/webcammenu/i6bigactive.jpg';
	window.setTimeout(function (){
		cameraLoader(false);
		camcenter.innerHTML = getJavaAppletSource(10);
		camcenter.style.display = 'block';
	},100);
	}
}

function clearCameras(){
	var camleft = document.getElementById('camleft');
	var camright = document.getElementById('camright');
	
	camleft.innerHTML = '';
	camright.innerHTML = '';
}

function cameraLoader(val){
	var cameraLoader = document.getElementById('loader');
	
	if(val){
		cameraLoader.style.display = 'block';
	}
	else{
		cameraLoader.style.display = 'none';
	}
}

function getJavaAppletSource(num){

	// Set the BaseURL to the URL of your camera
	//var BaseURL = 'http://192.168.100.'+num+'/';
	var BaseURL = 'http://neo.composeit.hu:23'+num+'/';
	
	// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
	// You may change these numbers, the effect will be a stretched or a shrunk image
	var DisplayWidth = "640";
	var DisplayHeight = "480";

	// This is the path to the image generating file inside the camera itself
	var File = "axis-cgi/mjpg/video.cgi?resolution=320x240&compression=50";
	// No changes required below this point
	var output = "";
	var AppletDir = BaseURL + "java/ama";
	var VideoPath = "axis-cgi/mjpg/video.cgi?resolution=";
	var restOfPath = "&compression=50";
	var VideoURL = BaseURL + VideoPath;

	output  = '<APPLET archive="ama.jar" codeBase="';
	output += AppletDir + '"';
	output += ' code="ama.MediaApplet" height="';
	output += DisplayHeight;
	output += '" width="';
	output += DisplayWidth;
	output += '">';
	output += '<PARAM NAME="code" VALUE="ama.MediaApplet">';
	output += '<PARAM NAME="archive" VALUE="ama.jar">';
	output += '<PARAM NAME="codebase" VALUE="';
	output += AppletDir + '">';
	output += '<PARAM NAME="ama_cgi-path" VALUE="axis-cgi">';
	output += '<PARAM NAME="cache_archive" VALUE="ama.jar">';
	output += '<PARAM NAME="cache_version" VALUE="1.1.0.0">';
	output += '<PARAM NAME="ama_plugins" VALUE="">';
	output += '<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">';
	output += '<PARAM NAME="ama_url" VALUE="';
	output += VideoURL;
	output += DisplayWidth + 'x' + DisplayHeight;
	output += restOfPath +'">';
	output += '</APPLET>'
	//alert(output);
	return output;
}

function getQuickTimeSource(num){

// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
// You may change these numbers, the effect will be a stretched or a shrunk image
var DisplayWidth = 320;
var DisplayHeight = 240;

// This is the URL of the generated media.
var MediaURL = 'rtsp://192.168.100.'+num+':554/mpeg4/media.amp';

var output = "";

output  = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width=';
output += DisplayWidth;
output += ' height=';
output += DisplayHeight;
output += ' CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">';
output += '<param name="src" value="AxisMoviePoster.mov">';
output += '<param name="autoplay" value="true">';
output += '<param name="controller" value="false">';
output += '<param name="qtsrc" value="';
output += MediaURL;
output += '">';
output += '<embed src="AxisMoviePoster.mov" width=';
output += DisplayWidth;
output += ' height=';
output += DisplayHeight;
output += ' qtsrc="';
output += MediaURL;
output += '" autoplay="true" controller="false" target="myself"';
output += ' PLUGINSPAGE="http://www.apple.com/quicktime/download/"></embed>';
output += '</OBJECT>';
return output;
}

function getCameraImages(num){
// Set the BaseURL to the URL of your camera
var BaseURL = 'http://192.168.100.'+num+'/';

// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
// You may change these numbers, the effect will be a stretched or a shrunk image
var DisplayWidth = "320";
var DisplayHeight = "240";

// This is the path to the image generating file inside the camera itself
var File = "axis-cgi/jpg/image.cgi?resolution=320x240";

// Force an immediate image load
var theTimer = setTimeout('reloadImage()', 1);

function reloadImage()
{
  theDate = new Date();
  var url = BaseURL;
  url += File;
  url += '&dummy=' + theDate.getTime().toString(10);
  // The dummy above enforces a bypass of the browser image cache
  // Here we load the image
  document.theImage.src = url;

  // Reload the image every ten seconds (10000 ms)
  theTimer = setTimeout('reloadImage()', 500);
}

var string = '';
string = '<img name="theImage" src="'+url+'" height="' + DisplayHeight + '"';
string += 'width="' + DisplayWidth + '" alt="Live image">';
//document.write('<img name="theImage" src="" height="' + DisplayHeight + '"');
//document.write('width="' + DisplayWidth + '" alt="Live image">');
alert(string);
return string;
}
