/************************************************
* White paper registration and contact message *
************************************************/

var registrationEmailLabel;
var contactNameLabel;
var contactEmailLabel;
var contactMessageLabel;

$(document).ready(function(){
  /*jQuery('#jcarousel').jcarousel({scroll: 1});*/
  
  $("#text2").hide();
  
  $("#textButton1").click(function() {
    $("#text1").fadeOut("slow", function(){
      $("#text1").hide();
      $("#text2").fadeIn("slow");
    });
    return false;
  });
  
  $("#home").click(function() {
    $("#text2").fadeOut("slow", function(){
      $("#text2").hide();
      $("#text1").fadeIn("slow");
    });
    return false;
  });
  
  registrationEmailLabel = $("#registrationEmail").val();
  contactNameLabel = $("#contactName").val();
  contactEmailLabel = $("#contactEmail").val();
  contactMessageLabel = $("#contactMessage").val();
  
  $("#registrationSubmit").click(register);
  $("#contactSubmit").click(contact);
});

function register() {
  $("#registrationSubmit").attr('disabled', true);
  var email = $.trim($("#registrationEmail").val());
  if (email == registrationEmailLabel) email = '';
  $("#registrationResponse").html("Sending...");
  $.post("php/process.php", {email: email, action: 'register'}, registerResponse);
  return false;
}
  
function registerResponse(aResult) {
  var result = eval( '(' + aResult + ')' ); 
  $("#registrationResponse").html(result.response);
  $("#registrationSubmit").attr('disabled', false);
  if (result.success)
    $("#registrationEmail").val(registrationEmailLabel);
}

function contact() {
  $("#contactSubmit").attr('disabled', true);
  var email = $.trim($("#contactEmail").val());
  var name = $.trim($("#contactName").val());
  var message = $.trim($("#contactMessage").val());
  if (email == contactEmailLabel) email = '';
  if (name == contactNameLabel) name = '';
  if (message == contactMessageLabel) message = '';
  $("#contactResponse").html("Sending...");
  $.post("php/process.php", {email: email, name: name, message: message, action: 'contact'}, contactResponse);
  return false;
}
  
function contactResponse(aResult) {
  var result = eval( '(' + aResult + ')' );
  $("#contactResponse").html(result.response);
  $("#contactSubmit").attr('disabled', false);
  if (result.success) {
    $("#contactName").val(contactNameLabel);
    $("#contactEmail").val(contactEmailLabel);
    $("#contactMessage").val(contactMessageLabel);
  }
}

$().ready(function() {
  $('#dialog').jqm();
});

$(document).ready(function (){
  $("#marquee490").marquee({yScroll: "bottom"});
});


/*******************
* Content resizing *
********************/

function getWindowHeight() {
  var result = 0;
  if (self.innerHeight)
    result = self.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    result = document.documentElement.clientHeight;
  else if (document.body)
    result = document.body.clientHeight;

  return result;
}

function getWindowWidth() {
  var result = 0;
  if (self.innerWidth)
    result = self.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
    result = document.documentElement.clientWidth;
  else if (document.body)
    result = document.body.clientWidth;

  return result;
}

function updateSize() {
  var page = document.getElementById('page');
  var w = getWindowWidth();
  var h = getWindowHeight();
  page.style.height = Math.max(600, h) + 'px'
  
  if ((window.isIE && w < page.scrollWidth) || (!window.isIE && h < 600))
    page.style.width = (w - window.scrollbarWidth) + 'px'
  else
    page.style.width = w + 'px'
  
  page.style.visibility = 'visible';
  
  var modal = document.getElementById('jqmWindow');
  if (modal != null)
    modal.style.top = (document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px';
}

function loadComplete() {
  window.isIE = navigator.appName == 'Microsoft Internet Explorer';
  
  var i = document.createElement('p');
  i.style.width = '100%';
  
  i.style.height = '200px';
  
  var o = document.createElement('div');
  o.style.position = 'absolute';
  o.style.top = '0px';
  o.style.left = '0px';
  o.style.visibility = 'hidden';
  o.style.width = '200px';
  o.style.height = '150px';
  o.style.overflow = 'hidden';
  o.appendChild(i);
  
  document.body.appendChild(o);
  var w1 = i.offsetWidth;
  var h1 = i.offsetHeight;
  o.style.overflow = 'scroll';
  var w2 = i.offsetWidth;
  var h2 = i.offsetHeight;
  if (w1 == w2) w2 = o.clientWidth;
  if (h1 == h2) h2 = o.clientWidth;
  
  document.body.removeChild(o);
  
  window.scrollbarWidth = w1 - w2;
  window.scrollbarHeight = h1 - h2;
  
  updateSize();
}

window.onresize = updateSize;
window.onload = loadComplete;

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
  // The index() method calculates the index from a
  // given index who is out of the actual item range.
  var idx = carousel.index(i, mycarousel_itemList.length);
  carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
  carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item) {
  return '<img src="' + item.url + '" width="230" height="150" alt="' + item.title + '" />';
};

jQuery(document).ready(function() {
  jQuery('#mycarousel').jcarousel({
    scroll: 1,
    wrap: 'circular',
    itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
    itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
  });
});


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid) {
  var page_request = false;
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest();
  else if (window.ActiveXObject) { // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        page_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){}
    }
  } else
    return false;
  
  page_request.onreadystatechange = function() {
    loadpage(page_request, containerid)
  }
  
  if (bustcachevar) //if bust caching of external page
    bustcacheparameter = (url.indexOf("?") != -1) ? "&"+new Date().getTime() : "?" + new Date().getTime();
  
  page_request.open('GET', url+bustcacheparameter, true);
  page_request.send(null);
}

function loadpage(page_request, containerid) {
  if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
  if (!document.getElementById)
    return;
  
  for (var i = 0; i < arguments.length; i++) {
    var file = arguments[i];
    var fileref = "";
    if (loadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding
      if (file.indexOf(".js") != -1) { //If object is a js file
        fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", file);
      } else if (file.indexOf(".css") != -1){ //If object is a css file
        fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", file);
      }
    }
    
    if (fileref != "") {
      document.getElementsByTagName("head").item(0).appendChild(fileref);
      loadedobjects += file + " "; //Remember this object as being already added to page
    }
  }
}