/* ------------------------------------

Hamilton's "Jill's Toaster" Slider

By Hamilton Pytluk
ham@85digital.com

Free to use, but please keep this
credit line :)

------------------------------------ */

$(document).ready(function(){
	
	// Numbers!
	var current = 5;
	
	// Get number of slides, width and adjust container
	var num = $("#under .panel").children().length;

	// So you can't keep on clickin' (later on)
	var running = false;
	
	// Set the first panel to "isup"
	$("#under-"+current).addClass("isup");
	
	$("#feature-dots ul li").click(function() {	
	
		if(!running) {
			
			// Turn off clicks
			running = true;
			
			// Get the ID of the next slide	
			var goto = $(this).attr("id").replace(/dot-/, '');
			
			// Check if "goto" is already up
			var current = $(".isup").attr("class");
			var next = $("#under-"+goto).attr("class");
			
			// Checking...
			if(current == next) {
				
				// do nothing, slide is already active
				running = false;
					
			} else {
				
				// Swap the "on" marker
				$("#feature-dots ul li.on").removeClass("on"); $("#dot-"+goto).addClass("on");
				
				// Set new "isup"
				var currentid = $(".isup").attr("id").replace(/under-/, '');
				$("#under-"+currentid).removeClass("isup"); $("#under-"+goto).addClass("isup");
						
				// Send the current slide down...			
				$("#under-"+currentid+", #over-"+currentid).animate(
				{ "top": "540px" },
				{ "duration": 400, "easing": "easeInExpo", "complete": function(){	
				
						// ...fade it out...										
						$("#under-"+currentid+", #over-"+currentid).fadeOut(0);
						
						// ...fade in the new slide...
						$("#under-"+goto+", #over-"+goto).css("top","540px").fadeIn(0);	
						
						// ...and bring it up	 				
						$("#under-"+goto+", #over-"+goto).animate(
						{ "top": "0px" },
						{ "duration": 600, "easing": "easeOutExpo", "complete": function(){
							
							// We can click, again
							running = false;
								
						}});
				
				}});
				
			}
		
		}		
				
	});
	
});
