jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (typeof callback == 'function')  
            callback();  
    }); 
}; 

var rotationElements= new Object();

function checkRotationId(id) {
	if (rotationElements[id]==undefined) {
		rotationElements[id]= new Object();
		rotationElements[id].elements= new Array();
		rotationElements[id].current= 0;
		rotationElements[id].firstCall= true;
	}
}
function getRotationElements(id) {
	return rotationElements[id].elements;
}
function addRotationElement(id,data) {
	checkRotationId(id);
	rotationElements[id].elements.push(data);
}
function setRotationElements(id,array) {
	rotationElements[id].elements = array;
}
function getRotationCurrent(id) {
	return rotationElements[id].current;
}
function setRotationCurrent(id,pos) {
	return rotationElements[id].current= pos;
}
function getRotationFirstCall(id) {
	return rotationElements[id].firstCall;
}
function setRotationFirstCall(id,setting) {
	return rotationElements[id].firstCall= setting;
}

function showCurrentRotationElement(id) {
	checkRotationId(id);
	var elements= getRotationElements(id);
	var container = document.getElementById(id);
	if (container) {
		container.innerHTML=elements[getRotationCurrent(id)];
	}
}
function nextRotationElement(id) {
	var elements= getRotationElements(id);
	var pos= getRotationCurrent(id)+1;
	if(pos >= elements.length) pos = 0;
	setRotationCurrent(id,pos)
	showCurrentRotationElement(id);
}
function prevRotationElement(id) {
	var elements= getRotationElements(id);
	var pos= getRotationCurrent(id)-1;
	if(pos < 0) pos = elements.length-1;
	setRotationCurrent(id,pos)
	showCurrentRotationElement(id);
}
function shuffle ( myArray ) {
	var i = myArray.length;
	if ( i == 0 ) return false;
	while ( --i ) {
	    var j = Math.floor( Math.random() * ( i + 1 ) );
	    var tempi = myArray[i];
	    var tempj = myArray[j];
	    myArray[i] = tempj;
	    myArray[j] = tempi;
   }
   return myArray;
}
function autoRotationElement(id) {
	if(getRotationFirstCall(id)) {
		setRotationFirstCall(id,false);
		setRotationElements(id,shuffle(getRotationElements(id)));
	}
	else 
		$('#'+id).css('opacity',0);
	nextRotationElement(id);	
	$('#'+id).fadeTo('slow',1);
	setTimeout("autoRotationElement('"+id+"')", 4000);
}
