$(document).ready(function(){
	// lets find all oocurences
	
	// check if we are on the nomination form 
	// close all 
	if ($('#form').length) {
		
		
		// this code closes the panes
		// we have to check if radioboxes are checked
		
		$('.minusandplus').each(function(o){
			if(o != "0"){
				$(this).children("div").hide();
			}
		});
		
		// check if there is a checked radiobox
		
		$("input:radio").each(function(el){
			if($(this).attr("checked") === true){
				$(this).parent().parent().parent().parent().parent().css("display", "block");
			}
		});
		
		
		
		// toggle a fieldsetq
		$('.minusandplus').each(function(o){
			var p = this;
			
			// i kicked the animation out  causes issues in ie  TODO:small bug here
			$(this).children("legend").children("span").children("img").toggle(
				function(){
					$(p).children("div").css("display","block");
				}, function () {
					$(p).children("div").css("display","none");
				}
			);
		});
	};
	

});
	/*
	$(".sponsorrotatorlink").mouseover(function(){
		$(this).children('img').attr(
			"src"
			,$(this).children('.color').html() 
		);
    }).mouseout(function(){
		$(this).children('img').attr(
			"src"
			,$(this).children('.grey').html() 
		);
    });
	$('.sponsorrotatorlink').hover(
		function() {
			$(this).children('img').attr(
				"src"
				,$(this).children('.color').html() 
			);
		},
		function() {
			$(this).children('img').attr(
				"src"
				,$(this).children('.grey').html() 
			);
		}
	);
	*/

/*** ROTATION ELEMENT **/
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+"')", 7000); /*4000*/
}

function sponsorOnHover(anchor,src){
	$(anchor).children('img').attr("src",src);
}