//<![CDATA[

/* LICENSE (BSD)

Copyright (c) 2005, Fabricio Zuardi
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//for debugging
function trace(p_msg){
	document.getElementById('debug_output').value += p_msg +"\n";
}

function clearOutput(){
	document.getElementById('debug_output').value = "";
}


//Constants
var k_LOCATIONS = [];
	k_LOCATIONS["sao carlos"] = new GPoint(-22.533056,-51.983056)
	k_LOCATIONS["ribeirao preto"] = new GPoint(-21.066667,-47.833056)
	k_LOCATIONS["san fransico airport"] = new GPoint(-122.380003,37.607339)
	k_LOCATIONS["Microsoft Corporation"] = new GPoint(-122.127615,47.640699)
	k_LOCATIONS["Microsoft Corporation Top"] = new GPoint(-122.127615,47.641350)
	k_LOCATIONS["Microsoft Corporation Bottom"] = new GPoint(-122.127615,47.640114)
	k_LOCATIONS["Microsoft Corporation Left"] = new GPoint(-122.127725,47.640699)
	k_LOCATIONS["Microsoft Corporation Right"] = new GPoint(-122.127521,47.640699)
	k_LOCATIONS["Drop Zone"] = new GPoint(-122.127615,47.632611550290667362371)
	k_LOCATIONS["Drop Zone Screen Center"] = new GPoint(-122.127615,47.633509532569676)
	k_LOCATIONS["Parachutist read point"] = new GPoint(-122.127615,47.632)
	k_LOCATIONS["Starting point"] = new GPoint(-122.127615,47.6)
var k_PARACHUTIST_WIDTH = 69
var k_PARACHUTIST_HEIGHT = 64
var k_PARACHUTIST_MIN_WIDTH = 12;
var k_PARACHUTIST_MIN_HEIGHT = 11;
var k_DEFAULT_CLOUDS_FREQUENCY = 1//clouds per minute (layer 1)
var k_DEFAULT_CLOUDS2_FREQUENCY = 2//clouds per minute (layer 2)
var k_BRIEFING1 = "";
k_BRIEFING1 += "<h1>\n"
k_BRIEFING1 += "	Briefing:\n"
k_BRIEFING1 += "</h1>\n"
k_BRIEFING1 += "<p>\n"
k_BRIEFING1 += "	Good afternoon. You are now flying over Phantom Lake at\n"
k_BRIEFING1 += "	latitude 47 and longitude approximately -122. At this point, your\n"
k_BRIEFING1 += "	altitude is kept under 6K miles, to avoid detection by radar.\n"
k_BRIEFING1 += "</p>\n"
k_BRIEFING1 += "<p>\n"
k_BRIEFING1 += "	In about 4 minutes, you should infiltrate the airspace of a large\n"
k_BRIEFING1 += "	corporation taken by unsafe undisclosed forces. Allied forces found\n"
k_BRIEFING1 += "	evidence that a number of OSes are infected and multiple viruses have taken\n"
k_BRIEFING1 += "	over the entire network.\n"
k_BRIEFING1 += "</p>\n"
k_BRIEFING1 += "<p class=\"paginate\"><a href=\"javascript:nextPage()\">next</a></p>\n"

var k_BRIEFING2 = "";
k_BRIEFING2 += "<p>\n"
k_BRIEFING2 += "	Your mission is to reach their hub center before the unsafe agent\n"
k_BRIEFING2 += "	spreads to other networks. To accomplish this mission, you have\n"
k_BRIEFING2 += "	been escalated as the commander to the officers on board. You should\n"
k_BRIEFING2 += "	use the pilot engineer <a href=\"javascript:changeCamera(1)\">Billy-goat</a> to reach the first target as you approach NE\n"
k_BRIEFING2 += "	24th st, also called the Drop Zone. As you reach this point, the\n"
k_BRIEFING2 += "	parachutist engineer <a href=\"javascript:changeCamera(2)\">Albatross</a> should be released to reach the installation zone\n"
k_BRIEFING2 += "	- the actual roof of building 3.\n"
k_BRIEFING2 += "</p>\n"
k_BRIEFING2 += "<p>\n"
k_BRIEFING2 += "	When accomplish successfully, the parachutist can take\n"
k_BRIEFING2 += "	it from there. This step should be smooth, however, make sure that he\n"
k_BRIEFING2 += "	carries the software CD. The installation process will be\n"
k_BRIEFING2 += "	straightforward as the application has only 8.6 Megabytes.\n"
k_BRIEFING2 += "</p>\n"
k_BRIEFING2 += "<p class=\"paginate\"><a href=\"javascript:previousPage()\">previous</a> | <a href=\"javascript:nextPage()\">next</a></p>\n"

var k_BRIEFING3 = "";
k_BRIEFING3 += "<p>\n"
k_BRIEFING3 += "	It's not necessary to tell you that this mission is not officially\n"
k_BRIEFING3 += "	authorized. If any of you gets exposed or KIA, our organization will\n"
k_BRIEFING3 += "	deny everything, including and as you may guess, your existence.\n"
k_BRIEFING3 += "</p>\n"
k_BRIEFING3 += "<p>\n"
k_BRIEFING3 += "</p>\n"
k_BRIEFING3 += "	Proceed with caution.\n"
k_BRIEFING3 += "<p>\n"
k_BRIEFING3 += "	<a href=\"javascript:changeCamera(0)\">Colonel Clint</A>.<br />\n"
k_BRIEFING3 += "	GeekForce Alliance\n"
k_BRIEFING3 += "</p>\n"
k_BRIEFING3 += "<p>\n"
k_BRIEFING3 += "<small>\n"
k_BRIEFING3 += "	ssh-dss AAAAB3NzaC1kc3MAAACBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9EAMMe\n"
k_BRIEFING3 += "	P4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f6AR7\n"
k_BRIEFING3 += "	ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv8iID\n"
k_BRIEFING3 += "	GZ3RSAHHAAAAFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QAAAIEA9+GghdabPd7LvKtc\n"
k_BRIEFING3 += "	NrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwky\n"
k_BRIEFING3 += "	jMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/h\n"
k_BRIEFING3 += "	WuWfBpKLZl6Ae1UlZAFMO/7PSSoAAACAVfzHKMLqKPARgwVSoFB1yrIPn/IkVi7u\n"
k_BRIEFING3 += "	UbfO9onhG6jgB7LiogKHoJ5410uZQxBnvGEsE8U/BRrqq/w3iJL9U5U7+TRZpuV7\n"
k_BRIEFING3 += "	U9G4ADoK5FzaS9/DLBW27+J1sIS0wAHO9wbDgPHMwEUCEJD/BrvNiA2INjTYXVba\n"
k_BRIEFING3 += "	4C7oRtB6T5c= DSA-1024\n"
k_BRIEFING3 += "</small>\n"
k_BRIEFING3 += "</p>\n"
k_BRIEFING3 += "<p class=\"paginate\"><a href=\"javascript:previousPage()\">previous</a> | <a href=\"javascript:closeText()\">close!</a></p>\n"

//k_BRIEFING1 = "";

//Variables
var vel_h = 0.00001;			//horizontal speed of the map
var vel_v = 0.00002;			//vertical speed of the map (only when the jet hit the borders
var bg										//main map
var jet										//jet div element
var parachutist
var parachutist_img
var para_w
var para_h
var cloud1								//cloud layer 1 div
var cloud2								//cloud layer 2 div
var cloud3								//cloud layer 3 div
var manche_form						//manche radiogroup
var target_marker					//marker of the goal (microsoft building)
var drop_zone_marker
var clouds_button
var lat_display
var lon_display
var cam_1_btn
var cam_2_btn
var cam_3_btn
var writing_text = "";
var current_text = ""
var current_page
var tvback
var tvnoise1
var jet_x										//left position of the jet
var jet_y										//top position of the jet
var para_x
var para_y
var jet_frame								//current frame of the jet rotation sequence (-8 to +8, 19 frames)
var jet_v_rot								//intensity of the rotation (0 to 2)
var jet_s_rot								//direction of the rotation (-1 or 1, left/right)
var cloud1_x								//left position of the cloud layer 1
var cloud1_y								//top position of the cloud layer 1
var cloud2_x								//left position of the cloud layer 2
var cloud2_y								//top position of the cloud layer 2
var cloud3_x								//left position of the cloud layer 2
var cloud3_y								//top position of the cloud layer 2
var clouds_moving
var parachutist_read
var long_difference
var drop_long
var landing_interface
var tv_parachutist


function resetVars(){
	jet_x = para_x = 150;
	jet_y = para_y = 470;
	para_w = k_PARACHUTIST_WIDTH
	para_h = k_PARACHUTIST_HEIGHT
	jet_frame = 0;
	jet_v_rot = 0;
	jet_s_rot = 1;
	cloud1_x = 0;
	cloud1_y = -1200;
	cloud2_x = 0;
	cloud2_y = -1600;
	cloud3_x = 0;
	cloud3_y = -1900;
	cloud_count = 0;
	cam_1_btn.className = "on";
	cam_2_btn.className = "off";
	cam_3_btn.className = "off";
	jet.style.left = jet_x+"px";
	jet.style.top = jet_y+"px";
	parachutist.style.left = para_x+"px";
	parachutist.style.top = para_y+"px";
	parachutist_img.style.width = para_w+"px";
	parachutist_img.style.height = para_h+"px";
	jet.style.backgroundPosition = "-800px"
	cloud1.style.left = cloud1_x+"px";
	cloud1.style.top = cloud1_y+"px";
	cloud2.style.left = cloud2_x+"px";
	cloud2.style.top = cloud2_y+"px";
	cloud3.style.left = cloud3_x+"px";
	cloud3.style.top = cloud3_y+"px";
	manche_form.radiogroup[2].checked = true
	clouds_moving = true;
	parachutist_read = false;
}

//Initialize function
function init(){
	if (GBrowserIsCompatible()) {
		briefing = document.getElementById("briefing")
		bg = new GMap(document.getElementById("bg"));
		jet = document.getElementById("jet")
		parachutist = document.getElementById("parachutist")
		parachutist_img = document.getElementById("parachutist_img")
		cloud1 = document.getElementById("cloud1")	
		cloud2 = document.getElementById("cloud2")	
		cloud3 = document.getElementById("cloud3")	
		clouds_button = document.getElementById("clouds_btn")	
		lat_display = document.getElementById("lat_display")
		lon_display = document.getElementById("lon_display")
		cam_1_btn = document.getElementById("cam_1")
		cam_2_btn = document.getElementById("cam_2")
		cam_3_btn = document.getElementById("cam_3")
		manche_form = document.forms.manche
		tvback = document.getElementById('tvback');
		tvnoise1 = document.getElementById('tv_noise1');
		landing_interface = document.getElementById('landing_interface');
		tv_parachutist = document.getElementById('tv_parachutist');
		
		bg.disableDragging();
		bg.centerAndZoom(k_LOCATIONS["Starting point"], 0);
		bg.setMapType(G_SATELLITE_TYPE)
		target_marker = new GMarker(k_LOCATIONS["Microsoft Corporation"]);


		long_difference = k_LOCATIONS["Microsoft Corporation"].y - k_LOCATIONS["Drop Zone Screen Center"].y
		
		// Dropzone customized marker icon
		var drop_zone_icon = new GIcon();
		drop_zone_icon.image = "dropzone.png";
		drop_zone_icon.iconSize = new GSize(300, 300);
		drop_zone_icon.iconAnchor = new GPoint(150, 150);
		drop_zone_icon.infoWindowAnchor = new GPoint(150, 150);	
		drop_zone_icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		drop_zone_icon.shadowSize = new GSize(22, 20);	
		
		drop_zone_marker = new GMarker(k_LOCATIONS["Drop Zone"],drop_zone_icon);
		drop_zone_marker2 = new GMarker(k_LOCATIONS["Drop Zone"]);
  	bg.addOverlay(target_marker);
  	bg.addOverlay(drop_zone_marker);
  	bg.addOverlay(drop_zone_marker2);
		document.onkeydown = keyDown;
	}else{
		alert('your browser dont support gmaps, sorry')
	}
}

//Game Start
function start(){
		var opacity_layer = document.getElementById('opacity_layer')
		var start_screen = document.getElementById('start_screen')
		opacity_layer.style.display = "none";
		start_screen.style.display = "none";
		bg.centerAndZoom(k_LOCATIONS["Starting point"], 0);
		resetVars();
		scrollMap();
		jetRender();
		sendClouds();
		hideClouds(true);
		current_text = "k_BRIEFING"
		current_page = 1;
		showText();
		//tvNoise()
}

function showText(){
	writing_text = this[current_text+current_page].substr(0,writing_text.length+7);
	briefing.innerHTML = writing_text;
	if(writing_text.length<this[current_text+current_page].length){
		setTimeout("showText()",50); 
	}else{
		var links_ar = briefing.getElementsByTagName('a');
		for(var i in links_ar){
			links_ar[i].className = "on"
		}
	}
}

function previousPage(){
	writing_text = ""
	current_page--;
	showText()
}

function nextPage(){
	writing_text = ""
	current_page++;
	showText()
}

function closeText(){
	briefing.innerHTML = "";
	hideClouds(false);
}

function scrollMap(){
	var interval = 200;
	var para_factor = 1;
	var new_latlng = bg.getCenterLatLng()
	//is not at the goal yet
	//if((new_latlng.y < k_LOCATIONS["Microsoft Corporation"].y)&&(para_h>k_PARACHUTIST_MIN_HEIGHT)){
	if(para_h>k_PARACHUTIST_MIN_HEIGHT){
		//when on the borders of the screen, move the map also
		if(((jet_x <60)||(jet_x >220))&&(parachutist.style.display!="block")){
			new_latlng.x += vel_h*jet_frame;
			cloud1_x -= jet_frame/2; 
			cloud2_x -= jet_frame/2; 
			cloud3_x -= jet_frame/2; 
			//trace('jet.style.display:'+jet.style.display)
		}
		//parachutist released
		if (parachutist.style.display=="block"){
			//para_factor = (para_h-k_PARACHUTIST_MIN_HEIGHT)/(k_PARACHUTIST_HEIGHT-k_PARACHUTIST_MIN_HEIGHT)
			para_factor = (new_latlng.y - drop_long) / long_difference;
			para_y = 470 -((98+k_PARACHUTIST_MIN_HEIGHT)*(para_factor))
			parachutist.style.top = para_y+"px"
			//para_w -= 0.15;
			//para_h -= 0.15;
			para_w = k_PARACHUTIST_WIDTH - para_factor*(k_PARACHUTIST_WIDTH-k_PARACHUTIST_MIN_WIDTH)
			para_h = k_PARACHUTIST_HEIGHT - para_factor*(k_PARACHUTIST_HEIGHT-k_PARACHUTIST_MIN_HEIGHT)
			parachutistRender()
			new_latlng.x += (vel_h/10)*(jet_frame*-1);
		}else if(!parachutist_read){
			if(new_latlng.y>=k_LOCATIONS["Parachutist read point"].y){
				changeCamera(3);
				parachutist_read = true;
			}
		}
		new_latlng.y += vel_v;
		bg.recenterOrPanToLatLng(new_latlng)
		lat_display.value = "lat:"+new_latlng.x;
		lon_display.value = "lon:"+new_latlng.y;
		setTimeout("scrollMap()",interval); 
	}else{
		//stop map scroll
		//alert('diference '+(k_LOCATIONS["Microsoft Corporation"].y - new_latlng.y))
		var land_lat_lang = bg.getCenterLatLng();
		if(
			(land_lat_lang.y<k_LOCATIONS["Microsoft Corporation Top"].y)&&
			(land_lat_lang.y>k_LOCATIONS["Microsoft Corporation Bottom"].y)&&
			(land_lat_lang.x>k_LOCATIONS["Microsoft Corporation Left"].x)&&
			(land_lat_lang.x<k_LOCATIONS["Microsoft Corporation Right"].x)
			){
			var htmlStr = '<img src="zuardinewspaper_small.jpg" width="300" height="206"><p style="width:300px;">Congratulations, you managed to clean the unsafe threat. MISSION ACCOMPLISHED!<br>diference = '+(k_LOCATIONS["Microsoft Corporation"].y - new_latlng.y)+'</p>';
		}else{
			var htmlStr = '<div style="width:300px;">You landed outside of the target and got caught.<br> MISSION FAILED.</div>';
		}
		var html_element = document.createElement('div')
		html_element.innerHTML = htmlStr;
		//var land_marker = new GMarker(bg.getCenterLatLng());
		//bg.openInfoWindow(bg.getCenterLatLng(),document.createTextNode('diference = '+(k_LOCATIONS["Microsoft Corporation"].y - new_latlng.y)));
		//bg.openInfoWindowHtml(land_marker,htmlStr);
		bg.openInfoWindow(bg.getCenterLatLng(),html_element);
		parachutist_img.style.display = "none";
		clouds_moving = false;
	}
}

function jetRender(){
	var interval = 50*(3-jet_v_rot)
	//plane is turning
	if(jet_v_rot>0){
		//change frame (if possible)
		if((jet_frame + jet_s_rot>=-8)&&(jet_frame + jet_s_rot<=8)){
			jet_frame += jet_s_rot;
			jet.style.backgroundPosition = (-800-jet_frame*100)+"px"
		}
	}
	//move the jet horizontally according to the rotation
	jet_x += (jet_frame/2);
	jet.style.left = jet_x+"px"
	
	//parachutist released
	if(parachutist.style.display=="block"){
		jet_y -= 30;
		jet.style.top = jet_y+"px"
		if((jet_y<0)||(jet_x<-90)||(jet_x>400)){
			jet.style.display="none"
			landing_interface.style.display="block"
			return null;
		}
	}
	setTimeout("jetRender()",interval); 
}


function dropParachutist(){
	changeCamera(4);
	para_x = jet_x;
	parachutist.style.left = para_x+"px"
	parachutist.style.display="block"
	trace('lat: '+lat_display.value)
	trace('lon: '+lon_display.value)
	drop_long = bg.getCenterLatLng().y;
	parachutistRender();
	
}
function parachutistRender(){
	if(para_h>k_PARACHUTIST_MIN_HEIGHT){
		parachutist_img.style.width = para_w+"px";
		parachutist_img.style.height = para_h+"px";
	}
	//parachutist is turning
	if(jet_v_rot>0){
		//change frame (if possible)
		if((jet_frame + jet_s_rot>=-8)&&(jet_frame + jet_s_rot<=8)){
			jet_frame += jet_s_rot;
			tv_parachutist.style.backgroundPosition = (-1120-jet_frame*140)+"px"
		}
	}
}

function turnParachutist(p_value){
	for(var i=0; i< manche_form.radiogroup.length; i++){
		if(manche_form.radiogroup[i].checked){
			var selected = i
		}
	}
	if(((selected+p_value)>=0)&&((selected+p_value)<=4)){
		manche_form.radiogroup[selected+p_value].checked = true
		var manche_pos = (selected+p_value)-2;
		jet_v_rot = Math.abs(manche_pos)
		jet_s_rot = manche_pos/jet_v_rot
	}
}


function hideClouds(p_hide){
	if(p_hide){
		cloud1.style.display = "none"
		cloud2.style.display = "none"
		cloud3.style.display = "none"
		clouds_button.className = "off";
	}else{
		cloud1.style.display = "block"
		cloud2.style.display = "block"
		cloud3.style.display = "block"
		clouds_button.className = "on";
	}

}

function scrollCloud1	(){
	if(cloud1_y<=470){
		cloud1_y += 4; 
		cloud1.style.top = cloud1_y+"px";
		cloud1.style.left = cloud1_x+"px";
	}else{
		cloud1_y = -1200;
		cloud1_x = Math.random()*400 - 220;
	}
	if(clouds_moving){
		setTimeout("scrollCloud1()",70); 
	}
}

function scrollCloud2	(){
	if(cloud2_y<=470){
		cloud2_y += 25; 
		cloud2.style.top = cloud2_y+"px";
		cloud2.style.left = cloud2_x+"px";
	}else{
		cloud2_y = -1600;
		cloud2_x = Math.random()*400 - 180;
	}
	if(clouds_moving){
		setTimeout("scrollCloud2()",100); 
	}
}
function scrollCloud3	(){
	if(cloud3_y<=470){
		cloud3_y += 30; 
		cloud3.style.top = cloud3_y+"px";
		cloud3.style.left = cloud3_x+"px";
	}else{
		cloud3_y = -1900;
	cloud3_x = Math.random()*400 - 200;
	}
	if(clouds_moving){
		setTimeout("scrollCloud3()",50); 
	}
}

function sendClouds(){
	cloud1_x = Math.random()*400 - 220;
	scrollCloud1();
	cloud2_x = Math.random()*400 - 180;
	scrollCloud2();
	cloud3_x = Math.random()*400 - 200;
	scrollCloud3();
}

function keyDown(p_evt) {
	//alert('keyDown='+p_evt.keyCode)
	if(p_evt.keyCode == 37){//left
		if(jet.style.display!="none"){
			turnJet(-1)
		}else{
			turnParachutist(-1)
		}
	}else if(p_evt.keyCode == 39){//right
		if(jet.style.display!="none"){
			turnJet(1)
		}else{
			turnParachutist(1)
		}
	}else if(p_evt.keyCode == 38){//up
		if(parachutist.style.display!="block"){
			dropParachutist();
		}
	}
}

function speedUp(){
	vel_v += .00001;
	document.getElementById("vel_v_display").value = vel_v;
}

function speedDown(){
	vel_v -= .00001;
	document.getElementById("vel_v_display").value = vel_v;
}

function turnJet(p_value){
	var jet = document.getElementById("jet")
	for(var i=0; i< manche_form.radiogroup.length; i++){
		if(manche_form.radiogroup[i].checked){
			var selected = i
		}
	}
	if(((selected+p_value)>=0)&&((selected+p_value)<=4)){
		manche_form.radiogroup[selected+p_value].checked = true
		var manche_pos = (selected+p_value)-2;
		jet_v_rot = Math.abs(manche_pos)
		jet_s_rot = manche_pos/jet_v_rot
	}
}


function toggleMap(p_button){
	var map_type = bg.getCurrentMapType()
	if(map_type==G_SATELLITE_TYPE){
		bg.setMapType(G_HYBRID_TYPE)
		p_button.className = "on";
	}else{
		bg.setMapType(G_SATELLITE_TYPE)
		p_button.className = "off";
	}
}

function toggleClouds(){
	if(cloud1.style.display=="block"){
		hideClouds(true)
	}else{
		hideClouds(false)
	}
}

function changeCamera(p_cam){
	var tv_offset=0;
	if(p_cam==0){
		tv_offset = 4;
	}else	if(p_cam==1){
		tv_offset = 2;
	}else	if(p_cam==2){
		tv_offset = 0;
	}else	if(p_cam==3){
		tv_offset = 1;
		p_cam = 2;
	}else	if(p_cam==4){
		tv_offset = 3;
		p_cam = 1;
	}
	tvback.style.backgroundPosition = (tv_offset*-262)+"px";
	for(var i=1;i<=3;i++){
		if(i==(p_cam+1)){
			this["cam_"+i+"_btn"].className = "on";
		}else{
			this["cam_"+i+"_btn"].className = "off";
		}
	}
}

/*var state=0;
function tvNoise(){
	//var state = Math.round(Math.random()*2)
	if(state == 0){
		state=1;
		tvnoise1.style.display = "block"
		tvnoise2.style.display = "none"
	}else if(state ==1){
		state=0;
		tvnoise1.style.display = "none"
		tvnoise2.style.display = "block"
	}
	setTimeout("tvNoise()",100); 
}
*/

//]]>

