// Javascript: resize
//    Reloads the page if the window size is changed
var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}
if (Browser.Version() >= 7)
  window.onresize = resize;
function resize()
{
 wHeightWidth();
 //window.location.href=window.location.href;
}
//
// Javascript: addLoadEvent
//     checks for other onload functions established and adds a new function
function addLoadEvent(func) { 
  var prevFunction = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (prevFunction) { 
        prevFunction(); 
      } 
      func(); 
    } 
  } 
} 
// JavaScript wHeightWidth
//   calculate height by subtracting top location from bottom location
function wHeightWidth(){

if (Browser.Version() >= 7) {
  // Check if browser is IE 6 or below then do nothing 
  var iW = 800, iH = 600;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    iW = window.innerWidth;
    iH = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    iW = document.documentElement.clientWidth;
    iH = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    iW = document.body.clientWidth;
    iH = document.body.clientHeight;
  }
  var heightOfCell = (iH - 183);		// remove 183px to account for the header 149, footer 24, and padding 10
  //var footerLeft = (iW / 10);     		// left:  10% of window width 
  //var footerWidth = (footerLeft * 8);   // width:   80% of window width 
  document.getElementById("content").style.height = heightOfCell+'px';
  document.getElementById("sidebar").style.height = heightOfCell+10+'px';
  //if (document.getElementById("footer") != null) {
  //   document.getElementById("footer").style.left = footerLeft+'px';
  //   document.getElementById("footer").style.width = footerWidth+'px';
  //}
  //  Add message about IE6 or less being outdated and insecure
} else {
  var ni = document.getElementById('sidebar');
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id','IE6div');
  newdiv.innerHTML = '<div style="background:#666;position:relative;margin:2px 0px 0px 5px;padding:2px;border: 2px solid green;color:red;font-weight:bold;">WARNING! Internet Explorer ' + Browser.Version() + ' is outdated and not secure.&nbsp;Please upgrade or use another browser for this site!!</div>';
  ni.appendChild(newdiv);
}
}
// Initialize after loading the page
	addLoadEvent(wHeightWidth); 
//
// Javascript: mailpage
function mailpage()
{
  mail_str = "mailto:?subject=Check out " + document.title;
  mail_str += "&body=I thought you might be interested in " + document.title;
  mail_str += ". You can view it at, " + location.href;
  location.href = mail_str;
}
//
// Javascript: modxtabs
//  MODX sample for adding Tabs to your content
function navAllInactive() {
	oNav = document.getElementById('nav');
	oLis = oNav.getElementsByTagName('LI');
 
	for (i = 0; i < oLis.length; i++) {
		oLis[i].className = '';
	}
}
 
function hideAllData() {
	oData = document.getElementById('data');
	oDivs = oData.getElementsByTagName('DIV');
 
	for (i = 0; i < oDivs.length; i++) {
		oDivs[i].style.display = 'none';
	}
}
 
function doShow(o, pageId) {
	hideAllData();
	navAllInactive();
	o.className = 'active';
	oData = document.getElementById(pageId);
	oData.style.display = 'block';
 
	return false;
}
//
// Javascript: rotate
//  Rotate photos
var interval = 4.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
var image_index = 0;

function imageItem(image_location) {
  this.image_item = new Image();
  this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
  return(imageObj.image_item.src)
}
function generate(x, y) {
  var range = y - x + 1;
  return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
  if (random_display) {
    image_index = generate(0, number_of_image-1);
    random_display = 0;  // random start then sequential
  }
  else {
    image_index = (image_index+1) % number_of_image;
  }
  var new_image = get_ImageItemLocation(image_list[image_index]);
  return(new_image);
}
function rotateImage(place) {
  var stopstart = place + "ss";
  if (document.getElementById(stopstart).value == "Stop") {
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	setTimeout(recur_call, interval);
  }
}
function rotatestart(text,place) {
  var stopstart = place + "ss";
  document.getElementById(stopstart).value = (text == "Stop") ? "Start" : "Stop";
  rotateImage(place);
}
function next(place) {
  var new_image = getNextImage();
  document[place].src = new_image;
}
function previous(place) {
  if (image_index-2 >= -1) {
    image_index = image_index - 2;
    var new_image = getNextImage();
    document[place].src = new_image;
   }
  else {
    image_index = number_of_image - 2;
    var new_image = getNextImage();
    document[place].src = new_image;
   }
}
//
// Javascript: DivExpCol
//   Expands or collapses div that have class=divShowHide
//   global variables
  var templatePath  = 'assets/images/';
  var plusImg       = 'arrow_18gr.gif';
  var minusImg      = 'arrow_18gd.gif';
  var expandText    = 'Expand All';
  var collapseText  = 'Collapse All';
  var plus = new Image();
      plus.src = templatePath + plusImg;
  var minus = new Image();
      minus.src = templatePath + minusImg;
      
//   toggleMe function
function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
    var image = document.getElementById(a + '_image');
		if (image != null && image.src.indexOf(plusImg) > 0)
		  	image.src = minus.src;
  } else {
    e.style.display="none"
    var image = document.getElementById(a + '_image');
		if (image != null && image.src.indexOf(minusImg) > 0)
		  	image.src = plus.src;
  }
  return true;
}

//   DivExpandAll function
function DivExpandAll (DivsID)
	{
		var divs = document.getElementsByTagName('div');
		for (var i = 0; i < divs.length; i++)
		{
			if (divs[i].className != null && divs[i].className == 'divShowHide')
			{
          if (divs[i].style.display=="none")
			     	 divs[i].style.display="block";
    	}
		}
		var images = document.getElementsByTagName('img');
		for (var j = 0; j < images.length; j++)
		{
			if (images[j] != null && images[j].src.indexOf(plusImg) > 0)
		  		images[j].src = minus.src;
		}
		var link = document.getElementById(DivsID + '_all');
		link.innerHTML = collapseText;
		link.setAttribute('href','javascript:DivCollapseAll(\'' + DivsID + '\')');
	}

//   DivCollapseAll function
function DivCollapseAll (DivsID)
	{
		var divs = document.getElementsByTagName('div');
		for (var i = 0; i < divs.length; i++)
		{
			if (divs[i].className != null && divs[i].className == 'divShowHide')
			{
          if (divs[i].style.display=="block")
			     	 divs[i].style.display="none";
    	}
		}
		var images = document.getElementsByTagName('img');
		for (var j = 0; j < images.length; j++)
		{
			if (images[j] != null && images[j].src.indexOf(minusImg) > 0)
		  		images[j].src = plus.src;
		}
		var link = document.getElementById(DivsID + '_all');
		link.innerHTML = expandText;
		link.setAttribute('href','javascript:DivExpandAll(\'' + DivsID + '\')');
	}
//
// Javascript: drop_down_menu
/**
 * Light Menu System v0.1
 * @author Jonathan Schemoul
 * @copyright 2006-2007 Holdiland
 * @license GPL V2 or newer
 */
var menuEffects = new Class({
        initialize: function(selector, options) {
                this.options = Object.extend({
                        subElement: false,
                        subElementSelector: 'a'
                }, options || {})
                this.selector = selector;
                this.currTimer = 500;
                $ES(selector + ' li ul').each(function(el) {
                        el.setStyles({
                                'display': 'block'
                        });
                        normalHeight = el.offsetHeight;
                        el.setStyles({
                                'height': 0,
                                'overflow': 'hidden'
                        });
                        elParent = $(el.parentNode);
                        
                        currentMenu = new Fx.Style(el, 'height');
                        elParent.addEvents({
                                'mouseover': function(submenu, myParent, targetValue) {
                                        myParent.addClass('hover');
                                        submenu.clearTimer();
                                        submenu.custom(targetValue);
                                }.pass([currentMenu, elParent, normalHeight]),
                                'mouseout': function(submenu, myParent, targetValue) {
                                        myParent.removeClass('hover');
                                        submenu.clearTimer();
                                        submenu.custom(targetValue);
                                }.pass([currentMenu, elParent, 0])
                        })
                }.bind(this));
        }
});
function processMenuEffects (){
        var myMenus = new menuEffects('#myajaxmenu', {
                subElement: true
        });
}
window.onDomReady(processMenuEffects);
