jQuery(document).ready( function() {
	
	var flashArea = jQuery("#flashArea");
	var flashNavigation = jQuery("#flashNavigation");
	
	var flashContent = jQuery("#flashArea .flashContent");
	var flashnav = jQuery("#flashNavigation .flashNavigation");
	
	jQuery("#flashArea .flashContent").each( function() {
		
		jQuery(this).unwrap().unwrap();
		
	});	
	
	jQuery("#flashArea .flashContent:first").prev().remove();
	jQuery("#flashArea .flashContent:first").unwrap().unwrap();
	
	jQuery("#flashNavigation .flashNavigation").each( function() {
		
		jQuery(this).unwrap().unwrap();
		
	});	
	
	jQuery("#flashNavigation .flashNavigation:first").prev().remove();
	jQuery("#flashNavigation .flashNavigation:first").unwrap().unwrap();

	var flash = flashArea.children("div");
	var flashheight = parseInt(jQuery(flash[0]).height());
	var flashnavheight = parseInt(jQuery(flashnav[0]).height()) + 2;
	var flashtrick = jQuery("#flashTrick");
	jQuery(flashnav[1]).addClass("active");
	
	var flashactivenav = jQuery("#flashNavigation > .active");
	
	var flashnavindex;
	var flashinterval;
	
	flashnav.click(function() {
		
		flashanimater(jQuery(this));
		
	});
	
	function intervaller()
	{
	
		flashinterval = setInterval( function() {
									
			if ( flashactivenav.length > 0 )
			{
				flashanimater(flashactivenav);
			}
			else
			{
				flashanimater(jQuery(flashnav[0]));
			}
			
		},5000);
	
	}
	
	function flashanimater(flashobject) 
	{
		
		clearInterval(flashinterval);
		
		flashnav.removeClass("active");
		flashobject.addClass("active");
		
		flashnavindex = flashnav.index(flashobject);
		
		flash.parent().animate({
			marginTop: ( 0 - ( flashheight * flashnavindex ) )
		});
		
		flashtrick.animate({
			top: ( flashnavheight * flashnavindex )
		});
		flashactivenav = flashobject.next();
		
		intervaller();
	}
	
	intervaller();
	
});
