// JavaScript Document

var Pepe = {};

Pepe.registerScrollDown = function(button, element) {
	
	var intId;
	var scrollFunction = function() {
		element.scrollTop += 10;
	}
	
	button.onmouseover = function(e) {
		intId = setInterval(scrollFunction, 50);
	}
	
	button.onmouseout = function(e) {
		clearInterval(intId);	
	}
	
}

Pepe.registerScrollUp = function(button, element) {
	
	var intId;
	var scrollFunction = function() {
		element.scrollTop -= 10;
	}
	
	button.onmouseover = function(e) {
		intId = setInterval(scrollFunction, 50);
	}
	
	button.onmouseout = function(e) {
		clearInterval(intId);	
	}
	
}

Pepe.fadeIn = function(element, callback) {
	
	if(typeof callback == 'undefined') {
		callback = null;
	}
	
	var intId;
	var opacity = .10;
	element.style.opacity = opacity;
	element.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
	
	
	var fadeFunction = function() {
		opacity = parseFloat(opacity) + .05;
		element.style.opacity = opacity;
		element.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
		if(opacity >= 1) {
			clearInterval(intId);
			if(callback !== null) {
				callback();
			}
		}
	}
	
	intId = setInterval(fadeFunction, 100);
}

Pepe.fadeOut = function(element, callback) {
	
	if(typeof callback == 'undefined') {
		callback = null;
	}
	
	var intId;
	var opacity = 1;
	if(typeof element.style.opacity == 'undefined') {
		element.style.opacity = opacity;
		element.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
	}
	
	var fadeFunction = function() {
		opacity = parseFloat(opacity) - .05;
		element.style.opacity = opacity;
		element.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
		if(opacity <= 0) {
			clearInterval(intId);
			if(callback !== null) {
				callback();
			}
		}
	}
	
	intId = setInterval(fadeFunction, 100);
}

Pepe.imgHomeFade = function(parent) {
	
	var fadeImages = GabeUtil.getElements(parent, "img", "imgHomeFade");
	var currIndex = 0;
	
	var startFadeIn = function() {
		fadeImages[currIndex].style.display = 'inline';
		Pepe.fadeIn(fadeImages[currIndex], startFadeOut);
	}
	
	var startFadeOut = function() {
		var timeoutInt;
		var proceedFadeOut = function() {
			Pepe.fadeOut(fadeImages[currIndex], gotoNext);
		}
		timeoutInt = setTimeout(proceedFadeOut, 1000);
	}
	
	var gotoNext = function() {
		fadeImages[currIndex].style.display = 'none';
		currIndex++;
		if(currIndex == fadeImages.length) {
			currIndex = 0;	
		}
		startFadeIn();
	}
	
	startFadeIn();
}
