// JavaScript Document

function showBox(){
	Element.show('overlay_login');
	center('dual_box');
	//getVideo(ip,camera);
	return false;
}

function hideBox(){
	Element.hide('dual_box');
	Element.hide('overlay_login');
	Element.hide('results_form');
	Element.show('initial_form');
	return false;
}

function showServiceBox(){
	Element.show('service_message');
	center('service_box');
	getVideo(ip,camera);
	return false;
}

function hideServiceBox(){
	Element.hide('service_box');
	Element.hide('service_message');
	return false;
}

function showservice_desc_box(){
	Element.show('makeappointment_message');
	center('service_desc_box');
	return false;
}

function hideservice_desc_box(){
	Element.hide('service_desc_box');
	Element.hide('makeappointment_message');
	return false;
}
	
function showLoginLogout(){
	if ((user_login != null) && (user_login != '')) {
		new Insertion.Top('user_status', '<div id=\"loginlogout\">User: <a href="/users/show/'+user_id+'">'+user_login+'</a>&nbsp;&nbsp;|&nbsp<a href="/account/logout">Sign Out</a>&nbsp;&nbsp;|&nbsp<a href="/account/edit">Settings</a></div>');
	} else {
		new Insertion.Top('user_status', "<div id=\"loginlogout\"><a href=\"\" onclick=\"showBox(); return false;\">Log In</a></div>");
	}
}

function center(element){
    try{
    	element = document.getElementById(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
			 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}
function getVideo(ip, camera)
{
// Set the BaseURL to the URL of your camera
//function video( ip, camera)
var BaseURL = "http://"+ip;
//"http://67.32.144.214/";

// 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 = "704";
var DisplayHeight = "480";

// This is the path to the image generating file inside the camera itself
//var File = "axis-cgi/mjpg/video.cgi?resolution=CIF&camera=quad";
var File = "axis-cgi/mjpg/video.cgi?resolution=CIF&camera=" +camera;
// No changes required below this point
var output = "";
  var AppletDir = BaseURL + "java/ama";
  var VideoPath = "axis-cgi/mjpg/video.cgi?resolution=";
//  var restOfPath = "&camera=quad";
  var restOfPath = "&camera=" +camera;
  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, ptz.jar">';
  output += '<PARAM NAME="cache_version" VALUE="1.0.0.0, 1.2.0.0">';
  output += '<PARAM NAME="ama_plugins" VALUE="ptz.PTZ">';
  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>'
document.getElementbyId('video').innerHTML = document.write(output);
//	myWindow=window.open('','','')
//myWindow.document.write(output)
//myWindow.focus()
}

