var roller_ups = new Array();

function rollover(selector, rollup) {
	$(selector).each(function() {
		$(this).mouseenter(function() {
			if (roller_ups[selector] == undefined) roller_ups[selector] = $('#'+$(this).attr('id') +' '+ selector + rollup).css('top');
			$('#'+$(this).attr('id') +' '+ selector + rollup).animate({'top' : 0});
		});
		$(this).mouseleave(function() {
			$('#'+$(this).attr('id') +' '+ selector + rollup).stop();
			//alert(roller_ups[selector] );
			$('#'+$(this).attr('id') +' '+ selector + rollup).animate({'top' : roller_ups[selector]});
		});
	});
}
function rolloverMenu(selector, rollup) {
	$(selector).each(function() {
		var top = -1;
		$(this).mouseenter(function() {
			if (top == -1) top = $(this).children('.'+rollup).css('top');
			$(this).children('.'+rollup).animate({ top: -120});
		});
		$(this).mouseleave(function() {
			$(this).children('.'+rollup).animate({ top: top});
		});
	});
	
}

function Rotate(rotatorSelector, autoRun, clickStop, timeOut, linked, start) {
	this.selector = rotatorSelector;
	this.run = autoRun;
	this.clickStop = clickStop;
	this.timeOut = timeOut;
	this.linked = linked;
	this.rotation = new Array();
	this.at = 0;
	
	var obj = this;
	$(rotatorSelector).each(function() {
		var id =  $(this).attr('id');
		if (obj.rotation.length > 0) {
			$(this).hide();
			if (linked != '') $('#'+id + linked).removeClass('menuactive');
		} else {
			if (linked != '')  $('#'+id + linked).addClass('menuactive');
		}
		obj.rotation.push(this);
		if (clickStop) {
			$(this).click(function() {
				run = !obj.run;
			});
		}
		if (linked != '' && clickStop) {
			$('#'+  id + linked).click(function() {
				obj.run = false;
				if (!$(this).hasClass('menuactive')) {
					$(obj.selector).fadeOut();
					$(obj.selector + obj.linked).removeClass('menuactive');
					$(this).addClass('menuactive');
					$('#'+  id).fadeIn();
				}
				return false;
			});
		}
	});
	if (this.rotation.length == 0) return;
	window.setTimeout(function(that) { return function() { that.RotateImages();};}(this), start);
	
	this.RotateImages = function RotateImages() {
		if (!this.run) {
			return;
		}
		var last = this.at;
		this.at++;
		this.at %= this.rotation.length;
		
		$(this.rotation[last]).css('z-index', '1');
		$(this.rotation[this.at]).css('z-index', '0');
		$(this.rotation[this.at]).show();
		$(this.rotation[last]).fadeOut(1000);
		if (this.linked != '') {
			$('#'+ $(this.rotation[last]).attr('id') + this.linked).removeClass('menuactive');
			$('#'+ $(this.rotation[this.at]).attr('id') + this.linked).addClass('menuactive');
		}
		setTimeout(function(that) { return function() { that.RotateImages();};}(this), this.timeOut);
	}
	this.Restart = function() {
		this.at = 0;
	}
	this.Start = function () {
		if (this.run) return;
		this.run = true;
		setTimeout(function(that) { return function() { that.RotateImages();};}(this), this.timeOut);
	}
	this.StartAfter = function (timer) {
		if (this.run) return;
		this.run = true;
		setTimeout(function(that) { return function() { that.RotateImages();};}(this), timer);
	}
	this.Stop = function () {
		this.run = false;
	}
}
