// Browser Detection
var ie5   = ( document.getElementById && document.all ); 
var moz   = ( document.getElementById &&! document.all );
var opera    = ( navigator.userAgent.indexOf( 'Opera' ) != -1 );
if ( opera ) ie5 = false;



// Global pageinit function
function pageinit() {
	if (MM_findObj('fadingphotos')) {
		FadingPhotosInit();
	}
}



// Standard MM functions
function MM_findObj(n, d) { //v4.0
	var p,i,x;
	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById)
		x=document.getElementById(n); return x;
}
	
function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
		v=args[i+2];
		if (obj.style) {
			obj=obj.style;
			v=(v=='show')?'visible':(v='hide')?'hidden':v;
		}
		obj.visibility=v;
		obj.display=(v=='visible' ? 'block' : 'none');
	}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
	
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



// SubNavMenu functions
var SubNavMenuOn = '';
var SubNavMenuTimeout = 0;
var TerNavMenuOn = '';
var TerNavMenuTimeout = 0;
var TooltipNavOn = '';
var TooltipNavTimeout = 0;

function SubNavMenu(menuid, state) {
	if (state == 'show') {
		if (SubNavMenuTimeout!=0) {
			clearTimeout(SubNavMenuTimeout);
			SubNavMenuTimeout = 0;
		}
		if (SubNavMenuOn != menuid) {
			if (SubNavMenuOn.length>0) { DoSubNavMenu(SubNavMenuOn, 'hide'); }
			DoSubNavMenu(menuid, state);
		}
	} else {
		SubNavMenuTimeout = setTimeout("DoSubNavMenu('"+menuid+"','"+state+"')", 500);
	}
}

function DoSubNavMenu(menuid, state) {
	var no = MM_findObj('nav'+menuid);
	var so = MM_findObj('subnav'+menuid);
	if (so) {
		so.style.top = '-1000px';
		MM_showHideLayers('subnav'+menuid, '', state);
		//so.style.left = (no.offsetLeft + Math.floor(no.offsetWidth/2) - Math.floor(so.offsetWidth/2)) + 'px';
		so.style.left = (no.offsetLeft - 6) + 'px';
		so.style.top = '14px';
		if (state == 'show') {
			SubNavMenuOn = menuid;
		} else {
			SubNavMenuTimeout = 0;
			SubNavMenuOn = '';
		}
	}
}

function TerNavMenu(menuid, state) {
	if (state == 'show') {
		if (TerNavMenuTimeout!=0) {
			clearTimeout(TerNavMenuTimeout);
			TerNavMenuTimeout = 0;
		}
		if (TerNavMenuOn != menuid) {
			if (TerNavMenuOn.length>0) { DoTerNavMenu(TerNavMenuOn, 'hide'); }
			DoTerNavMenu(menuid, state);
		}
	} else {
		TerNavMenuTimeout = setTimeout("DoTerNavMenu('"+menuid+"','"+state+"')", 500);
	}
}

function DoTerNavMenu(menuid, state) {
	var no = MM_findObj('terbutton'+menuid);
	var so = MM_findObj('ternav'+menuid);
	if (so) {
		so.style.top = '-1000px';
		MM_showHideLayers('ternav'+menuid, '', state);
		so.style.left = (no.offsetLeft - 2) + 'px';
		so.style.top = '131px';
		if (state == 'show') {
			TerNavMenuOn = menuid;
		} else {
			TerNavMenuTimeout = 0;
			TerNavMenuOn = '';
		}
	}
}





// Miscellaneous Custom Functions

function CenteredPopup(url, width, height) {
	var left = Math.floor(screen.availWidth/2 - width/2);
	var top = Math.floor(screen.availHeight/2 - height/2);
	var w = window.open(url, 'GWMpopup1', 'width='+width+',height='+height+',left='+left+',top='+top+',toolbar=no,menubar=no,locationbar=no,scrollbars=yes,resizable=yes');
	w.focus();
	return false;
}

function ButtonToggle(id) {
	var o = MM_findObj(id);
	if (o) {
		o.checked = true;
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}



// Fading Photo Options
var FadingPhotosDelay = 6000;
var FadingPhotosZoneDelay = 2000;
var FadingPhotosStepOpacity = 4;
var FadingPhotosStepTime = 20;
var FadingPhotosNextTransition = 0;
var FadingPhotosImmediateCancel = 0;
var FadingPhotosBusy = 0;
var FadingPhotosDelays = new Array();

function FadingPhotosInit() {
	var z;
	for (z=0; z<9; z++) {
		if (MM_findObj('photozone'+z)) {
			FadingPhotosDelays[z] = FadingPhotosDelay;
			if (typeof(window['FadingPhotosDelay_'+z]) != 'undefined')
				FadingPhotosDelays[z] = window['FadingPhotosDelay_'+z];
			if (FadingPhotosDelays[z] <= 0) FadingPhotosDelays[z] = FadingPhotosDelay;
			if (MM_findObj('fadingphoto_'+z+'_1')) {
				if (MM_findObj('fadingphoto_'+z+'_bg')) {
					MM_showHideLayers('fadingphoto_'+z+'_bg', '', 'show');
				}
				FadingPhotosFade(z, 1, 1, 0);
				if (window.FadingPhotoPreloads) {
					for (i in window.FadingPhotoPreloads) {
						o = MM_findObj('fadingphotoimg_'+i);
						if (o) {
							o.src = window.FadingPhotoPreloads[i];
						}
					}
				}
				if (MM_findObj('fadingphoto_'+z+'_2')) {
					FadingPhotosNextTransition = setTimeout('FadingPhotosTransition('+z+',1,2)', FadingPhotosDelays[z] + (z*FadingPhotosZoneDelay));
				}
			}
		}
	}
}

function FadingPhotosTransition(z, a, b) {
	FadingPhotosNextTransition = 0;
	
	// set layering for fadingphoto containers
	var oa = MM_findObj('fadingphoto_'+z+'_'+a);
	var ob = MM_findObj('fadingphoto_'+z+'_'+b);
	oa.style.zIndex = 50+a;
	ob.style.zIndex = 60+b;

	FadingPhotosFade(z, a, 0, b);
	if (MM_findObj('fadingphoto_'+z+'_'+(b+1))) {
		FadingPhotosNextTransition = setTimeout('FadingPhotosTransition('+z+','+b+','+(b+1)+')', FadingPhotosDelays[z]);
	} else {
		FadingPhotosNextTransition = setTimeout('FadingPhotosTransition('+z+','+b+',1)', FadingPhotosDelays[z]);
	}
}

function FadingPhotosFade(z, id, fadein, nextin) {
	FadingPhotosBusy = 1;
	if (fadein) {
		FadingPhotosSetOpacity(0, 'fadingphoto_'+z+'_'+id, 0);
		FadingPhotosSetOpacity(0, 'fadingphoto_'+z+'_'+id+'a', 1);
		FadingPhotosSetOpacity(0, 'fadingphoto_'+z+'_'+id+'b', 3);
		FadingPhotosSetOpacity(100, 'fadingphoto_'+z+'_'+id+'mid', 2);
		setTimeout('FadingPhotosFadeStep('+z+','+id+','+fadein+','+FadingPhotosStepOpacity+','+nextin+')', 0);
		setTimeout('FadingPhotosCallback('+z+','+id+')',0);
	} else {
		setTimeout('FadingPhotosFadeStep('+z+','+id+','+fadein+','+(100-FadingPhotosStepOpacity)+','+nextin+')', 0);
	}
}

function FadingPhotosFadeStep(z, id, fadein, opa, nextin) {
	if (FadingPhotosImmediateCancel) {
		FadingPhotosImmediateCancel = 0;
		opa = 0;
		nextin = 0;
	}
	if (opa > 100) { opa = 100; }
	if (opa < 0) { opa = 0; }

	// set opacity of master container and sub-containers
	FadingPhotosSetOpacity(opa, 'fadingphoto_'+z+'_'+id, 0);
	FadingPhotosSetOpacity(opa, 'fadingphoto_'+z+'_'+id+'a', 1);
	FadingPhotosSetOpacity(opa, 'fadingphoto_'+z+'_'+id+'b', 3);
	
	if (opa > 0 && opa < 100) {
		setTimeout('FadingPhotosFadeStep('+z+','+id+','+fadein+','+(fadein ? opa+FadingPhotosStepOpacity : opa-FadingPhotosStepOpacity)+','+nextin+')', FadingPhotosStepTime);
	} else if (nextin) {
		FadingPhotosFade(z, nextin, 1, 0);
	} else {
		FadingPhotosBusy = 0;
	}
}

function FadingPhotosSetOpacity(opa, obj, zid) {
	var o = MM_findObj(obj);
	if (o) {
		o.style.opacity = (opa / 100);
		o.style.MozOpacity = (opa / 100);
		if (o.filters) {
			if (o.filters.alpha) {
				o.filters.alpha.opacity = opa;
			}
		}
		o.style.display = 'inline';
		if (zid) { o.style.zIndex = zid; }
	}
}



/***********************************************
* Cool DHTML tooltip script- © 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 offsetxpoint=30 //Customize x offset of tooltip
var offsetypoint=-20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var tipobj;


function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth, dX, dY){
tipobj=MM_findObj('dhtmltooltip');
if (!tipobj) {
	tipobj = document.createElement("div")
	tipobj.id = 'dhtmltooltip'
	document.body.appendChild(tipobj)
}
if (typeof dX!="undefined") offsetxpoint = dX
if (typeof dY!="undefined") offsetypoint = dY
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

