// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$(document).ready(function() {
	ProgressiveEnhancement();
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function ProgressiveEnhancement()
{
	RemoveSparkle();
	AddSparkle();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function RemoveSparkle()
{
	// handled in the CSS to prevent flicker
	// $("#power-station").css("bottom", "-414px");
	// $("#sun").css("bottom", "-414px");
	// $("#windows").hide();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function AddSparkle()
{
	ShowPowerStation(); // chains the Sun and Windows on
	PanWaves();
	RoundCorners();
	StartCarousel();
	FetchTweets();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function ShowPowerStation()
{
	$("#power-station").delay(1000).animate({bottom: 0}, {
		easing: "easeOutBounce",
		duration: 2000,
		complete: ShowSun
	});
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function ShowSun()
{
	$("#sun").delay(500).animate({bottom: 0}, {
		easing: "easeOutElastic",
		duration: 2000,
		complete: ShowWindows
	});
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function ShowWindows()
{
	$("#windows").fadeIn(1000);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function PanWaves()
{
	$("#footer").pan({fps: 10, speed: 2, dir: "left"});
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function RoundCorners()
{
	$("h2").corner("0.5em");
	$("#attractions ul li").corner("0.5em tr tl");
	$("div.buttons button.next").corner("0.5em tr br");
	$("div.buttons button.prev").corner("0.5em tl bl");
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function StartCarousel()
{
	$("#attractions").jCarouselLite({
        btnNext: "#attractions div.buttons button.next",
        btnPrev: "#attractions div.buttons button.prev",
		auto: 7500,
		easing: "easeOutBounce",
		circular: true,
		visible: 1,
		speed: 1500,
		start: 0
    });
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function FetchTweets()
{
	getTwitters('tweets', {
		id: 'uppercockenzie',
		count: 3,
		enableLinks: true,
		ignoreReplies: true,
		clearContents: true,
		template: '<q>&bull; &ldquo;%text%&rdquo;<\/q> <cite><a href="http://twitter.com/%user_screen_name%/statuses/%id%/" target="_blank">%time%<\/a></cite>'
	});
}
