var ltg_timer = "";
LTG.addLoadEvent(function(){
	/* code here runs when page loads */
	//(title, img, txt, alt, url) 
	// graphics files go in /_graphics/_features/giving_and_me.gif
	
	/*
	LTG.addFeature("Giving Game", 
				   "giving_game.gif", 
				   "Empower individuals to do amazing things through acts of kindness. Learn how to use the Giving Game in your class.", 
				   "Giving Game", 
				   "/teachers/giving_game.asp");
*/
	
	LTG.addFeature("Character Education Mini-Units", 
				   "puzzlepiece.gif", 
				   "Teach character education in the classroom with these mini-units.", 
				   "Character Education Mini-Units", 
				   "/lessons/aisd/");
	
/*	LTG.addFeature("Get Money Smart!", 
				   "penny.jpg", 
				   "Creative lessons and resources teaching financial literacy to youth K-12.",
				   "Get Money Smart!",
				   "/teachers/financialliteracy/"); */
	
	LTG.addFeature("Service Project Toolkits", 
				   "toolkits.gif", 
				   "Service project toolkits make planning easy!",
				   "Service Project Toolkits",
				   "/genonltg/servicetoolkits/");
	
/*	LTG.addFeature("Smart City: Land of Money Smart Kids", 
				   "smart_city.jpg", 
				   "Join Alex Ant on a journey through Smart City and learn about money management and more! Created for early elementary students.",
				   "Smart City: Land of Money Smart Kids",
				   "/students/smartcity/"); */
	
/*	LTG.addFeature("S.O.U.L.", 
				   "soul.jpg", 
				   "S.O.U.L. of Philanthropy: Heartwarming stories of giving and resources that guide learners to create their own stories.",
				   "S.O.U.L. of Philanthropy",
				   "/teachers/soul/"); */
	
/*	LTG.addFeature("Giving &amp; Me", 
				   "giving_and_me.gif", 
				   "Fun activities with Ant Phil! Early elementary students learn about giving and serving.",
				   "Giving &amp; Me",
				   "/students/giving_and_me/"); */
	
	LTG.addFeature("Save the Earth ", 
				   "save_the_earth.gif", 
				   "A unique resource for teaching youth about the critical subject of environmental stewardship.",
				   "Save the Earth ",
				   "/savetheearth/");
	
	LTG.addFeature("Folktales", 
				   "folktales.gif", 
				   "Generosity of Spirit Myths and folktales with Grades 9-12 lessons and more!",
				   "Folktales",
				   "/materials/folktales/");

	LTG.addFeature("Adults Serving in Schools", 
				   "pdf.png", 
				   "This toolkit was designed to help make the most of volunteers' experience in schools.",
				   "Adults Serving in Schools",
				   "/resources/Adults-in-Schools-Guide.pdf");
					 
/*	LTG.addFeature("Money Smart Choices", 
				   "money_smart_choices.jpg", 
				   "Do you ever think about how to manage your money? Or how to find a way to give some to a good cause?",
				   "Money Smart Choices",
				   "http://www.moneysmartchoices.org");
	
	LTG.addFeature("Civic Reflection", 
				   "civic_reflection.gif", 
				   "An introduction to Civic Reflection, the practice of reading texts to inspire dialogue about giving and serving. Read reflective prose and poetry.",
				   "Civic Reflection",
				   "/resources/community/"); */
	
	LTG.addFeature("Paw Prints to Learning", 
				   "paw.jpg", 
				   "Teach young people about animal welfare and how they CAN make a difference in animals' lives.",
				   "Paw Prints to Learning",
				   "/lessons/aspca/");
	
	LTG.addFeature("Literature Guides", 
				   "LitGuides.jpg", 
				   "Teach children to give, care and share through great literature!",
				   "Literature Guides",
				   "/teachers/literature_guides/");
	
	shuffle(LTG.features);  // INSERT AFTER HERE TO FORCE ITEM TO BE FIRST
	
		LTG.addFeature("Online Institute", 
				   "online_institute.jpg", 
				   "<b>PROFESSIONAL DEVELOPMENT</b>: <br> Max M. Fisher Online Institute is an interactive, self-paced tutorial in philanthropy education.",
				   "Online Institute",
				   "/lessons/institute/");
					 
/*	LTG.addFeature("National Phil. Day", 
				   "npd.jpg", 
				   "On November 15, recognize the countless ways philanthropy and service have affected our world. Inspire the next generation with lessons and activities related to <strong>National Philanthropy Day</strong>.",
				   "National Philanthropy Day",
				   "/lessons/NPD/"); */
					 
	LTG.addFeature("Learning to Give Joins generationOn  ", 
				   "genon.jpg", 
				   "Learning to Give has joined generationOn, a global youth service movement igniting the power of all kids to make their mark on the world. View the generationOn Moments of Service.", 
				   "Learning to Give Joins generationOn  ", 
				   "/genonltg/");
					 
	LTG.addFeature("Disaster Relief Resources", 
				   "disaster_relief.jpg", 
				   "Lesson, tools, and resources to help students respond from the heart to world disasters.", 
				   "Disaster Relief Resources", 
				   "/lessons/disaster_relief/");
	
	//LTG.randomnumber = Math.floor(Math.random()*LTG.features.length);
	LTG.randomnumber = LTG.features.length+1;

	LTG.StartTimer();
	$("#fc_play_pause").click(function() {
		if($(this).attr("title")=="Play") {
			//console.log("Play");
			$(this).attr("src","/_graphics/cork_pause.png").attr("title","Pause");
			LTG.StopTimer();
			LTG.StartTimer(true);
		} else {
			//console.log("Pause");
			$(this).attr("src","/_graphics/cork_play.png").attr("title","Play");
			LTG.StopTimer();
		}
	});
	$("#fc_prev").click(function() {
		//console.log("prev");
		LTG.StopTimer();
		var num = LTG.randomnumber-6;
		if(num<0) {
			LTG.randomnumber = LTG.features.length+(num);
		} else {
			LTG.randomnumber = LTG.randomnumber-6;
		}
		LTG.Rotate(false);
	});
	$("#fc_next").click(function() {
		LTG.StopTimer();
		LTG.Rotate(false);					   
	});
	
});

LTG.StartTimer = function() {
	$("#fc_play_pause").addClass("pause").removeClass("play").attr("title","Pause");
	LTG.Rotate(false);
	ltg_timer = window.setInterval("LTG.Rotate(true)",8000);
}
LTG.StopTimer = function(fade) {
	$("#fc_play_pause").addClass("play").removeClass("pause").attr("title","Play");
	window.clearInterval(ltg_timer);
	ltg_timer = "";
}


LTG.Rotate = function(fade) {
	if(fade) {
		$("#feature_cells div").fadeOut('slow',function(i){
			if(this.id=="first_div") {
				LTG.setCell("#feature_cells .left_col div",1);
				LTG.setCell("#feature_cells .mid_col div",2);			
				LTG.setCell("#feature_cells .right_col div",3);
				$("#feature_cells div").fadeIn();
			}
		});
	} else {
		$("#feature_cells div").hide();
		$("#feature_cells div").each(function(i){
			if(this.id=="first_div") {
				LTG.setCell("#feature_cells .left_col div",1);
				LTG.setCell("#feature_cells .mid_col div",2);			
				LTG.setCell("#feature_cells .right_col div",3);
				$("#feature_cells div").show();
			}
		});
	}
}

LTG.setCell = function(selector, more) {
	LTG.randomnumber++;
	if(LTG.randomnumber>=LTG.features.length) {
		LTG.randomnumber=0;
	}
	var feat = LTG.features[LTG.randomnumber];
	$(selector).html('<a href="'+feat.url+'" '+feat.targ+'><img src="_graphics/_features/'+feat.img+'" alt="'+feat.alt+'" class="ft_icon" /></a><h3>'+feat.title+'</h3><p>'+feat.txt+'</p><a href="'+feat.url+'" title="more" '+feat.targ+'><img src="_graphics/more'+more+'.png" alt="more" class="more" width="70" height="29" /></a>');
}

LTG.features =  new Array();
LTG.addFeature = function(title, img, txt, alt, url, target) {
	LTG.features.unshift( { title:title, img:img, txt:txt, alt:alt, url:url, targ:target } );	
}

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};
