﻿$(document).ready(function() {

		var selectedEffect = 'blind';
		sponsorer = Array('sponsorA','sponsorB','sponsorC','sponsorD','sponsorE','sponsorF');

		  $.shuffle = function(arr) {
			for(
			  var j, x, i = arr.length; i;
			  j = parseInt(Math.random() * i),
			  x = arr[--i], arr[i] = arr[j], arr[j] = x
			);
			return arr;
		  }
		
		var sponsorer = $.shuffle(sponsorer);
		var spons_max = sponsorer.length;
		
		function nextSpons() {
			next = sponsorer.shift();
			sponsorer.push(next);
			return next;
		} 
		//run the currently selected effect

		function slideOut(){
			//get effect type from 
			
			//most effect types need no options passed by default
			//check if it's scale, transfer, or size - they need options explicitly set
/*			if(selectedEffect == 'scale'){  options = {percent: 100}; }
			else if(selectedEffect == 'transfer'){ options = { to: "#button", className: 'ui-effects-transfer' }; }
			else if(selectedEffect == 'size'){ options = { to: {width: 280,height: 185} }; }
	*/		
			//run the effect
			$("#sponsor").hide('drop',{},500,slideRepeat("in"));
		};

		function slideIn() {
			var options = {direction: 'right'};	
			$("#sponsor").removeClass().addClass(nextSpons());			
			$("#sponsor").show('drop',options,500,slideRepeat("out"));

		}
		//callback function to bring a hidden box back
		function slideRepeat(f){
			if(f=='in') timer = 500;
			else if(f=='out') timer = 4000;

			setTimeout(function(){
				if(f=='in') slideIn();
				else if(f=='out') slideOut();
			}, timer);
		};
		
		$.get('', function(){
			$("#sponsor").addClass(nextSpons());
			slideRepeat('out');
		});

});
