/*
 * Smallbox CMS http://www.smallboxsoftware.com
 *
 * Copyright (C) 2000-2008 Smallbox Software Inc. 
 * Author: Kenneth Spencer
 *
 * This file is intended only for use within Smallbox CMS.
 * Unauthorized use is strictly prohibited.
 *
 */


var ie_version = 5;
var mouseX;
var mouseY;
var disable_events = 0;
var boxModel = false;
var drag_interval = null;
var mouseMoveAction = null;
var image_list = new Array();
var preloads   = new Array();
var onloads    = new Array();
var moveStart = 0;
var drag_object = null;


function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}



function sb_onload() {
 var testNode = document.createElement('div');
 testNode.style.width = '100px';
 testNode.style.border = 'solid 2px black' ;
 testNode.style.visibility = 'hidden' ;
 testNode.style.position = 'absolute';
 document.body.appendChild(testNode);

 document.onmousemove = mouse_pos;
 
 if(testNode.offsetWidth == 104)
  boxModel = true;
 else
  boxModel = false;

 for(var i = 0; i < onloads.length; i++) {
  onloads[i]();
 }
}


function mouse_pos(evt) {
 if(evt) {
  mouseX = evt.pageX ;
  mouseY = evt.pageY ;
 }
 else {
  if(boxModel == true) {
   mouseX = event.clientX+document.documentElement.scrollLeft ;
   mouseY = event.clientY+document.documentElement.scrollTop ;
  }
  else {
   mouseX = event.clientX+document.body.scrollLeft ;
   mouseY = event.clientY+document.body.scrollTop ;
  }
 }
 if(mouseMoveAction != null) {
  mouseMoveAction();
 } 
 if(drag_object != null) {
  drag_object.onmousemove();
 }
}


function setOpacity(Obj, Level) {
 if(typeof(Obj.style.opacity) == "string")
  Obj.style.opacity=Level > 0 ? Level / 100 : 0;
 else if( typeof(Obj.style.filter) == "string") {
  Obj.style.filter = 'alpha(opacity='+Level+')';
 }
}


function getPos(thisId) {
 var pos  = new Object();
 pos.left = 0;
 pos.top  =  0;


 if(thisId.style.top) {
  pos.top  = parseInt(thisId.style.top);
  pos.left = parseInt(thisId.style.left);
  return pos;
 }

 for (var p = thisId; p.parentNode ; p =  p.parentNode) {
  if (getStyle(p, 'position') == 'fixed') {
   pos.top += typeof(window.scrollY) != 'undefined' ? window.scrollY : document.body.parentNode.scrollTop;
   pos.left += typeof(window.scrollX) != 'undefined' ? window.scrollX : document.body.parentNode.scrollLeft;
   break;
  }
 }

 for (var p = thisId; p ; p = p.offsetParent) {
  pos.top+= p.offsetTop;
  pos.left+= p.offsetLeft;
 }

 pos.bottom = pos.top + thisId.offsetHeight
 pos.right  = pos.left + thisId.offsetWidth;
 return pos;
}


function sb_drag_object(Node) {
 this.Node = Node;
 this.start = drag_start;
 this.onmousemove = drag_move; 
 this.onmouseup   = drag_stop;

 this.default_start = drag_start;
 this.default_onmousemove = drag_move; 
 this.default_onmouseup   = drag_stop;

 pos = getPos(Node);
 this.offsetY = mouseY - pos.top;
 this.offsetX = mouseX - pos.left;

}



function drag_start() {
 document.onmouseup = this.onmouseup;
 document.body.style.cursor = this.Node.style.cursor;
}

function drag_move() {
 this.Node.style.top  =  mouseY - this.offsetY +'px';
 this.Node.style.left =  mouseX - this.offsetX +'px';
}

function drag_stop() {
 drag_interval = null;
 document.onmouseup = null;
 document.body.style.cursor = null;
 this.Nde = null;
 drag_object = null;
 mouseMoveAction = null;
}

function sb_preload() {
 for(var i =0 ; i < preloads.length; i++) {
  tmp = new Image();
  tmp.src = preloads[i];
 }
}
onloads[onloads.length] = sb_preload;

function sb_over(thisId, Num) {
 if (typeof(thisId) == 'string') {
  thisId = document.getElementById(thisId);
 }
 if(thisId.ie_png_src) {
  image_list[Num] = thisId.ie_png_src;
  thisId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+preloads[Num]+"', sizingMethod='scale')";
 }
 else {
  image_list[Num] = thisId.src;
  thisId.src = preloads[Num];
 }
}

function sb_out(thisId, Num) {
 if (typeof(thisId) == 'string') {
  thisId = document.getElementById(thisId);
 }

 if(thisId.ie_png_src)
  thisId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image_list[Num]+"', sizingMethod='scale')";
 else
  thisId.src = image_list[Num];
}

function ie_png_loader() {
 var images = document.getElementsByTagName("img");
 for(var i = 0; i < images.length; i++) {
  var img = images.item(i);
  if(img.src.match(/\.png$/i)) {
   iePNG(img);
  }
 }
}

function iePNG(thisId) {
 var version = navigator.appVersion.match(/MSIE ([0-9])/);
 var pixel = "/smallbox4/images/pixel.gif";
/*
 if(thisId.src.match(pixel)) {
  thisId.style.visibility = 'visible';
  return false;
 }
*/
 if(typeof(thisId.style.filter) == 'string' && parseInt(version[1]) < 7) {
  thisId.style.height = thisId.offsetHeight +"px";
  thisId.style.width  = thisId.offsetWidth +"px";
  var src = thisId.src;
  thisId.ie_png_src = src;
  thisId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')";
  thisId.src = pixel;
//  thisId.style.visibility = 'visible';
 }
 else {
//  thisId.style.visibility = 'visible';
 }
}

var swfCount = 0;
function sbSWF(src, width, height) {
 this.src = src;
 this.width = width;
 this.height = height;
 this.params = new Array();
 this.params["quality"] = "high";
 this.append = swfAppend;
}

function swfAppend() {
 swfCount++;
 var str = "";
 str += "<object width=\""+this.width+"\" height=\""+this.height+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"&#10;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" >";
 str += "<param name=\"movie\" value=\""+this.src+"\" />";
 for(param in this.params) {
  str +="<param name=\""+param+"\" value=\""+this.params[param]+"\" />";
 }

 str += "<embed  src=\""+this.src+"\" width=\""+this.width+"\" height=\""+this.height+"\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" ";
 for(param in this.params) {
  str += " "+param+"=\""+this.params[param]+"\" ";
 }
 str += "></embed>";
 str += "</object>";
 document.write(str);
}

function ieSWF() {
 if(true){
  var theObjects = document.getElementsByTagName('object');
  var theObjectsLen = theObjects.length;


  for (var i = 0; i < theObjectsLen; i++) {
   node = theObjects[i];
   var params = node.getElementsByTagName('param');
   var fv = "";
   for(j =0; j < params.length; j++) {
    if(params[j].name == "FlashVars") {
     fv = "<param name='"+params[j].name+"' value='"+params[j].value+"'>\n";
    }
   }

   if(node.outerHTML){
    if(node.data){
     node.removeAttribute('data');
    }

    if(fv)
     node.outerHTML = node.outerHTML.replace(/<param name="FlashVars" value="">/ig, fv);
    else
     node.outerHTML = node.outerHTML;

     
    //node.parentNode.style.display='block';
   }
  }
 }
}

function sb_scroll() {
}

function sb_resize() {

}

//window.onscroll      = sb_scroll;
//window.onresize      = sb_resize;



var escape_node;
var escape_mode = 0;
var sbEscapes = new Array();
var escapeDepth = 0;

function escapeNode(Node, mode, depth, ref, doc) {
 escape_node = Node;
 escape_mode = escape_mode;
 var o = new Object();
 o.node = Node;
 o.mode = mode;
 o.ref  = ref;

 if (depth) {
  escapeDepth = depth - 1;
 }
 sbEscapes[escapeDepth] = o;

 if(!doc)
  document['onkeypress']=clearEscapeNode;
 else
  doc['onkeypress']=clearEscapeNode;
}
                                                                                                 
function clearEscapeNode(evt) {
 if(evt) {
  if(evt.keyCode==27) 
   escapeClear();
 }
 else if(event) {
  if(event.keyCode==27)
   escapeClear();
 }
}

function escapeRemove(o) {
 if(o) {
  if (o.ref) {
   o.ref();
  }
  if(o.mode == true)
   o.node.parentNode.removeChild(o.node);
  else
   o.node.style.display = 'none';
 }
}

function escapeClear(depth) {
 depth = parseInt(depth) ? depth - 1 : escapeDepth;
 if(sbEscapes[depth]) {
  while(sbEscapes[depth]) {
   escapeRemove(sbEscapes.pop());
  }
  escapeDepth = sbEscapes.length > 0 ? sbEscapes.length - 1 : 0;
 }
}


var sbShowThumb;
function sb_show_thumbnail(thisId, src, width, height) {
 sb_hide_thumbnail();
 pos = getPos(thisId);
 var div = sbShowThumb = sb_node(document.body, "div");
 div.style.visibility = 'hidden';
 div.style.position = 'absolute';
 div.style.border = 'solid 2px #666666';
 div.style.top  = pos.top  - height / 2 + 8  +"px";
 div.style.left = pos.left - width - 10 + "px";
 div.style.width = width+'px';
 div.style.height = height+'px';
 img = sb_node(div, "img");
 img.src = src;
 div.style.background = 'url(/smallbox4/images/bg_repeat.gif)';
/*
 div.style.backgroundImage = "url("+src+")";
 div.style.backgroundRepeat = 'no-repeat';
*/
 div.style.visibility = 'visible';
}

function sb_hide_thumbnail() {
 if(sbShowThumb) {
  document.body.removeChild(sbShowThumb);
  sbShowThumb = null;
 }
}

function sb_toggle(thisId, ID) {
 var element = document.getElementById(ID);

 var status;
 if(status = getCookie("toggles")) {
  status = status.split(',');
 }
 else {
  status = new Array();
 }

 var img = document.getElementById(ID+'_expand');

 if(element.style.display == 'none') {
  img.src = '/smallbox4/images5/icons/contract_block.png';
  thisId.parentNode.className = "expander on";
  element.style.display = 'block';
  status[status.length] = ID;
 }
 else {
  img.src = '/smallbox4/images5/icons/expand_block.png';
  thisId.parentNode.className = "expander";
  element.style.display = 'none';
  for(var i = 0; i < status.length; i++) {
   if(status[i] == ID) {
    delete status[i];
   }
  }

 }

 var retval = "";
 for(var i = 0; i < status.length; i++) {
  if(status[i]) {   
   retval += (retval.length ? "," : "") + status[i];
  }
 }
 document.cookie = "toggles="+retval;

}

var sb_reload_time;

function sb_set_reload() {
 if(sb_reload_time) {
  clearTimeout(sb_reload_time);
  sb_reload_time = null;
 }
 sb_reload_time = setTimeout(sb_reload, 3600 * 1000);
}

function sb_reload() {
 window.location.replace(window.location.href);
}


function sb_window(thisId, id, align, ref) {
 escapeClear(1);
 var win = document.getElementById(id);
 win.style.display = 'block';
 if (ref) {
  ref = new ref();
 }

 if (ref && ref.open) {
  ref.open();
 }

 if (align == 'center' || align == 'fillY') {
  var width  = document.body.offsetWidth;
//  var height = document.body.offsetHeight;
  var height  = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  var scrollY = document.documentElement.scrollTop;


  var top = (height - win.offsetHeight) / 2 + scrollY;
  win.style.top = (top > 30 ? top : 30) + 'px'; 
  win.style.left = (width - win.offsetWidth) / 2 + 'px'; 
  if (align == 'fillY') {
   var bodyId, headId;
   var fillHeight = (window.innerHeight ? window.innerHeight: document.documentElement.clientHeight) - 60;

   win.style.maxHeight = fillHeight + 'px';
   if (bodyId = document.getElementById(id+'_body')) {
    headId =  document.getElementById(id+'_head');
    bodyId.style.maxHeight = (fillHeight - headId.offsetHeight - 15) + 'px';
    bodyId.style.overflow = 'auto';
   }
  }

  var underlay = document.createElement('div');
  underlay.className = 'sb_window_underlay';
  underlay.style.position = 'absolute'; 
  underlay.style.zIndex = 100;
  underlay.style.backgroundColor = 'black';
  underlay.style.top = 0;
  underlay.style.left = 0;
  underlay.style.right = 0;
  underlay.style.height = document.body.offsetHeight + 'px';
  setOpacity(underlay, 60);
  document.body.appendChild(underlay);
 
  var ref2 = function() {
   if (ref && ref.close) {
    ref.close();
   }
   document.body.removeChild(underlay);
  }
  escapeNode(win, null, null, ref2);
 }
 else {
  pos = getPos(thisId);
  var left = (pos.left - win.offsetWidth - 20);
  if (left <= 0) {
   win.style.left = (pos.left + 20 + thisId.offsetWidth) + "px";
  }
  else if(pos.left > 20)
   win.style.left = left+"px";
  else
   win.style.left = "0px";
  var top = (pos.top - win.offsetHeight / 2);
  win.style.top = (top > 0 ? top : 0) + "px";
  escapeNode(win);
 }

}



function sb_isTarget(e, node) {
 /** Detect if element is the element that originated the event */
 if (e.type != 'mouseout' && e.type != 'mouseover') return false;
 var reltg = e.relatedTarget ? e.relatedTarget :e.type == 'mouseout' ? e.toElement : e.fromElement;
 while (reltg && reltg != node) reltg = reltg.parentNode;
 return (reltg != node); 
}

function sb_rollover(img) {
 var match = img.src.match(/\.(png)|(gif)$/);
 if (match != null) {
  var out  = img.src;
  var over = img.src.replace(match[0], "_over"+match[0]);
  var pre = new Image();
  pre.src = over;
  img.onmouseover = function() {this.src = over}
  img.onmouseout  = function() {this.src = out}
 }
}


function sb_css(file) {

/*
 var style  = document.createElement('style');
 style.type = 'text/css';

 var textNode = document.createTextNode("@import url(\""+file+"\");");
 style.appendChild(textNode);
*/
 var link = document.createElement("link")
 link.setAttribute("href", file)
 link.setAttribute("rel", "stylesheet")
 link.setAttribute("type", "text/css")


 var head  = document.getElementsByTagName("head").item(0);
 head.appendChild(link);
}

var sbIncluded = new Array();
function sb_include(file, ref) {
 var scripts = document.getElementsByTagName('script');
 for (var i = 0; i < sbIncluded.length; i++) {
  if (sbIncluded[i] == file) {
   return;
  }
 }
 sbIncluded.push(file);

 var head = document.getElementsByTagName("head").item(0);

 var script = document.createElement('script');
 script.type = 'text/javascript';
 script.src  = file;
 if (ref) {
  if (typeof(script.onreadystatechange) == 'undefined') {
   script.onload = function() {
    ref();
   }
  }
  else {
   script.onreadystatechange = function() {
    if (this.readyState == 'loaded') { 
     ref();
    }
   } 
  }
 }
 head.appendChild(script);
}


onloads[onloads.length] = function() {
 /** MSIE **/
 var ie = new Array();
 var state = new Object();
 if (ie = navigator.appVersion.match(/MSIE ([0-9]+\.[0-9]+)/)) {
  var version = parseFloat(ie[1]);

//  document.cookie = "ieWarning=";

  if (version < ie_version && !getCookie('ieWarning')) {
    var ref = function(obj) {
    if (obj.ref1 == true && obj.ref2 == true) {
     var kit = new sb_window_kit("Old version of Internet Explorer Detected.", 1);
     kit.underlay = true;
     kit.position = 'middle';
     kit.cont.style.width = '500px';

     var browsers = [
      { icon : 'chrome.gif', name : 'Google Chrome', link : 'http://www.google.com/chrome' },
      { icon : 'firefox.gif', name : 'Firefox', link : 'http://www.getfirefox.com' },
      { icon : 'ie.gif', name : 'Internet Explorer', link : 'http://www.getie.com' },
      { icon : 'safari.gif', name : 'Safari', link : 'http://www.apple.com/safari/download/' }
     ];

     kit.head.className += ' ie_message_head';
     var cont = sb_node(kit.body, 'div');
     cont.className = 'ie_message';
     
     var p, a, table, tbody, tr, td, img;
     p = sb_node(cont, 'p', "You are using an out of date version of Internet Explorer (IE) which is not supported by this website. Newer browsers are available with greatly improved support for web standards, security and load times. Please see alternatives below:");
     p = sb_node(cont, 'p', "If you would like to continue browsing this website using your current browser simply close this window.");
     sb_node(cont, 'br');
     table = sb_node(sb_node(cont, 'div'), 'table');
     tbody = sb_node(table, 'tbody');   
     for (var i = 0; i < browsers.length; i++) {
      var browser = browsers[i];
      tr    = sb_node(tbody, 'tr');
      td    = sb_node(tr, 'td');
      a     = sb_node(td, 'a');
      a.href = browser.link;
      a.target = '_new';
      img   = sb_node(a, 'img');
      img.src = '/smallbox4/images5/browsers/'+browser.icon;
      td    = sb_node(tr, 'td');
      td.style.paddingLeft = '15px';
      a     = sb_node(td, 'a', browser.name);
      a.href = browser.link;
      a.target = '_new';
     }   

     sb_node(cont, 'br');
     p = sb_node(cont, 'p', "For more information on this decision please ");
     a = sb_node(p, 'a', 'click here');
     a.href = 'http://www.smallboxsoftware.com/about_us/news/index/post7.htm';
     a.target = '_new';
     sb_text_node(p, '.');

 

     kit.append(document.body);
     var now = new Date();
     now.setTime(now.getTime() + 1000 * 60 * 60);
     document.cookie = "ieWarning=1;expires=" + now.toGMTString();
    }
   }
   sb_include('/smallbox4/js/xml.js', function() {state.ref1 = true;ref(state);});      
   sb_include('/smallbox4/js/windows.js', function() {state.ref2 = true;ref(state);});      
  }
 }
}

var toolTip;
function sb_tooltip(node, text) {
 sb_tooltip_clear();
 var pos = getPos(node);
 
 
 var div = toolTip = document.createElement('div');
 div.style.left = pos.left + 'px';
 div.className = 'sb_tooltip';
 textNode = document.createTextNode(text);
 div.appendChild(textNode);
 document.body.appendChild(div);

 if (pos.left + div.offsetWidth > document.body.offsetWidth - 5) {
  div.style.left = 'auto';
  div.style.right = '5px';
 }
 if (pos.top - 5 - div.offsetHeight > 5)
  div.style.top = pos.top - 5 - div.offsetHeight + 'px';
 else
  div.style.top = pos.bottom + 5 + 'px';

}

function sb_tooltip_clear() {
 if (toolTip) {
  document.body.removeChild(toolTip);
  toolTip = null;
 }
}


function sb_load_it(Node, Image) {
 var node = document.getElementById(Node);
 var image = document.getElementById(Image);
 if (node && image) { // && node.lastChild.nodeName == '#text') {
//  node.removeChild(node.lastChild);
  node.parentNode.removeChild(node);
  image.style.visibility = 'visible';
 }
}

