function toggle ( divnum ) {
	if ( document.getElementById ) {
		
		var d1 = document.getElementById('cat'+divnum);
		var i1 = document.getElementById('click'+divnum);
		
		if (d1.className == 'box') {
			d1.className = 'hidden';
			i1.className = 'up';
		} else {
			d1.className = 'box';
			i1.className = 'down';
		}
	}
}

function doPopup(url, windowWidth, windowHeight, resize, returnType) {

	windowId = 'window' + Math.ceil( Math.random() * 3256 + Math.random() * 587 );
	
	if ( resize=='yes' ) {
		windowWidth = windowWidth + 20;
	} else if ( windowWidth > screen.availWidth ||  windowHeight > screen.availHeight ) {
		windowWidth = windowWidth + 20;
	}
	if ( windowWidth > screen.availWidth ) {
		windowWidth = screen.availWidth - 20;
	}
	if ( windowHeight > screen.availHeight ) {
		windowHeight = screen.availHeight - 55;
	}

	xPos = Math.ceil( ( screen.availWidth / 2 ) - ( windowWidth / 2 ) );
	yPos = Math.ceil( ( screen.availHeight / 2 ) - ( windowHeight / 2 ) );

	window.open( url, windowId, 'left=' + xPos + ',top=' + yPos + ',width=' + windowWidth + ',height=' + windowHeight + ',scrollbars=no,resizable=' + resize + ',location=no,directories=no,status=no' );

	if ( returnType=='false' ) {
		return false;
	} else {
		return true;
	}
} 


function doPopupRelativeSize(url, screenPercentage) {
	windowId='window'+Math.ceil(Math.random()*3256+Math.random()*587);
	
	windowWidth=(screen.availWidth*screenPercentage)/100;
	windowHeight=(screen.availHeight*screenPercentage)/100;
	
	// Calculate the position to centre on screen
	xPos = ((screen.availWidth/2)-(windowWidth/2));
	yPos = ((screen.availHeight/2)-(windowHeight/2));
			
	window.open(url+'&windowWidth='+windowWidth+'&windowHeight='+windowHeight,windowId,'left='+xPos+',top='+yPos+',width='+windowWidth+',height='+windowHeight+',scrollbars=auto,resizable=auto,location=no,toolbar=no,directories=no,status=no');

	return false;
}


function scroller(element, totalPanels, currentPanel, direction, panel_title) {
	if(totalPanels>1) {
		var panels = new Array();
		for(i=1; i<=totalPanels; i++) {
			panels[i]=element+i;
		}
			
		if(direction=='next') {
			if(currentPanel>=totalPanels) currentPanel1=1;
			else currentPanel1=currentPanel+1;
		} else { 
			if(currentPanel==1) currentPanel1=totalPanels;
			else currentPanel1=currentPanel-1;
		}
		panelName = panel_title+"_circles";
		document.getElementById(panelName).className = "circle"+currentPanel1;
		setOpacity(0, panels[currentPanel1]); // set to 0 so we don't get a flash of this div before it fades up.
		document.getElementById(panels[currentPanel]).style.display="none";
		fadeElementSetup(panels[currentPanel1], 0, 100, 5);
	}
	return currentPanel1;
}

function fadeElementSetup(theID, fdStart, fdEnd, fdSteps) {
  fadeSteps = fdSteps;
  fadeCurrent = 0;
  fadeAmount = (fdStart - fdEnd) / fadeSteps;
  document.getElementById(theID).style.display="block";
  fadeTimer = setInterval("fadeElement('"+theID+"')", 25);
}

function fadeElement(theID) {
  fadeCurrent++;
  // Set the opacity depending on if we're adding or subtracting (pos or neg)
  if (fadeAmount < 0) {
    setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);
  } else {
    setOpacity(100 - (fadeCurrent * fadeAmount), theID);
  }
  if (fadeCurrent == fadeSteps) {
  	// We're done, so clear
    clearInterval(fadeTimer);
  }
}

function setOpacity(opacity, theID) { 

  var object = document.getElementById(theID).style;

  // If it's 100, set it to 99 for Firefox.
  if (navigator.userAgent.indexOf("Firefox") != -1) {
    if (opacity == 100) { opacity = 99.999; } 
  }

  // Multi-browser opacity setting

  object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
  object.KhtmlOpacity = (opacity / 100);            // Safari 1.1 or lower, Konqueror
  object.MozOpacity = (opacity / 100);              // Older Mozilla+Firefox
  object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla

}

