function addLoadEvent(func) {var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }
/* MAD Slider */
//default hidden content to hidden
addLoadEvent(defaultView);
function defaultView(){
	var sliders = getElementsByClassName("slider");
	for ( var i=0; i < sliders.length; i++){
		sliders[i].style.left = '249px';
	}
}
function closeEmAll(){//only 1 can be open at time.
	var sliders = getElementsByClassName("slider");
	for ( var i=0; i < sliders.length; i++){
		var sliderIDs = sliders[i].id;
		closeBox(sliderIDs);
	}
}

//get all slideboxes on page, attach onclick event to all switches, add parent id as parameter to slide, slide only if 'closed'
//or if 'open'. Removed onmouseover event and 'slideBack' function 03/06/08
/*addLoadEvent(slideBox);
function slideBox(){
	var switches = getElementsByClassName("switch");
	
	if (switches.length < 0) return false;
	for ( var i=0; i < switches.length; i++){
		switches[i].onclick = function(){
			//on open, close others
			if(this.parentNode.style.left == '249px'){
				closeEmAll();//close all boxes
				slide(this.parentNode.id);//open the required box
				
			}
			if(this.parentNode.style.left == '4px'){
				closeBox(this.parentNode.id);
			}
		return false;
		}
	}
}*/
addLoadEvent(slideBox);
function slideBox(){
	var switches = getElementsByClassName("switch");
	if (switches.length < 0) return false;
	for ( var i=0; i < switches.length; i++){
		switches[i].onmouseover = function(){
			if(this.parentNode.style.left == '249px'){
				closeEmAll();
				slide(this.parentNode.id);
			}
		return false;
		}
	}
}

addLoadEvent(slideBack);
function slideBack(){
	var switches = getElementsByClassName("switch");
	if (switches.length < 0) return false;
	for ( var i=0; i < switches.length; i++){
		switches[i].onclick = function(){
			if(this.parentNode.style.left == '4px'){
				closeBox(this.parentNode.id);
			}
		return false;
		}
	}
}
//if(object.activeX){}

//make magic
function slide(parentBox){
	var box1 = $(parentBox);
	var switcher = box1.getElementsByClassName("switch");

	if (box1.movement){
		clearTimeout(box1.movement);
	}
	var xpos = parseInt(box1.style.left);
	if (xpos == 4){
		for (var i=0; i<switcher.length; i++){
			switcher[i].style.backgroundPosition = '247px -219px';
		}
		
		return true;
	}
	if (xpos == 3){ xpos = 4; }
	if (xpos > 4){
		if(window.ActiveXObject){var dist = Math.floor((0 - xpos) / 12)}
		//IE open speed
		else{var dist = Math.floor((0 - xpos) / 5)}
		//other browser open speed
		xpos = xpos + dist;
	}
	box1.style.left = xpos + "px";
	var repeat = "slide('"+parentBox+"',10)";
	box1.movement = setTimeout(repeat, 10);

}
// reverses slide function. look at merging with slider
function closeBox(parentBox){
	var box1 = $(parentBox);
	var switcher = box1.getElementsByClassName("switch");
	
	if (box1.movement){
		clearTimeout(box1.movement);
	}
	var xpos = parseInt(box1.style.left);
	if (xpos == 249){
		for (var i=0; i<switcher.length; i++){
			switcher[i].style.backgroundPosition = '247px 0px';
		}
		return true;
	}
	
	if (xpos < 249){
		var dist = Math.ceil((249 - xpos) / 5);
		xpos = xpos + dist;
	}
	box1.style.left = xpos + "px";
	var repeat = "closeBox('"+parentBox+"',10)";
	box1.movement = setTimeout(repeat, 10);
		
}

