

function fadeIt(){
	
	//create custom font
	Cufon.replace('.description h2', {hover: true});
	Cufon.replace('.description p');
	Cufon.replace('.staticText h2');
	Cufon.replace('.staticText p');
	Cufon.now();
	
	var itemsList = dojo.query("#imageContainer div.holder");
	var volunteer = dojo.query(".chosenvolunteer .volunteerofthemonth");

	for (var i = 0; i < itemsList.length; i++) {
		dojo.addClass(itemsList[i], "holder" + (i + 1));
		if(dojo.hasClass(itemsList[i], "insight")) {
			dojo.style(itemsList[i], "zIndex", "1");
			dojo.fadeIn({node : itemsList[i], duration: 1000}).play();
		}
	}
	dojo.style(dojo.byId("preloader"), "display", "none");
	dojo.style(volunteer[0], "display", "block");
	setInterval(function(){
			var visibleItem = dojo.query("#imageContainer .insight");
			var selectedItem=0;
			var nextItem=0;
			var counter=0;
			for (var i = 0; i < itemsList.length; i++) {
				counter=i+1;
				if(dojo.hasClass(itemsList[i], "insight")) {
					if(itemsList.length!==counter) {
						nextItem=counter;
						selectedItem = i;
					}
					else {
						nextItem = 0;
					}
				}
			}
			
			dojo.removeClass(visibleItem[0], "insight");
			if(nextItem > selectedItem){
				dojo.style(itemsList[nextItem], "zIndex", "1");		
				if(dojo.isIE){
					dojo.animateProperty({
						node: itemsList[nextItem],
						duration: 500,
						properties: {
							opacity: {
								start: 0,
								end: 1
							}
						},
						rate: 800,
						onEnd: function() {
					
							dojo.style(visibleItem[0], "opacity", "0");	
							dojo.style(visibleItem[0], "zIndex", "0");	
							dojo.addClass(itemsList[nextItem], "insight");
						}
					}).play();
				}
				else {
					dojo.animateProperty({
						node: itemsList[nextItem],
						duration: 1000,
						properties: {
							opacity: {
								start: 0,
								end: 1
							}
						},
						onEnd: function() {
					
							dojo.style(visibleItem[0], "opacity", "0");	
							dojo.style(visibleItem[0], "zIndex", "0");	
							dojo.addClass(itemsList[nextItem], "insight");
						}
					}).play();					
				}
			}
			if(selectedItem >= nextItem){
				dojo.style(itemsList[nextItem], "zIndex", "1");		
				dojo.style(itemsList[nextItem], "opacity", "1");
				if(dojo.isIE){
					dojo.animateProperty({
						node: visibleItem[0],
						duration: 500,
						properties: {
							opacity: {
								start: 1,
								end: 0
							}
						},
						rate: 800,
						onEnd: function() {
							dojo.style(visibleItem[0], "zIndex", "0");	
							dojo.style(visibleItem[0], "opacity", "0");	
							dojo.addClass(itemsList[nextItem], "insight");
						}
					}).play();
				}
				else{
					dojo.animateProperty({
						node: visibleItem[0],
						duration: 1000,
						properties: {
							opacity: {
								start: 1,
								end: 0
							}
						},
						onEnd: function() {
							dojo.style(visibleItem[0], "zIndex", "0");	
							dojo.style(visibleItem[0], "opacity", "0");	
							dojo.addClass(itemsList[nextItem], "insight");
						}
					}).play();
				}
			}

		}
	,10000 );
}

dojo.addOnLoad(fadeIt);