// VARS
//
var current = 0;
var noofflowers = 0;

var currentnews = 1;
var noofnews = 0;

var initialwidths = [];

// INIT JQUERY
//
$(document).ready(function(){
	
	// FLOWERS
	$("div#top h1 span.flower").hide();
	noofflowers = $("div#top h1 span.flower").size();
	triggerFlower();
	
	// NEWS
	$("ul#latestnews li").hide();
	$("ul#latestnews li.title").show();
	noofnews = $("ul#latestnews li").size();
	triggerNews();
	
	// TREE BOXES
	$("ul#treeboxes li").each(function(){initialwidths.push($(this).width());});
	$("ul#treeboxes li").hide().css('width','0px');
	
	$("ul#treeboxes li a").click(
		function(e){
			e.preventDefault();
			var index = $(this).parent().index();
			$("ul#treedescriptions").show();
			$("ul#treedescriptions li").hide();
			$("ul#treedescriptions li:eq("+index+")").show();
		}
	);
	
	$("ul#treedescriptions").hide();
	$("ul#treedescriptions li").hide();
	
});

// PAGE LOAD
//
$(window).load(function(){
	var wait = 1000;
	$("ul#treeboxes li").each(
		function(index){
			$(this).delay(wait).animate({width:String(initialwidths[index]+'px')},1000);
			wait+=100;
		}
	);
});

// TRIGGER FLOWER FUNCTION
//
function triggerFlower(){
	$("div#top h1 span.flower").hide();
	$("div#top h1 span.flower:eq("+current+")").fadeIn(1000).delay(5000).fadeIn(0,triggerFlower);
	current++;
	if(current > (noofflowers-1)){
		current = 0;
	}
}

// TRIGGER NEWS FUNCTION
//
function triggerNews(){
	$("ul#latestnews li").hide();
	$("ul#latestnews li.title").show();
	$("ul#latestnews li:eq("+currentnews+")").fadeIn(1000).delay(7500).fadeIn(0,triggerNews);
	currentnews++;
	if(currentnews > (noofnews-1)){
		currentnews = 1;
	}
}
