var browserIE  = (navigator.appVersion.toLowerCase().indexOf("msie") != -1)?true:false;
var browserWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1)?true:false;
var browserFF = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1)?true:false;
var browserOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1)?true:false;

function playSound(sound_id) {
  if (sound_id == null)
    sound_id = "click2";
  if ( window.parent && window.parent.playSound )
	window.parent.playSound(sound_id);
  return false;	
}

var frame_num = 1;

function $$() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
	var element = arguments[i];
	if (typeof element == 'string')
	  element = document.getElementById(element);
	if (arguments.length == 1)
	  return element;
	elements.push(element);
  }
  return elements;
}

$(document).ready(function(){
  $("#main_wrap").click(function(event){
	$("#popup_main").fadeIn("slow");
	hideAll("main");
	event.preventDefault();
	});
  $("#legend_wrap").click(function(event){
	$("#popup_legend").fadeIn("slow");
	hideAll("legend");
	event.preventDefault();
	});
  $("#zoom_wrap").click(function(event){
	$("#popup_zoom").fadeIn("slow");
	hideAll("zoom");
	event.preventDefault();
	});
  $("#stats_wrap").click(function(event){
	$("#popup_stats").fadeIn("slow");
	hideAll("stats");
	event.preventDefault();
	});
  $("#info_wrap").click(function(event){
	$("#popup_info").fadeIn("slow");
	hideAll("info");
	event.preventDefault();
	});
  $("#energy_wrap").click(function(event){
	$("#popup_energy").fadeIn("slow");
	hideAll("energy");
	event.preventDefault();
	});
  $("#speed_wrap").click(function(event){
	$("#popup_speed").fadeIn("slow");
	hideAll("speed");
	event.preventDefault();
	});
  $("#popup_window").click(function(event){
	hideAll();
	$("#products_wrap").fadeIn("slow");
	event.preventDefault();
	});
  });

function hideAll( allBut ) {
  playSound();
  if( allBut )
	$("#products_wrap").hide();
  var p_type = ["main","legend","zoom","stats","info","energy","speed"];
  for ( var ix=0; ix<p_type.length; ix++) {
	if ( p_type[ix] != allBut )
	  $("#popup_" + p_type[ix] ).hide();
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
		 
function MM_displayStatusMsg(msgStr) { //v1.0
  window.status=msgStr;
  document.MM_returnValue = true;
}

function displayStandardMsg() {
  window.status="TrackHawk  -  Follow the Leader";
  document.MM_returnValue = true;
}

function setImage( elemId, srcName ) {
  document.getElementById(elemId).src = "images/" + srcName;
}

function flashWindow() {
	var popupFlash = window.open('TrackHawk.html', 'ModalWin', 'width=676,height=496,modal=0');
	popupFlash.focus();
}

function popupClosed() {
  playSound("mech1");
}

function closeModelessWindows() {
  if ( popup )
	popup.close();
}

var popup = null;
function popupWindow(pu_url, rem_href) {
  if (rem_href) {
    $$(rem_href).href = "javascript:void(0);";
  }
  var play_when_ready = (!popup || popup.closed)?true:false;
try {
  if ( window.showModelessDialog ) {
    if ( popup && !popup.closed )
	  popup.close();
  	popup = window.showModelessDialog(pu_url,window,"dialogWidth:616px;dialogHeight:700px;dialogLeft:100px;dialogTop:100px;center:0;resizable:0;status:0");
  } else {	
	popup = window.open(pu_url, 'PopupWin', "width=616,height=700,modal=no,dialog=no,z-lock=1,alwaysRaised=1,scrollbars=1,dependent=1,resizable=1");
  }
  popup.focus();
} catch(err) {}
  if ( play_when_ready )
    playSound("winopen");
  return false;
}

function resizeParent(frm_id) {
  var min_height = 500;	
  var the_height = document.getElementById("fcontainer").scrollHeight;
//alert("the_height " + the_height);	
  if( !the_height || the_height < min_height )
    the_height = min_height;
  parent.document.getElementById(frm_id).height = the_height+40;
}

function disableSubmit() {
  playSound();
  $$('send').disabled = true;
  setTimeout( function() {$$('send').disabled = false;}, 2000 );
  return true;
}

function handleResponse(r_code) {
  var elem2, elem1 = document.getElementById("in-name");
  elem2 = document.getElementById("in-email");
  elem1.style.backgroundColor = elem2.style.backgroundColor = "#ffffff";
  if( r_code == 0 ) {
	document.forms[0].reset();
  }
  if( r_code == 1 ) {
	elem1.style.backgroundColor = "#ffbbbb";
	elem1.focus();
  }
  if( r_code == 2 ) {
	elem2.style.backgroundColor = "#ffbbbb";
	elem2.focus();
  }	
}
