// JavaScript Document

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		Curve_01_over = newImage("images/Curve_01-over.jpg");
		Curve_02_over = newImage("images/Curve_02-over.jpg");
		Curve_03_over = newImage("images/Curve_03-over.jpg");
		Curve_04_over = newImage("images/Curve_04-over.jpg");
		preloadFlag = true;
	}
}

var reflink = 1;
var allowtoggle = 1;
var curShowing = 0;
function changeFrame(frameName,frameSource) {
	
	//window.alert(frameSource);
	frameName = 'Frame_' + frameName;
	frameName = 'EveryFrame';
	//window.alert(frameName);
	//[frameName].location.href=[frameSource]; 
	document.getElementById(frameName).src=frameSource;

}

function showpopup( pageToLoad, winName, width, height, center) {

	    xposition=0; yposition=0;
	    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
	        xposition = (screen.width - width) / 2;
	        yposition = (screen.height - height) / 2;
	    }
	    args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=0," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;           
	    window.open( pageToLoad,winName,args );

}

function showGalleryNav(bShow) {
if (allowtoggle == 1) {
		if (bShow==1 && curShowing==0) {
			curShowing = 1;
			//Effect.Appear('gall-navigation2', { duration: 1.0, from:0, to:.5 });
			Effect.Appear('gall-navigation', { duration: .5, from:0, to:.5 });
			
		}
		else if (allowtoggle == 1 && bShow==0 && curShowing==1) {
			curShowing = 0;
			Effect.Fade('gall-navigation', { duration: .5 });
			//Effect.Fade('gall-navigation2', { duration: 1.0 });	
			
		}	
	}

}

function toggleGalleryNav(bActive) {
	if (bActive) {
		allowtoggle = 1;
	}
	else {
		allowtoggle = 0;
	}	
}
function ClickImage(curlink,totallinks) {
	
	if (curlink == 99) {
		if (reflink==totallinks) {
			curlink = 1;
		}
		else {
			curlink = reflink+1;
		}	
		reflink = curlink;
		//alert('reflinkF: '+reflink);
	}
	else if (curlink == 88) {
		if (reflink==1) {
			curlink = totallinks;
		}
		else {
			curlink = reflink-1;
		}	
		reflink = curlink;
		//alert('reflinkB: '+reflink);
	}
	else {
		reflink = curlink;
	}
	
	for(var i=1; i<totallinks+1; i++) {
		if (i==curlink) {	
			changeClass('bullet'+curlink, 'active');
		}	
		else {
			changeClass('bullet'+i, 'inactive');
		}
	}


	for(var i=1; i<totallinks+1; i++) {
		if (i==curlink) {	
			Effect.Appear('PhotoImage'+curlink, { duration: 1.0, from:0, to:1.0 });
		}	
		else {
			Effect.Fade('PhotoImage'+i, { duration: 0 });
		}
	}

	toggleBox('ImageContainer',1);
	toggleBox('Resume',1);

}

function clickhomediv(divname,icurdiv,totallinks) {
	
	for(var i=1; i<totallinks+1; i++) {
	
		if (i==icurdiv) {	
			Effect.Appear(''+divname+i, { duration: 1.0, from:0, to:1.0 });
		//	alert('show: '+divname+i);	
		}	
		else {
			Effect.Fade(''+divname+i, { duration: 0 });
		//	alert('hide: '+divname+i);
		}
	}	
}


function confirmCancel(sPopupLayer) 
{ 
var cancelChanges=confirm("Are you sure you wish to delete this item? All content & sub-pages related to this link will be deleted."); 
if (cancelChanges) 
new Effect.BlindDown(sPopupLayer, {duration: .3});
else 
return false ; 
} 

function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}


function menuHover(obj,stopHide) {
	if (!stopHide) {
		hideSubnavs();
	}
	
	if (obj.className != "current") {
		obj.className = "current";	
	
		obj.onmouseout = function() {
			obj.className = "";	
		}
	}
}

function showSubnav(num) {
	menuHover(document.getElementById("menu"+num),true);
	
	if (document.getElementById('subMenu'+num).style.display == "none") {
		toggleBox('subMenu'+num,1); 
		opacity('subMenu'+num, 0, 100, 200);
	}
	
	if (isSubShowing() != false && isSubShowing() != num) {
		document.getElementById('subMenu'+isSubShowing()).style.display = "none";
	}
}

function hideSubnavs() {
	for (var i = 1; i < 3; i++) {
		if (document.getElementById('subMenu'+i).className != "subMenuCurrent") {
			if (isSubShowing() != false) {
				document.getElementById('subMenu'+i).style.display = "none";
			} else {
				hideSubNav(i);
			}
		} else {
			showSubnav(i);
		}
	}
}
function hideSubNav(num) {
	opacity('subMenu'+num, 100, 0, 300);
	toggleBox2('subMenu'+num,0);
}

function toggleBox(szDivID, iState) { // 1 visible, 0 hidden

	if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
       // obj.style.visibility = iState ? "visible" : "hidden";
		obj.style.display= iState ? "" : "none"; 
        //obj.style.zIndex=0
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function toggleBox2(szDivID, iState) { // 1 visible, 0 hidden
	window.setTimeout('toggleBox(\''+szDivID+'\','+iState+')',200);
}

function isSubShowing() {
	for (var i = 1; i < 3; i++) {
		if (document.getElementById('subMenu'+i).className == "subMenuCurrent") {
			return i;
		}
	}
	
	return 0;
}

// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=1500;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  FadeInImage(pictureID,nextImage,backgroundID);
  var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

