﻿/*=:Title : custom.js :: Development version
  =:Author : HodgsonConsulting
  =:URL : 
  =:Description : 
	This file contains all custom javascripts used.
	Remember to compress for production.
  
  =:Created : 07/24/2007
  =:Modified : 08/23/2007
*/
var hc = {};
hc.widget = {};
hc.util = {};
hc.util.getElement = function(el) {
	if (el && typeof el == "string")
		return document.getElementById(el);
	return el;
};
hc.util.getElementChildren = function(el) {
	var children = [];
	var child = el.firstChild;
	while (child)
	{
		if (child.nodeType == 1)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};
hc.util.browser = {
    init: function () {
		this.agent = this.searchString(this.dataBrowser) || "unknown";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "unknown";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	]
};
hc.util.browser.init();
hc.trans = {};
hc.trans.defaultTransition = function(time,begin,finish,duration) { 
    time/=duration;
    return begin + ((2.001-time) * time * finish);
};
/*= popup
--------------------------------------------------*/
hc.widget.popup = function(el,opt) {
    this.el = hc.util.getElement(el);
    this.bgnY = this.curY = opt.from;
    this.dstY = opt.to;
    this.duration = opt.dur;
    this.startTime = 0;
    this.trans = hc.trans.defaultTransition;
    this.interval = 1000/40; //fps
    this.timeoutId = 0;
    var me = this;
    this.intervalFunc = function() { me.step(); }
};
hc.widget.popup.prototype.start = function () {
    this.stop();
    this.curY = this.el.offsetTop;
    this.startTime = (new Date()).getTime();
    this.timeoutId = setTimeout(this.intervalFunc, this.interval);
};
hc.widget.popup.prototype.stop = function () {
    if(this.timeoutId)
        clearTimeout(this.timeoutId);
	this.timeoutId = 0;
};
hc.widget.popup.prototype.step = function () {
    var elapsedTime = (new Date()).getTime() - this.startTime;
    var done = elapsedTime >= this.duration;
    var y;
    if(done)
        y = this.curY = this.endY;
    else {
        y = this.trans(elapsedTime,this.curY,this.endY-this.curY,this.duration);
    }
    this.el.style.top = y + 'px';
	if (!done)
		this.timeoutId = setTimeout(this.intervalFunc,this.interval);
};
hc.widget.popup.prototype.open = function () {
    this.endY = this.dstY;
    this.start();
};
hc.widget.popup.prototype.close = function () {
    this.endY = this.bgnY;
    this.start();
};
/*= slider
--------------------------------------------------*/
hc.widget.slider = function(el,opt) {
    this.el = hc.util.getElement(el);
    this.curPanel = null;
    if(typeof opt.def != 'undefined') { //default index
		if (typeof opt.def == 'number')
			this.curPanel = this.getPanels()[opt.def];
		else
		    this.curPanel = this.getPanels()[0];
    }

    this.curPanel.style.display = 'block';
};
hc.widget.slider.prototype.getGroup = function() {
	return hc.util.getElementChildren(this.el)[0];
};
hc.widget.slider.prototype.getPanels = function() {
	return hc.util.getElementChildren(this.getGroup());
};
hc.widget.slider.prototype.showPanel = function(tabIndex) {
    try {
        this.curPanel.style.display = 'none';
        this.curPanel = this.getPanels()[tabIndex];
        this.curPanel.style.display = 'block';
    }
    catch (ex) {}
};
/*= tabbed panels
--------------------------------------------------*/
hc.widget.tabbed = function (el,opt) {
    this.el = hc.util.getElement(el);
    this.mySlider = new hc.widget.slider(this.getContentGroup(),{def:opt.def});
}; 
hc.widget.tabbed.prototype.getTabGroup = function() {
	if (this.el) {
		var children = hc.util.getElementChildren(this.el);
		if (children.length)
			return children[0];
	}
	return null;
};
hc.widget.tabbed.prototype.getTabs = function() {
	var tabs = [];
	var tg = this.getTabGroup();
	if (tg) tabs = hc.util.getElementChildren(tg);
	return tabs;
};
hc.widget.tabbed.prototype.getContentGroup = function() {
	if(this.el) {
	    var children = hc.util.getElementChildren(this.el);
	    if (children.length) {
	        return children[1];
	    }
	}
	return null;
};
hc.widget.tabbed.prototype.showPanel = function(tabIndex){
    this.mySlider.showPanel(tabIndex);
};
/*= menu 
--------------------------------------------------*/
hc.widget.menu = function (el,opt) {
    this.el = hc.util.getElement(el);
    this.right = this.el.offsetWidth + this.el.offsetLeft;
    
    this.items = [];
    var lis = this.el.getElementsByTagName('li');
    for(var i=0;i<lis.length;++i) {
        this.items[i] = new hc.widget.menu.li(lis[i],{menu:this});
    }
    for(var i=0;i<lis.length;++i) {
        this.items[i].el.style.position = 'static';
    }
};
hc.widget.menu.li = function (el,opt) {
    this.el = hc.util.getElement(el);
    this.menu = ((typeof opt != 'undefined' && opt.menu) ? opt.menu : null);

    var uls = this.el.getElementsByTagName('ul');
    this.submenu = null;
    if(uls.length>0) {
        this.submenu = new hc.widget.menu.ul(uls[0],{menu:this.menu});
    }
    
    var on, off;
    var me = this;    
    
    if(this.submenu) {
        on = function () {
            me.togglePosition();
            me.el.className += (hc.util.browser.agent == 'Explorer' ? ' hover' : '');
            //me.el.className += ' hover';
            me.submenu.open(); 
        };
        off = function () {
            me.togglePosition();
            me.el.className = me.el.className.replace(' hover', '');
            me.submenu.close(); 
        };
    } else {
        on = function () {
            me.togglePosition();
            me.el.className += (hc.util.browser.agent == 'Explorer' ? ' hover' : '');
            //me.el.className += ' hover';
        };
        off = function () {
            me.togglePosition();
            me.el.className = me.el.className.replace(' hover', '');
        };
    }
    this.el.onmouseover = on;
    this.el.onmouseout = off;
    
    //this.el.style.position = 'static';
};
hc.widget.menu.li.prototype.togglePosition = function () {
    if(this.el.style.position == 'relative') {
        this.el.style.position = 'static';
    } else {
        this.el.style.position = 'relative';
    }
};
hc.widget.menu.ul = function (el,opt) {
    this.el = hc.util.getElement(el);
    this.menu = ((typeof opt != 'undefined' && opt.menu) ? opt.menu : null);
    if(this.menu) {
        var el = this.el;
        var left = 0;
        while(el != null && el.offsetParent != this.menu.el.offsetParent) {
            left += el.offsetLeft;
            el = el.offsetParent;
        }
        if(left + this.el.offsetWidth > this.menu.right) {
            var parent = this.el.parentNode;
            var offsetX = parent.offsetWidth - (this.el.offsetLeft - parent.offsetLeft);
            this.el.className += ' right';
        }
    } 
    if(hc.util.browser.agent == 'Explorer' && hc.util.browser.version < 7) {
        //this.createIframe();
    }
};
hc.widget.menu.ul.prototype.createIframe = function () {
    this.iframe = document.createElement('iframe');
	this.iframe.src = 'javascript:false';
	this.iframe.tabIndex = '-1';
	this.iframe.style.position = 'absolute';
	this.iframe.style.left = this.el.offsetLeft + 'px';
	this.iframe.style.top = this.el.offsetTop + 'px';
	this.iframe.style.width = this.el.offsetWidth + 'px';
	this.iframe.style.height = this.el.offsetHeight + 'px';
	this.iframe.style.visibility = 'hidden';
	this.iframe.style.filter = 'Alpha(opacity=0)';
	this.el.parentNode.appendChild(this.iframe);
};
hc.widget.menu.ul.prototype.toggleIframe = function () {
    if(this.iframe != null) {
        if(this.iframe.style.visibility == 'hidden') {
            this.iframe.style.visibility = 'visible';
        } else {
            this.iframe.style.visibility = 'hidden';
        }
    }
};
hc.widget.menu.ul.prototype.open = function () {
    this.el.style.visibility = 'visible';
    this.toggleIframe();
};
hc.widget.menu.ul.prototype.close = function () {
    this.el.style.visibility = 'hidden';
    this.toggleIframe();
};
/*= pop desc box
--------------------------------------------------*/
hc.widget.box = function (opt) {
    this.hasDropShadow = false;
    if(typeof opt != 'undefine') {
        if(typeof opt.shdw != 'undefined') {
            this.hasDropShadow = opt.shdw;
        }
    }    
    this.container = document.createElement("div");
    this.container.className = "info";
    if(this.hasDropShadow) {
        this.container.className += " drpshdw";
    }
    this.content = document.createElement("div");
    this.content.className = "content";
    
    this.container.appendChild(this.content);
};
hc.widget.box.prototype.show = function () {
    this.container.style.display = 'block';  
};
hc.widget.box.prototype.hide = function () {
    this.container.style.display = 'none';  
};
/*= content custom functions
--------------------------------------------------*/
function disclose(el) {
    var el = hc.util.getElement(el);
    if(el.style.display != 'none') {
        el.style.display = 'none'
    } else {
        el.style.display = 'block'
    }
}
function info_s(el,opt) {
    var el = hc.util.getElement(el);
    var parent = el.parentNode;
    if(typeof el.info != 'undefined') {
        el.info.show();
    } else {
        el.info = new hc.widget.box({shdw:true});
        if(typeof opt != 'undefined') {
            if(typeof opt.html == 'string') {
                el.info.content.innerHTML = opt.html;
            }
            if(typeof opt.w == 'number') {
                el.info.content.style.width = opt.w + 'px';
            }
        }
        parent.insertBefore(el.info.container,el);
        el.info.show()
    }
}
function info_h(el) {
    var el = hc.util.getElement(el);
    var parent = el.parentNode;
    if(typeof el.info != 'undefined') {
        el.info.hide();
    }
}
function scrollTop() {
    if (document.documentElement && document.documentElement.scrollTop)
	    document.documentElement.scrollTop = 0;
    else if (document.body)
	    document.body.scrollTop = 0;
}
