/********** INDEX IMAGE SCROLLER **********/

var timer;

function scrollPicsLeft() {

	clearInterval( timer);
	timer = setInterval("document.getElementById('scroller').scrollLeft -= 4", 20);
	
}

function scrollPicsRight() {

	clearInterval( timer);
	timer = setInterval("document.getElementById('scroller').scrollLeft += 4", 20);
}

function stopScroll() {

	clearInterval( timer);
}


/********** WINDOW EXPANDER ***********/

var windowExpanded = [ false, false];
var currentSize;
var toExpand;
var toReduce;
var t, r;
var limit;
var otherNum;

function changeWindow( winNum) {
	windowExpanded[winNum] == true ? retractWindow( winNum) : expandWindow( winNum);
	toExpand = document.getElementById("window" + winNum);
}

function expandWindow( winNum) {

	windowExpanded[winNum] = true;

	winNum == 0 ? otherNum = 1 : otherNum = 0; 
	if( windowExpanded[otherNum])
		reduceWindow(otherNum);	

	currentSize = 10;
	windowExpanded[otherNum] == true ? limit = 210 : limit = 430;

	t = self.setInterval("expand()", 1);
	
	alert('expanding');
}

function expand() {

	if( currentSize == limit)
		clearInterval(t);
	currentSize += 20;
	toExpand.style.height = currentSize + "px";
}

function retractWindow( winNum) {

	windowExpanded[winNum] = false;

	limit = 10;
	winNum == 0 ? otherNum = 1 : otherNum = 0; 
	windowExpanded[otherNum] == true ? currentSize = 210 : currentSize = 430;

	// contract the window to 0px;
	r = self.setInterval("retract()", 1);
	
	alert('retracting');
}

function reduceWindow( winNum) {
	
	limit = 210;
	
	r = self.setInterval("reduce()", 1);

	alert('half retracting');
}

function reduce() {
	if( currentSize == 210)
		clearInterval(r);
	currentSize -= 20;
	toReduce.style.size = currentSize + "px";
	}

function retract() {
	if( currentSize == 10)
		clearInterval(r);
	currentSize -= 20;
	toExpand.style.height = currentSize + "px";
}

/*************** PICTURE FADER INTO PICTUREER ********************/


function fadeObjects(imageid, imageid2) {

setTimeout("fadeObject2('" + imageid + "','" + imageid2 + "')", 2000);

setInterval("fadeObject('" + imageid2 + "','" + imageid + "')", 10000);

}

function fadeObject2(imageid, imageid2) {

var opacityOut = 100;
var opacityIn = 0;
var timer = 25;
var n = 0;

while( opacityOut > 0) {
opacityOut = opacityOut - 5;
opacityIn = opacityIn + 5;
setTimeout("fade('" + imageid + "'," + opacityOut + ")", ( timer * ++n));
setTimeout("fade('" + imageid2 + "'," + opacityIn + ")", ( timer * n));
}

}

function fadeObject(imageid, imageid2) {

var opacityOut = 100;
var opacityIn = 0;
var timer = 25;
var n = 0;

while( opacityOut > 0) {
opacityOut = opacityOut - 5;
opacityIn = opacityIn + 5;
setTimeout("fade('" + imageid + "'," + opacityOut + ")", ( timer * ++n));
setTimeout("fade('" + imageid2 + "'," + opacityIn + ")", ( timer * n));
}

n += 200;


while( opacityOut <= 100) {
opacityOut = opacityOut + 5;
opacityIn = opacityIn - 5;
setTimeout("fade('" + imageid + "'," + opacityOut + ")", ( timer * ++n));
setTimeout("fade('" + imageid2 + "'," + opacityIn + ")", ( timer * n));
}

}

function fade(imageid, newOpacity) {

var image = document.getElementById(imageid);
image.style.opacity = newOpacity/100;
image.style.MozOpacity = newOpacity/100;
image.style.KhtmlOpacity = newOpacity/100;
image.style.filter = "alpha(opacity=" + newOpacity + ")";
}

/*********** EQUALIZE DIV HEIGHT ************/

function equalizeMainHeights() {

var divs = getElementsByClass('mainDiv');

var maxHeight = 0;

	for( element in divs) {
		if( divs[element].offsetHeight > maxHeight) maxHeight = divs[element].offsetHeight;
		
	}

	for( element in divs) {
		divs[element].style.height = maxHeight;
	}

}


/************* GET ELEMENTS BY CLASS ************/

function getElementsByClass( className) {

var classElements = new Array();

var elements = document.getElementsByTagName('*');
var length = elements.length;

var pattern = new RegExp('^'+className+'$','gi');

	for( var i = 0; i < length; i++) {
	
	if( elements[i].className.match(pattern)) classElements.push( elements[i]);
	}			

return classElements;
}