﻿document.documentElement.className = "js";

var leaves = [
             // ["LEAF NAME", Y/TOP (PX)], Is it a link?]
                ["leathams", 108, false],
                ["ingredients", 30, true],
                ["recipes", 125, true],
                ["food-service", 197, true],
                ["retail", 253, true],
                ["brands", 296, true],
                ["products", 313, true],
                ["about", 375, true]
            ];

var delayIncrement = 50; // Milliseconds
var randomAnimation = true;

Array.prototype.shuffle = function () {
    var i = this.length, j, temp;
    if (i == 0) return;
    while (--i) {
        j = Math.floor(Math.random() * (i + 1));
        temp = this[i];
        this[i] = this[j];
        this[j] = temp;
    }
}

if (randomAnimation)
    leaves.shuffle();

$(function () {

    $("#subscribe_button").delay(200).css("top", "-100px").animate({
        'top': '0'
    }, {
        duration: 1000, easing: 'easeOutBounce', complete: function () {
            // Unlock
        }
    });

    $("#links").css("top", "-100px").animate({
        'top': '0'
    }, {
        duration: 1000, easing: 'easeOutBounce'
    });

    $("html.js #header #features > div > a img").bind("load", function () { $(this).fadeIn(); });

    $.each(
        leaves,
	    function (intIndex, objValue) {
	        // Animation
	        $("#leaf_" + objValue[0]).css("top", "-200px").delay(delayIncrement * intIndex).animate({
	            'top': (objValue[1] + 'px')
	        }, {
	            duration: 1000, easing: 'easeInOutElastic'
	        });

	        if (objValue[2]) {
	            // Mouse Functions
	            $("#map_" + objValue[0] + " > area").mouseover(function () {
	                $("#leaf_" + objValue[0]).attr("src", "/Content/Img/Leaves/Lge/" + objValue[0] + "_hover.png");
	            }).mouseout(function () {
	                $("#leaf_" + objValue[0]).attr("src", "/Content/Img/Leaves/Lge/" + objValue[0] + ".png");
	            });

	            // Preload the hover image
	            jQuery.preLoadImages("/Content/Img/Leaves/Lge/" + objValue[0] + "_hover.png");
	        }

	    }
    );

    $('a[rel=external]').bind('click', function () { window.open(this.href); return false; });

});
