preloadflag = true;

// Browser Detection
var V = navigator.appVersion.substring(0,1);
var brsr = 0;
if (V < 4) {
	top.alert("This site uses java to support its major navigation.\n You may have trouble viewing the site");
} else if (navigator.appName.indexOf("Netscape") > -1) {

} else if (navigator.appName.indexOf("Explorer") > -1) {
		var T = navigator.appVersion.indexOf("MSIE");
		T += 5;
		V = navigator.appVersion.substring(T,eval(T+1));
}
if (navigator.appName.indexOf("Netscape") > -1) {
	brsr = 1;
} else if (navigator.appName.indexOf("Explorer") > -1) {
	if (V < 5) {

	} else {
		brsr = 2;
	}
}


function getElmById(aID){
	var rv = null;

	if (document.getElementById) {
		//alert("byId");
		rv = document.getElementById(aID)
	} else if (document.layers) {
		//alert("layers");
		rv = document.layers[aID]
	} else if (document.all) {
		//alert("all");
		rv = document.all[aID];
	}

	return rv;
}


function alignContent () {

	//top.alert(getElmById("mainFraming").offsetHeight);
	contentBottom = getElmById("mainFraming").offsetHeight;
	if ((contentBottom) % 6 != 0) {
		contentBottom = ((Math.ceil((contentBottom)/6)) * 6);
	//	top.alert(contentBottom);
		getElmById("mainFraming").style.height = contentBottom;
	//	top.alert(getElmById("mainFraming").offsetHeight);
	}
	// getElmById("sizeMe").style.height = getElmById('footerPage').offsetHeight + maxBottom;

}

function openPhotoCredit () {
	showHideLayers('','photoCreditClosed','hidden','photoCreditOpen','visible');
}

function closePhotoCredit () {
	showHideLayers('','photoCreditClosed','visible','photoCreditOpen','hidden');
}


function getElementById(id){
	var el = null;

	if (document.getElementById) {
		// isMozilla || isIE5
		el = document.getElementById(id)
	} else if (document.layers) {
		// isNetscape4
		el = document.layers[id]
	} else if (document.all) {
		// isIE4
		el = document.all[id];
	}

	return el;
}



// Email Spam hiding.
function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}
function linkMail(host,user,cls) {
	document.write('<a href="javascript:popMail(\''+ host +'\',\''+ user +'\');"');
	if (cls) {
		document.write(' class="'+ cls +'"');
	}
	document.write('>');
	showMail(host,user);
	document.write('</a>');
}
function showMail(host,user) {
	var acct = user +'@'+ host;
	document.write(acct);
}


function centerPop(page,w,h,args){
	if (w > 0) {
	} else {
		w = 650
	}
	if (h > 0) {
	} else {
		h = 550
	}
	var width
	var height
	var leftdist
	var topdist
	width = screen.width;
	height = screen.height;
	leftdist = Math.round((width - w) / 2);
	topdist = Math.round((height - h) / 2);
	if (args = '') {
		args = 'resizable=1,menubar=0,location=0,scrollbars=1,status=1,toolbar=0';
	}
	cpw = window.open(page,'cpw','width='+ w +',height='+ h +',top='+topdist+',left='+leftdist+','+ args);
	cpw.focus();
}


function centerPopMenu(page,w,h){

if (w > 0) {
} else {
 w = 650
}
if (h > 0) {
} else {
 h = 550
}

var width
var height
var leftdist
var topdist
width = screen.width;
height = screen.height;
leftdist = Math.round((width - w) / 2);
topdist = Math.round((height - h) / 2);

gwin = window.open(page,'gwin','width='+ w +',height='+ h +',top='+topdist+',left='+leftdist+',resizable=1,menubar=1,location=0,scrollbars=1,status=1,toolbar=0');
gwin.focus();

}


	function PopWin(HEIGHT,WIDTH,URL) {
		var PopWin = window.open(URL,'PopWin',"width="+ WIDTH +",height="+ HEIGHT +",scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
		PopWin.focus()
	}

	function newImage(arg) {
		if (document.images) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}

		//img_on	= newImage("/pics/index_nav/index_con.gif");
		//img_off	= newImage("/pics/index_nav/index_con.gif");
	}

	function resWin(page) {
		var resWin = window.open(page,'resWIn',"width=499,height=333,scrollbars=0,toolbar=1,location=0,directories=0,status=1,menubar=0,resizable=1");
		resWin.open
	}

	function changeImages() {
	//	if (document.images && (preloadFlag == true)) {
			for (var i=0; i<changeImages.arguments.length; i+=3) {
			//  top.alert (document.layers[i].document[changeImages.arguments[i+1]].name)
			//document.layers[changeImages.arguments[i]].document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src");
				if (brsr == 1) {
			//		if (changeImages.arguments[i] != '') {
			//			document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
			//		} else {
						if (document[changeImages.arguments[i+1]]) document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
			//		}
				}
				if (brsr == 2) {
					if (document[changeImages.arguments[i+1]]) document[changeImages.arguments[i+1]].src = eval(changeImages.arguments[i+2]+".src")
				}
			}
	//	}
	}
	function changeImagesStr() {
			for (var i=0; i<changeImagesStr.arguments.length; i+=3) {
				if (brsr == 1) {
						document[changeImagesStr.arguments[i+1]].src = changeImagesStr.arguments[i+2]
				}
				if (brsr == 2) {
					document[changeImagesStr.arguments[i+1]].src = changeImagesStr.arguments[i+2]
				}
			}
	}

	function rollOver (item,state) {
		if (state) {
			changeImages('','i'+item,'i'+item+'_on');
		} else {
			changeImages('','i'+item,'i'+item+'_off');
		}
	}

	function setClass() {
		var args=setClass.arguments;
		var ston = 0;

		if (brsr != 0) {
			for (i = ston; i<(args.length-1); i+=2) {
				var obj = args[i];
				var cls = args[i+1];
				if (brsr == 1 && V >= 5) {
					document.getElementById(obj).className = cls;
				}
				if (brsr == 2) {
					if (document.all[obj]) {
						document.all[obj].className = cls;
					}
				}
			}
		}
	}

	function showHideLayers() {
		var args=showHideLayers.arguments;
		var ston = 1;
		var baser = args[0];

		if (brsr != 0) {
			for (i = ston; i<(args.length-1); i+=2) {
				var obj = args[i];
				var vis = args[i+1];
				if (brsr == 1 && V < 5) {
						if (document.layers[obj]) document.layers[obj].visibility = vis;
				}
				if (brsr == 1 && V >= 5) {
					if (document.getElementById(obj)) {
						document.getElementById(obj).style.visibility = vis;
					}
				}
				if (brsr == 2) {
					if (document.all[obj]) {
						document.all[obj].style.visibility = vis;
					}
				}
			}
		}
	}



	function delayHide() {
			if (t==0) {
					removeall();
					lCount = 0;
			}
			if (t==2) {
					lCount = 0;
			}
			if (t==1) {
					lCount = lCount + 1;
					if (lDelay <= lCount) {
							t = 0;
					}
					if (lDelay >= lCount) {
							setTimeout('delayHide(' + t + ')',pause);
					}
			}
			return false;
	}



/**
 * select_tree = ['level1','level2']
 *
 * select_tree = {'level1': {'value1':{
 *
 * clearOptions = {'level1':'Clear Text'}
 */


function SelectMenuTree ()
{
    this.select_tree = null;

    this.tree_data  = null;

    this.startValues = null;

    this.clearOptions = null;

    this.onChange = function (elm) {
        var id = $(elm).identify();
        this.updateNextSelect(id);
    }

    this.updateNextSelect = function (id)
    {
        var treeIndex = this.findInTree(id);
        if (treeIndex !== false) {
            var next = treeIndex + 1;
            if (this.select_tree[next]) {
                var nextId = this.select_tree[next];
                this.updateSelect(nextId,id);
            }
        }
    }

    this.updateSelect = function (id,parentId)
    {
//      top.alert(id);
        $(id).disabled = false;
        if (parentId) {
            if ($(parentId).value) {
               var parentValue = $(parentId).value;
               if (this.tree_data[id][parentValue]) {
                   this.updateSelectOptions(id,this.tree_data[id][parentValue]);
               }
            } else {
              this.updateSelectOptions(id,null);
            }
        } else {
            if (this.tree_data[id]
                    && this.findInTree(id) === 0) {
                this.updateSelectOptions(id,this.tree_data[id]);
            }
        }
        this.updateNextSelect(id);
        if ($(id).descendants().length == 0) {
            $(id).disabled = true;
        }
    }

    this.updateSelectOptions = function (id,data)
    {
        if ($(id).type.indexOf('select') >= 0) {
            $(id).update();
            if (this.clearOptions != null) {
                if (this.clearOptions[id]) {
                    var option = new Element('option',{'value':''});
                    option.update(this.clearOptions[id]);
                    $(id).appendChild(option);
                }
            }
            if (data != null) {
                for (var k in data) {
                //    top.alert(k +':'+ v);
                    var v = data[k];
                    var option = new Element('option',{'value':k});
                    option.update(v);
                    if (this.testSelectedStartValue(id,k)) {
                        option.writeAttribute('selected',true)
                    }
                    $(id).appendChild(option);
                }
            }
        }
    }

    this.testSelectedStartValue = function (id,value)
    {
        var startValue = this.startValues[id];
        if (Object.isNumber(startValue)
                || Object.isString(startValue)) {
            if (startValue == value) {
                return true;
            }
            return false;
        }
        if (Object.isArray(startValue)
                || Object.isHash(startValue)) {
            for (var key in startValue) {
                if (startValue[key] == value) {
                    return true;
                }
            }
            return false;
        }
    }

    this.findInTree = function (id)
    {
        for (i=0;i<this.select_tree.length;i++) {
            if (id == this.select_tree[i]) {
                return i;
            }
            return false;
        }
    }

    this.init = function (startValues)
    {
        this.startValues = startValues;
        this.updateSelect(this.select_tree[0]);
    }

}


var GB_ROOT_DIR = null;


function greyBoxLoader ()
{
    if (GB_ROOT_DIR == null) {
        GB_ROOT_DIR = '/include/greybox/';
        externalLoader('/include/greybox/AJS.js','js');
        externalLoader('/include/greybox/AJS_fx.js','js');
        externalLoader('/include/greybox/gb_scripts.js','js');
        externalLoader('/include/greybox/gb_styles.css','css');
    }
}

function externalLoader (file,type)
{
    if (type == 'css') {
        elm = new Element('link',{'href':file,'type':'text/css','media':'screen'})
        //.appendChild(elm);
    } else if (type == 'js') {
        elm = new Element('script',{'src':file,'type':'text/javascript'})
       // $('head').appendChild(elm);
    }
    headList = $$('head');
    headElm  = headList[0];
    headElm.appendChild(elm);
}


jQuery(function () {
    if (jQuery('ul.icons li')) {
        jQuery('ul.icons li').hover(
            function() {jQuery(this).addClass('ui-state-hover');},
            function() {jQuery(this).removeClass('ui-state-hover');}
        );
    }
});
