// Defaults
$.fn.cycle.defaults.speed   = 900;
$.fn.cycle.defaults.timeout = 6000;

// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	
	mh = (mh >= 0) ? mh : 0;

	$(this).css('margin-top', mh);
	});
};

$.fn.vAlignP = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	
	mh = (mh >= 0) ? mh : 0;

	$(this).css('padding-top', mh);
	});
};

var cur_product_page = 0;
var num_product_pages = 0;

var cur_viewing_product = "none";

// Get Elements Height
function getElementHeight(el)
{
    return ($(el).css("height")) ? parseInt($(el).css("height").toString().substr(0,$(el).css("height").toString().length - 2)) : 0;
}

// Get Elements Width
function getElementWidth(el)
{
    return ($(el).css("width")) ? parseInt($(el).css("width").toString().substr(0,$(el).css("width").toString().length - 2)) : 0;
}

function killFocus(el, str) {
	if( el.value == '' ) {
		el.value = str;
	}
}
 
function grantFocus(el, str) {
	if( el.value == str ) {
		el.value = "";
	}
}
 
function killFocusH(el, str) {
	if( el.innerHTML == '' ) {
		el.innerHTML = str;
	}
}

function grantFocusH(el, str) {
	if( el.innerHTML == str ) {
		el.innerHTML = "";
	}
}

// Convert RGB to HEX
function rgbToHex(rgb) {
    var rgbvals = /rgb\((.+),(.+),(.+)\)/i.exec(rgb);
    var rval = parseInt(rgbvals[1]);
    var gval = parseInt(rgbvals[2]);
    var bval = parseInt(rgbvals[3]);
    
    var rvals = rval.toString(16);
    var gvals = gval.toString(16);
    var bvals = bval.toString(16);
    
    rvals = (rvals.length < 2) ? "0" + rvals : rvals;
    gvals = (gvals.length < 2) ? "0" + gvals : gvals;
    bvals = (rvals.length < 2) ? "0" + bvals : bvals;

    return '' + (
        rvals +
        gvals +
        bvals
    ).toLowerCase();
}

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';
    
    $("#content-wrapper").show();
    $("#footer-wrapper").show();

	$("a.lightbox").lightBox();

    var page_hash = jQuery.url.attr("anchor");

    //alert(page_hash);
    
    var hash_split = (page_hash) ? page_hash.split("/") : [];

    var len = hash_split.length;

    if (hash_split.length >= 2)
    {
        if (hash_split[len - 3] == "page")
        {
            cur_product_page = parseInt(hash_split[len - 2]) - 1;
        }
        else if (hash_split[len - 3] == "product")
        {
            cur_viewing_product = hash_split[len - 2];
        }
    }

    // Get Number of Product Pages
    num_product_pages = $(".thumb-panels").children().size();
    
    cur_product_page = (cur_product_page < num_product_pages && cur_product_page >= 0) ? cur_product_page : 0;

    //$('#expandable-side-menu').scale9Grid({top:10,bottom:30,left:0,right:0});
    
    if (jQuery.support.opacity)
    {
        $("#expandable-side-menu .bg").hide();
        $("#expandable-side-menu ul").fadeTo(0,0);
        $("#expandable-side-menu .contracted").show();
    }
    else
    {
        $("#expandable-side-menu .bg").hide();
        $("#expandable-side-menu ul").hide();
        $("#expandable-side-menu .contracted").show();
    }

    // Top Nav Animation
    $("#expandable-side-menu").hover(function(){
        if (jQuery.support.opacity)
        {
            $("#expandable-side-menu").animate({height: 513}, { queue:false, duration:"fast" });
            $("#expandable-side-menu .contracted").animate({opacity: 0}, { queue:false, duration:"fast" });
            $("#expandable-side-menu .expanded").fadeTo(0,0).animate({opacity: 1}, { queue:false, duration:"fast" });
            $("#expandable-side-menu ul").animate({opacity: 1}, { queue:false, duration:"fast" });
        }
        else
        {
            $("#expandable-side-menu").css("height","513px");
            $("#expandable-side-menu .bg").hide();
            $("#expandable-side-menu ul").show();
            $("#expandable-side-menu .expanded").show();
        }
    },function(){
        if (jQuery.support.opacity)
        {
            $("#expandable-side-menu").animate({height: 74}, { queue:false, duration:"fast" });
            $("#expandable-side-menu .expanded").animate({opacity: 0}, { queue:false, duration:"fast" });
            $("#expandable-side-menu .contracted").fadeTo(0,0).animate({opacity: 1}, { queue:false, duration:"fast" });
            $("#expandable-side-menu ul").animate({opacity: 0}, { queue:false, duration:"fast" });
        }
        else
        {
            $("#expandable-side-menu").css("height","74px");
            $("#expandable-side-menu .bg").hide();
            $("#expandable-side-menu ul").hide();
            $("#expandable-side-menu .contracted").show();
        }
    });

    // Watermellon Animation
    $('#watermellon-holder').fadeTo(0,0).animate({left: 0},1000).fadeTo(1000,1);
    $('#watermellon').animate({backgroundPosition: '0px 0px'},0).animate({left: 0},1000).animate({backgroundPosition: '50% 0px'},1000);

    // Logo Animation
    $('#logo.animated').animate({top: -(getElementHeight('#logo'))},0).animate({left: 20},500).animate({top: 0},1000);

    // Image Panel Animation
    $('#image-panel').animate({top: -(getElementHeight('#image-panel'))},0).animate({right: 0},1000).animate({top: 0},1000);

 // Image Panel2 Animation
    $('#image-panel2').animate({top: -(getElementHeight('#image-panel2'))},0).animate({right: 0},1000).animate({top: 0},1000);
    
    // Product Header Animation
    $('#product-header').animate({top: -(getElementHeight('#product-header'))},0).animate({right: 0},1000).animate({top: 0},1000);
    
    // Side Menu Animation
    //$('#side-menu').animate({left: -(getElementWidth('#side-menu'))},0).animate({top: 0},1500).animate({left: 0},1000);
    //$('.side-menu-holder').fadeTo(0,0).animate({left: 0},1500).fadeTo(1000,1);
    
    // Top Nav Animation
    $(".menu-panel li").hover(function(){
        $(".bars ."+$(this).attr("class")+"-bar").animate({height: 60}, { queue:false, duration:"fast" });
        var color = $(".bars ."+$(this).attr("class")+"-bar").css('backgroundColor');
        color = rgbToHex(color);
        $(this).find("img").attr("src",base_url+"dynamic_text.php?fontname=latino-samba&color="+color+"&size=10&title="+$(this).find("img").attr('alt'));
    },function(){
        $(".bars ."+$(this).attr("class")+"-bar").animate({height: 50}, { queue:false, duration:"fast" });
        $(this).find("img").attr("src",base_url+"dynamic_text.php?fontname=latino-samba&color=ffffff&size=10&title="+$(this).find("img").attr('alt'));
    });

    $(".products-panel .thumb-panels .panel .next-page").hide();
    $(".products-panel .thumb-panels .panel .prev-page").hide();

    if (num_product_pages > 1)
    {
        if (cur_product_page < (num_product_pages - 1)) {
        	$(".products-panel .thumb-panels .panel .next-page").show();
        }
        if (cur_product_page > 0)
        {
        	$(".products-panel .thumb-panels .panel .prev-page").show();
        }
    }
    
    $(".products-panel .back-to-list").hide();
    
    if (cur_viewing_product != "none")
    {
        $(".products-panel .back-to-list").show();
        $(".products-panel .info-panels").css("zIndex",30);
    }

	$(".products-panel .thumb-panels .panel .product-item .title span").vAlign();
	$(".recipes-panel .thumb-panels .panel .recipe-item .title span").vAlign();
	$(".watermelon-panel .panels .panel .watermelon-item .title span").vAlign();
	$(".media-panel .media-pages .page .media-item .title span").vAlign();

    // Product Animation
	$(".products-panel .thumb-panels .panel .product-item").hover(function(){
		$(this).find(".title").css("backgroundColor", "#009de9");
    },function(){
        $(this).find(".title").css("backgroundColor", "#000000");
    });

    $(".products-panel .thumb-panels .panel").animate({left: getElementWidth('.products-panel .thumb-panels .panel')}, { queue:false, duration:0 });
	if (cur_viewing_product == "none") $(".products-panel .thumb-panels .panel").eq(cur_product_page).animate({left: 0}, { queue:false, duration:0 });
	$(".products-panel .thumb-panels").css("zIndex",20);
	$(".products-panel .info-panels .panel").animate({left: getElementWidth('.products-panel .info-panels .panel')}, { queue:false, duration:0 });
	
	$(".products-panel .info-panels").find("#"+cur_viewing_product+"-info").animate({left: 0}, { queue:false, duration:0 });

	$(".products-panel .thumb-panels .panel .product-item").click(function(){
        $(".products-panel .back-to-list").show();
        $(".products-panel .info-panels").css("zIndex",30);
        cur_viewing_product = $(this).attr("id");
        //window.location.hash = "#/product/" + cur_viewing_product +"/";
        $(".products-panel .info-panels").find("#"+cur_viewing_product+"-info").animate({left: 0}, { queue:false, duration:500 });
        $(".products-panel .thumb-panels .panel").eq(cur_product_page).animate({left: -(getElementWidth('.products-panel .thumb-panels .panel'))}, { queue:false, duration:500 });
    });
    
    $(".products-panel .info-panels .panel .recipe-info").hide();
    
    $(".products-panel .info-panels .panel .show-recipe").click(function(){
    	$(".products-panel .info-panels").find("#"+cur_viewing_product+"-info" + " .show-recipe").hide();
		$(".products-panel .info-panels").find("#"+cur_viewing_product+"-info" + " .recipe-info").fadeIn(500);
    });

    $(".products-panel .thumb-panels .panel .next-page").click(function(){
		var old_product_page = cur_product_page;
        //cur_product_page = (cur_product_page + 1 < num_product_pages) ? cur_product_page + 1 : 0;
        
        cur_product_page += 1;
        
        if (cur_product_page == (num_product_pages - 1)) {
        	$(".products-panel .thumb-panels .panel .next-page").hide();
        	$(".products-panel .thumb-panels .panel .prev-page").show();
        }
        else
        {
        	$(".products-panel .thumb-panels .panel .next-page").show();
        	$(".products-panel .thumb-panels .panel .prev-page").show();
        }
        
        //window.location.hash = "#/page/" + (cur_product_page + 1)+"/";
        $(".products-panel .thumb-panels .panel").eq(old_product_page).animate({left: -(getElementWidth('.products-panel .thumb-panels .panel'))}, { queue:false, duration:500 });
        $(".products-panel .thumb-panels .panel").eq(cur_product_page).animate({left: getElementWidth('.products-panel .thumb-panels .panel')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
    
    $(".products-panel .thumb-panels .panel .prev-page").click(function(){
		var old_product_page = cur_product_page;
        //cur_product_page = (cur_product_page - 1 >= 0) ? cur_product_page - 1 : num_product_pages - 1;
        
        cur_product_page -= 1;
        
        if (cur_product_page == 0) {
        	$(".products-panel .thumb-panels .panel .next-page").show();
        	$(".products-panel .thumb-panels .panel .prev-page").hide();
        }
        else
        {
        	$(".products-panel .thumb-panels .panel .next-page").show();
        	$(".products-panel .thumb-panels .panel .prev-page").show();
        }
        
        //window.location.hash = "#/page/" + (cur_product_page + 1)+"/";
        $(".products-panel .thumb-panels .panel").eq(old_product_page).animate({left: getElementWidth('.products-panel .thumb-panels .panel')}, { queue:false, duration:500 });
        $(".products-panel .thumb-panels .panel").eq(cur_product_page).animate({left: -(getElementWidth('.products-panel .thumb-panels .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });

    $(".products-panel .back-to-list").click(function(){
        $(".products-panel .back-to-list").hide();
        $(".products-panel .info-panels .panel .show-recipe").show();
        $(".products-panel .info-panels .panel .recipe-info").hide();
        $(".products-panel .info-panels").css("zIndex",10);
        //window.location.hash = "#/page/" + (cur_product_page + 1)+"/";
        $(".products-panel .info-panels").find("#"+cur_viewing_product+"-info").animate({left: getElementWidth('.products-panel .thumb-panels .panel')}, { queue:false, duration:500 });
        $(".products-panel .thumb-panels .panel").eq(cur_product_page).animate({left: -(getElementWidth('.products-panel .thumb-panels .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
        cur_viewing_product = "none";
    });


    // Top Nav Animation
    $("#side-menu ul li .blackbox").fadeTo(0,0);
    $("#side-menu ul li").hover(function(){
        $(this).find(".blackbox").animate({opacity: 1}, { queue:false, duration:300 });
    },function(){
        $(this).find(".blackbox").animate({opacity: 0}, { queue:false, duration:300 });
    });
    
    // Top Nav Animation
    $("#expandable-side-menu ul li .blackbox").fadeTo(0,0);
    $("#expandable-side-menu ul li").hover(function(){
        $(this).find(".blackbox").animate({opacity: 1}, { queue:false, duration:300 });
    },function(){
        $(this).find(".blackbox").animate({opacity: 0}, { queue:false, duration:300 });
    });

    // Slideshow Animation
    if ($('.slideshow').css("height"))
    {
    $('.slideshow').cycle({
        fx:      'custom',
        cssBefore: {
            left: 230,
            top:  137,
            width: 0,  
            height: 0,  
            opacity: 0,
            zIndex: 1
        }, 
            animOut: {
            opacity: 0,
            left: 460
        }, 
        animIn: {
            left: 0,
            top: 0,  
            width: 430,
            height: 274,
            opacity: 1
        },
        cssAfter: {  
            zIndex: 0
        },
        delay: -2000,
        speed: 2000,
        sync: false
    });
    }
    
    if ($('.image-fader').css("height"))
    {
    $('.image-fader').cycle({
        fx:      'fade',
        delay: -2000,
        speed: 3000
    });
    }
    
    if ($('#image-panel .left').css("height") || $('#image-panel2 .left').css("height"))
    {
    $('#image-panel .left').cycle({
        fx:      'fade',
        delay: -2000,
        speed: 3000
    });
    }

    if ($('#image-panel .right').css("height"))
    {
    $('#image-panel .right').cycle({
        fx:      'fade',
        delay: -1500,
        speed: 3000
    });
    }
});


/* ================== Recipe page JS =================== */
var cur_recipe_page = 0;
var num_recipe_pages = 0;

var cur_viewing_recipe = "none";
var cur_viewing_category = "none";

$(document).ready(function(){
	jQuery.easing.def = 'easeInOutExpo';
	
	var page_hash = jQuery.url.attr("anchor");
    
    //alert(page_hash);
    
    var hash_split = (page_hash) ? page_hash.split("/") : [];

    var len = hash_split.length;

    if (hash_split.length >= 2)
    {
        if (hash_split[len - 3] == "page")
        {
            cur_product_page = parseInt(hash_split[len - 2]) - 1;
        }
        else if (hash_split[len - 3] == "recipe")
        {
            cur_viewing_product = hash_split[len - 2];
        }
    }

	// Recipe Header Animation
    $('#recipe-header').animate({top: -(getElementHeight('#recipe-header'))},0).animate({right: 0},1000).animate({top: 0},1000);
	

    if (cur_viewing_category == "none")
    {
        cur_viewing_category = ($(".recipes-categories ul li a").eq(0).attr("id")) ? "#" + $(".recipes-categories ul li a").eq(0).attr("id") + "-category" : "none";
    }

	// Get Number of Recipe Pages
    num_recipe_pages = $(cur_viewing_category + " .thumb-panels").children().size();

    $(".recipes-panel .thumb-panels .panel .next-page").hide();
    $(".recipes-panel .thumb-panels .panel .prev-page").hide();

    if (num_recipe_pages > 1)
    {
        if (cur_recipe_page < (num_recipe_pages - 1)) {
        	$(cur_viewing_category + " .thumb-panels .panel .next-page").show();
        }
        if (cur_recipe_page > 0)
        {
        	$(cur_viewing_category + " .thumb-panels .panel .prev-page").show();
        }
    }
    
    $(".back-to-recipes").hide();

    if (cur_viewing_recipe != "none")
    {
        $(".back-to-recipes").show();
    }


	// Recipe Animation
	$(".recipes-panel .thumb-panels .panel .recipe-item").hover(function(){
	    $(this).animate({backgroundColor: "#009de9"}, { queue:false, duration:300 });
	},function(){
	    $(this).animate({backgroundColor: "#000"}, { queue:false, duration:300 });
	});

	
	$(".recipes-panel .thumb-panels .panel").animate({left: getElementWidth('.recipes-panel .thumb-panels .panel')}, { queue:false, duration:0 });
	$(".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).animate({left: 0}, { queue:false, duration:0 });
	$(".recipes-panel .thumb-panels").css("zIndex",20);
	$(".recipes-panel .info-panels .panel").animate({left: getElementWidth('.recipes-panel .info-panels .panel')}, { queue:false, duration:0 });
	$(".recipes-panel .thumb-panels .panel").hide();
	$(".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).show();

	$(".recipes-panel .thumb-panels .panel .recipe-item").click(function(){
		
	    $(".back-to-recipes").show();
	    $(cur_viewing_category + ".recipes-panel .info-panels").css("zIndex",30);
	    cur_viewing_recipe = "#"+$(this).attr("id")+"-info";
		$(cur_viewing_category + ".recipes-panel .info-panels").find(cur_viewing_recipe).show();
	    $(cur_viewing_category + ".recipes-panel .info-panels").find(cur_viewing_recipe).animate({left: 0}, { queue:false, duration:500 });
		
		
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).animate({left: -(getElementWidth('.recipes-panel .thumb-panels .panel'))}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	});

	$(".recipes-panel .thumb-panels .panel .next-page").click(function(){
		var old_recipe_page = cur_recipe_page;
	    //cur_recipe_page = (cur_recipe_page + 1 < num_recipe_pages) ? cur_recipe_page + 1 : 0;
	    
	    cur_recipe_page += 1;
        
        if (cur_recipe_page == (num_recipe_pages - 1)) {
        	$(cur_viewing_category + " .thumb-panels .panel .next-page").hide();
        	$(cur_viewing_category + " .thumb-panels .panel .prev-page").show();
        }
        else
        {
        	$(cur_viewing_category + " .thumb-panels .panel .next-page").show();
        	$(cur_viewing_category + " .thumb-panels .panel .prev-page").show();
        }
        
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(old_recipe_page).animate({left: -(getElementWidth('.recipes-panel .thumb-panels .panel'))}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).show();
		$(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).animate({left: getElementWidth('.recipes-panel .thumb-panels .panel')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	$(".recipes-panel .thumb-panels .panel .prev-page").click(function(){
		var old_recipe_page = cur_recipe_page;
	    //cur_recipe_page = (cur_recipe_page - 1 >= 0) ? cur_recipe_page - 1 : num_recipe_pages - 1;
	    cur_recipe_page -= 1;
        
        if (cur_recipe_page == 0) {
        	$(cur_viewing_category + " .thumb-panels .panel .next-page").show();
        	$(cur_viewing_category + " .thumb-panels .panel .prev-page").hide();
        }
        else
        {
        	$(cur_viewing_category + " .thumb-panels .panel .next-page").show();
        	$(cur_viewing_category + " .thumb-panels .panel .prev-page").show();
        }
        
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(old_recipe_page).animate({left: getElementWidth('.recipes-panel .thumb-panels .panel')}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).show();
		$(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).animate({left: -(getElementWidth('.recipes-panel .thumb-panels .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	$(".back-to-recipes").click(function(){
	    $(".back-to-recipes").hide();
	    $(cur_viewing_category + ".recipes-panel .info-panels").css("zIndex",10);
	    $(cur_viewing_category + ".recipes-panel .info-panels").find(cur_viewing_recipe).animate({left: getElementWidth(cur_viewing_category + '.recipes-panel .thumb-panels .panel')}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).show();
		$(cur_viewing_category + ".recipes-panel .thumb-panels .panel").eq(cur_recipe_page).animate({left: 0}, { queue:false, duration:500 });
	    cur_viewing_recipe = "none";
	});
	
	$(".category-panels .recipes-panel").animate({top: getElementHeight('.category-panels .recipes-panel')}, { queue:false, duration:0 });
	$(".category-panels .recipes-panel").hide();
	$(".category-panels").find(cur_viewing_category).animate({top: 0}, { queue:false, duration:0 });
	$(".category-panels").find(cur_viewing_category).show();

	$(".recipes-categories a").click(function(){
		var new_viewing_category = "#"+$(this).attr("id")+"-category";
		
		if (new_viewing_category != cur_viewing_category) {
		    reset_pages(new_viewing_category);
			
			// Get our position in the list
			var $p = $(this).parent().parent().children();
			var n = $p.index($(this).parent());
			//console.log(n);
			
			// Get cur's position in the list
			var c = $p.index($(".recipes-categories .selected"));
			//console.log(c);
			
			if (c > n) {	//we're moved up the list, so scroll recipe-panels down
				$(".category-panels").find(new_viewing_category).show();
				$(".category-panels").find(new_viewing_category).animate({top: -(getElementHeight('.category-panels .recipes-panel'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
				$(".category-panels").find(cur_viewing_category).animate({top: (getElementHeight('.category-panels .recipes-panel'))}, { queue:false, duration:500, complete: function() { $(this).hide();} });				
			} else {		//we moved down the list, scroll recipe-panels up
				$(".category-panels").find(cur_viewing_category).animate({top: -(getElementHeight('.category-panels .recipes-panel'))}, { queue:false, duration:500, complete: function() { $(this).hide();} });
				$(".category-panels").find(new_viewing_category).show();
				$(".category-panels").find(new_viewing_category).animate({top: (getElementHeight('.category-panels .recipes-panel'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
			}
			
			// Set hilight
			$(".recipes-categories li").attr("class", "");
			$(this).parent().attr("class", "selected");
			
			cur_viewing_category = new_viewing_category;
		}
	});
	
});

function reset_pages(cur_cat) {
	//console.log(cur_cat);
	// Get Number of Recipe Pages
    num_recipe_pages = $(cur_cat + " .thumb-panels").children().size();

	cur_recipe_page = 0;
	
    $(cur_cat + " .thumb-panels .panel .next-page").hide();
    $(cur_cat + " .thumb-panels .panel .prev-page").hide();
    
    if (num_recipe_pages > 1)
    {
        if (cur_recipe_page < (num_recipe_pages - 1))
        {
        	$(cur_cat + " .thumb-panels .panel .next-page").show();
        }
        if (cur_recipe_page > 0)
        {
        	$(cur_cat + " .thumb-panels .panel .prev-page").show();
        }
    }
    
	cur_viewing_recipe = "none";
	$(".recipes-panel .info-panels").css("zIndex",10);
	
    $(".back-to-recipes").hide();
    
	$(cur_cat + " .thumb-panels .panel").animate({left: getElementWidth(cur_cat + ' .thumb-panels .panel')}, { queue:false, duration:0 });
	$(cur_cat + " .thumb-panels .panel").eq(cur_recipe_page).animate({left: 0}, { queue:false, duration:0 });
	$(cur_cat + " .thumb-panels").css("zIndex",20);
	$(cur_cat + " .info-panels .panel").animate({left: getElementWidth(cur_cat + ' .info-panels .panel')}, { queue:false, duration:0 });
	$(cur_cat + " .info-panels .panel").hide();
	$(cur_cat + " .thumb-panels .panel").eq(cur_recipe_page).show();
	
}


/* ================== Blog page JS =================== */

var cur_blog_page = 0;
var num_blog_pages = 0;

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';
    
    var page_hash = jQuery.url.attr("anchor");
    
    //alert(page_hash);
    
    var hash_split = (page_hash) ? page_hash.split("/") : [];

    var len = hash_split.length;

    if (hash_split.length >= 2)
    {
        if (hash_split[len - 3] == "page")
        {
            cur_product_page = parseInt(hash_split[len - 2]) - 1;
        }
    }

    // Get Number of Product Pages
    num_blog_pages = $(".blog-pages").children().size();
    
    cur_blog_page = (cur_blog_page < num_blog_pages && cur_blog_page >= 0) ? cur_blog_page : 0;

    $(".blog-panel .blog-pages .page .next-page").hide();
    $(".blog-panel .blog-pages .page .prev-page").hide();
    
    if (num_blog_pages > 1)
    {
        if (cur_blog_page < (num_blog_pages - 1)) {
        	$(".blog-panel .blog-pages .page .next-page").show();
        }
        if (cur_blog_page > 0)
        {
        	$(".blog-panel .blog-pages .page .prev-page").show();
        }
    }

    $(".blog-panel .blog-pages .page").animate({left: getElementWidth('.blog-panel .blog-pages') + 20}, { queue:false, duration:0 });
	$(".blog-panel .blog-pages .page").eq(cur_blog_page).animate({left: 0}, { queue:false, duration:0 });

    $(".blog-panel .blog-pages .page .next-page").click(function(){
		var old_blog_page = cur_blog_page;
        //cur_blog_page = (cur_blog_page + 1 < num_blog_pages) ? cur_blog_page + 1 : 0;
        cur_blog_page += 1;
        
        if (cur_blog_page == (num_blog_pages - 1)) {
        	$(".blog-panel .blog-pages .page .next-page").hide();
        	$(".blog-panel .blog-pages .page .prev-page").show();
        }
        else
        {
        	$(".blog-panel .blog-pages .page .next-page").show();
        	$(".blog-panel .blog-pages .page .prev-page").show();
        }
        
        window.location.hash = "#/page/" + (cur_blog_page + 1)+"/";
        $(".blog-panel .blog-pages .page").eq(old_blog_page).animate({left: -(getElementWidth('.blog-panel .blog-pages'))}, { queue:false, duration:500 });
        $(".blog-panel .blog-pages .page").eq(cur_blog_page).animate({left: getElementWidth('.blog-panel .blog-pages')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
    
    $(".blog-panel .blog-pages .page .prev-page").click(function(){
		var old_blog_page = cur_blog_page;
        cur_blog_page = (cur_blog_page - 1 >= 0) ? cur_blog_page - 1 : num_blog_pages - 1;
        
        cur_blog_page -= 1;
        
        if (cur_blog_page == 0) {
        	$(".blog-panel .blog-pages .page .next-page").show();
        	$(".blog-panel .blog-pages .page .prev-page").hide();
        }
        else
        {
        	$(".blog-panel .blog-pages .page .next-page").show();
        	$(".blog-panel .blog-pages .page .prev-page").show();
        }
        
        window.location.hash = "#/page/" + (cur_blog_page + 1)+"/";
        $(".blog-panel .blog-pages .page").eq(old_blog_page).animate({left: getElementWidth('.blog-panel .blog-pages')}, { queue:false, duration:500 });
        $(".blog-panel .blog-pages .page").eq(cur_blog_page).animate({left: -(getElementWidth('.blog-panel .blog-pages'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
});

/* ================== Media page JS =================== */
var cur_media_page = 0;
var num_media_pages = 0;

var cur_viewing_media = "none";
var cur_viewing_media_category = "none";

$(document).ready(function(){
	jQuery.easing.def = 'easeInOutExpo';
	
	var page_hash = jQuery.url.attr("anchor");
    
    //alert(page_hash);
    
    var hash_split = (page_hash) ? page_hash.split("/") : [];

    var len = hash_split.length;

    if (hash_split.length >= 2)
    {
        if (hash_split[len - 3] == "page")
        {
            cur_product_page = parseInt(hash_split[len - 2]) - 1;
        }
    }
    
    // #/category-name/page-number
    // #/category-name/current-media
    
    if (cur_viewing_media_category == "none")
    {
        cur_viewing_media_category = ($(".media-panel .media-menu ul li a").eq(0).attr("id")) ? $(".media-panel .media-menu ul li a").eq(0).attr("id") : "none";
    }

	// Get Number of Recipe Pages
    num_media_pages = $("#"+cur_viewing_media_category+"-category" + " .media-pages").children().size();

    $(".media-panel .media-categories .media-category .media-pages .page .next-page").hide();
    $(".media-panel .media-categories .media-category .media-pages .page .prev-page").hide();

    if (num_media_pages > 1)
    {
        if (cur_media_page < (num_media_pages - 1)) {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .next-page").show();
        }
        if (cur_media_page > 0)
        {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .prev-page").show();
        }
    }


	// Recipe Animation
	$(".media-panel .media-categories .media-category .media-pages .page .media-item").hover(function(){
	    $(this).animate({backgroundColor: "#009de9"}, { queue:false, duration:300 });
	},function(){
	    $(this).animate({backgroundColor: "#000"}, { queue:false, duration:300 });
	});


	$(".media-panel .media-categories .media-category .media-pages .page").animate({left: getElementWidth('.media-panel .media-categories .media-category .media-pages .page')}, { queue:false, duration:0 });
	$(".media-panel .media-categories .media-category .media-pages .page").eq(cur_media_page).animate({left: 0}, { queue:false, duration:0 });
	$(".media-panel .media-categories .media-category .media-pages").css("zIndex",20);
	$(".media-panel .media-categories .media-category .media-infos .info").animate({left: getElementWidth('.media-panel .media-categories .media-category .media-infos .info')}, { queue:false, duration:0 });


	$(".media-panel .media-categories .media-category .media-pages .page .next-page").click(function(){
		var old_media_page = cur_media_page;
	    //cur_media_page = (cur_media_page + 1 < num_media_pages) ? cur_media_page + 1 : 0;
	    
	    cur_media_page += 1;
        
        if (cur_media_page == (num_media_pages - 1)) {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .next-page").hide();
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .prev-page").show();
        }
        else
        {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .next-page").show();
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .prev-page").show();
        }
	    
	    $("#"+cur_viewing_media_category+"-category" + " .media-pages .page").eq(old_media_page).animate({left: -(getElementWidth('.media-panel .media-categories .media-category .media-pages .page'))}, { queue:false, duration:500 });
	    $("#"+cur_viewing_media_category+"-category" + " .media-pages .page").eq(cur_media_page).animate({left: getElementWidth('.media-panel .media-categories .media-category .media-pages .page')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	$(".media-panel .media-categories .media-category .media-pages .page .prev-page").click(function(){
		var old_media_page = cur_media_page;
	    //cur_media_page = (cur_media_page - 1 >= 0) ? cur_media_page - 1 : num_media_pages - 1;
	    
	    cur_media_page -= 1;
        
        if (cur_media_page == 0) {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .next-page").show();
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .prev-page").hide();
        }
        else
        {
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .next-page").show();
        	$("#"+cur_viewing_media_category+"-category" + " .media-pages .page .prev-page").show();
        }
        
	    $("#"+cur_viewing_media_category+"-category" + " .media-pages .page").eq(old_media_page).animate({left: getElementWidth('.media-panel .media-categories .media-category .media-pages .page')}, { queue:false, duration:500 });
	    $("#"+cur_viewing_media_category+"-category" + " .media-pages .page").eq(cur_media_page).animate({left: -(getElementWidth('.media-panel .media-categories .media-category .media-pages .page'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	
	$(".media-panel .media-categories .media-category").animate({top: getElementHeight('.media-panel .media-categories .media-category')}, { queue:false, duration:0 });
	$(".media-panel .media-categories").find("#"+cur_viewing_media_category+"-category").animate({top: 0}, { queue:false, duration:0 });
	
	$(".media-panel .media-menu ul li a").click(function(){
		var new_viewing_category = $(this).attr("id");

		if (new_viewing_category != cur_viewing_media_category) {
		    reset_media_pages("#"+new_viewing_category+"-category");
			
			// Get our position in the list
			var $p = $(this).parent().parent().children();
			var n = $p.index($(this).parent());
			//console.log(n);
			
			// Get cur's position in the list
			var c = $p.index($(".media-panel .media-menu ul li a.selected").parent());
			//console.log(c);
			
			if (c > n) {	//we're moved up the list, so scroll recipe-panels down
				$(".media-panel .media-categories").find("#"+new_viewing_category+"-category").animate({top: -(getElementHeight('.media-panel .media-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
				$(".media-panel .media-categories").find("#"+cur_viewing_media_category+"-category").animate({top: (getElementHeight('.media-panel .media-categories'))}, { queue:false, duration:500 });
			} else {		//we moved down the list, scroll recipe-panels up
				$(".media-panel .media-categories").find("#"+cur_viewing_media_category+"-category").animate({top: -(getElementHeight('.media-panel .media-categories'))}, { queue:false, duration:500 });
				$(".media-panel .media-categories").find("#"+new_viewing_category+"-category").animate({top: (getElementHeight('.media-panel .media-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
			}
			
			// Set hilight
			$(".media-panel .media-menu ul li a").attr("class", "");
			$(this).attr("class", "selected");
			
			cur_viewing_media_category = new_viewing_category;
		}
	});
	
});

function reset_media_pages(cur_cat) {
	//console.log(cur_cat);
	// Get Number of Media Pages
    num_media_pages = $(cur_cat + " .media-pages").children().size();
    cur_media_page = 0;
    
    $(cur_cat + " .media-pages .page .next-page").hide();
    $(cur_cat + " .media-pages .page .prev-page").hide();

    if (num_media_pages > 1)
    {
        if (cur_media_page < (num_media_pages - 1))
        {
        	$(cur_cat + " .media-pages .page .next-page").show();
        }
        if (cur_media_page > 0)
        {
        	$(cur_cat + " .media-pages .page .prev-page").show();
        }
    }
    
	cur_viewing_media = "none";
	$(".media-panel .media-categories .media-category .media-infos").css("zIndex",10);
	
    $(".back-to-gallery").hide();
    
	$(cur_cat + " .media-pages .page").animate({left: getElementWidth(cur_cat + ' .media-pages .page')}, { queue:false, duration:0 });
	$(cur_cat + " .media-pages .page").eq(cur_media_page).animate({left: 0}, { queue:false, duration:0 });
	$(cur_cat + " .media-pages").css("zIndex",20);
	$(cur_cat + " .media-infos .info").animate({left: getElementWidth(cur_cat + ' .media-infos .info')}, { queue:false, duration:0 });
	
}

// ========================== Form pages JS
$(function() {
	$(".form input.date").datepicker({
		minDate: 0,
		showAnim: null
	});
});
$(document).ready(function(){
	
	$(".form ul.options").hide();	//Initially hide all uloptions
	
	//when any options li is clicked, set the prev input text's value and hide the ul
	$(".form ul.options li").mouseover(function() {
		$(this).parent().prev("input").val($(this).text());
		//$(this).parent().hide();
		
		//console.trace($(this).text());
	});

	// Hide/Show the ul when the imput text is un/focused
	$(".form input.select").focusin(function(){
		$(this).next().show();
	});
	$(".form input.select").focusout(function(){
		$(this).next().hide();
	});

});


// ========================== Resources Page JS

var num_resources_pages = 0;
var cur_resources_page = 0;

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';

    // Get Number of Product Pages
    num_resources_pages = $(".resources-panel .panels").children().size();

    $(".resources-panel .panels .panel .next-page").hide();
    $(".resources-panel .panels .panel .prev-page").hide();

    if (num_resources_pages > 1)
    {
        if (cur_resources_page < (num_resources_pages - 1)) {
        	$(".resources-panel .panels .panel .next-page").show();
        }
        if (cur_resources_page > 0)
        {
        	$(".resources-panel .panels .panel .prev-page").show();
        }
    }

    $(".resources-panel .panels .panel").animate({left: getElementWidth('.resources-panel .panels .panel')}, { queue:false, duration:0 });
    
    $(".resources-panel .panels .panel").eq(cur_product_page).animate({left: 0}, { queue:false, duration:0 });

    $(".resources-panel .panels .panel .next-page").click(function(){
		var old_resources_page = cur_resources_page;

        cur_resources_page += 1;
        
        if (cur_resources_page == (num_resources_pages - 1)) {
        	$(".resources-panel .panels .panel .next-page").hide();
        	$(".resources-panel .panels .panel .prev-page").show();
        }
        else
        {
        	$(".resources-panel .panels .panel .next-page").show();
        	$(".resources-panel .panels .panel .prev-page").show();
        }
        
        $(".resources-panel .panels .panel").eq(old_resources_page).animate({left: -(getElementWidth('.resources-panel .panels .panel'))}, { queue:false, duration:500 });
        $(".resources-panel .panels .panel").eq(cur_resources_page).animate({left: getElementWidth('.resources-panel .panels .panel')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
    
    $(".resources-panel .panels .panel .prev-page").click(function(){
		var old_resources_page = cur_resources_page;

        cur_resources_page -= 1;
        
        if (cur_resources_page == 0) {
        	$(".resources-panel .panels .panel .next-page").show();
        	$(".resources-panel .panels .panel .prev-page").hide();
        }
        else
        {
        	$(".resources-panel .panels .panel .next-page").show();
        	$(".resources-panel .panels .panel .prev-page").show();
        }
        
        $(".resources-panel .panels .panel").eq(old_resources_page).animate({left: getElementWidth('.resources-panel .panels .panel')}, { queue:false, duration:500 });
        $(".resources-panel .panels .panel").eq(cur_resources_page).animate({left: -(getElementWidth('.resources-panel .panels .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });

});



// ========================== Pan Page JS

$.fn.enableLightbox = function() {
	return this.each(function(i) {
		var id = $(this).attr("id");
		id = id.substr(0,id.indexOf("-"));
		$(".lightbox-" + id).lightBox();
	});
};

var num_pan_pages = 0;
var cur_pan_page = 0;
var cur_viewing_pan_category = "none";

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';

    $(".pan-panel .pan-categories .panel .next-page").hide();
    $(".pan-panel .pan-categories .panel .prev-page").hide();
    
    $(".pan-panel .pan-categories .pan-category").enableLightbox();
    
    if (cur_viewing_pan_category == "none")
    {
        cur_viewing_pan_category = ($(".pan-panel .pan-menu ul li a").eq(0).attr("id")) ? "#" + $(".pan-panel .pan-menu ul li a").eq(0).attr("id") + "-category" : "none";
    	
		$(".pan-panel .pan-menu ul li a").eq(0).attr("class", "selected");
    }
    
    if ( cur_viewing_pan_category != "none")
    {
    	reset_pan_pages(cur_viewing_pan_category);
    }
    
    $(".pan-panel .pan-categories .pan-category .panel .next-page").click(function(){
		var old_pan_page = cur_pan_page;

        cur_pan_page += 1;
        
        if (cur_pan_page == (num_pan_pages - 1)) {
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .next-page").hide();
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .prev-page").show();
        }
        else
        {
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .next-page").show();
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .prev-page").show();
        }
        
        $(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel").eq(old_pan_page).animate({left: -(getElementWidth('.pan-panel .pan-categories '+cur_viewing_pan_category+' .panel'))}, { queue:false, duration:500 });
        $(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel").eq(cur_pan_page).animate({left: getElementWidth('.pan-panel .pan-categories '+cur_viewing_pan_category+' .panel')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
    
    $(".pan-panel .pan-categories .pan-category .panel .prev-page").click(function(){
		var old_pan_page = cur_pan_page;

        cur_pan_page -= 1;
        
        if (cur_pan_page == 0) {
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .next-page").show();
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .prev-page").hide();
        }
        else
        {
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .next-page").show();
        	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel .prev-page").show();
        }
        
        $(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel").eq(old_pan_page).animate({left: getElementWidth('.pan-panel .pan-categories '+cur_viewing_pan_category+' .panel')}, { queue:false, duration:500 });
        $(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel").eq(cur_pan_page).animate({left: -(getElementWidth('.pan-panel .pan-categories '+cur_viewing_pan_category+' .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
    });
    
    $(".pan-panel .pan-menu ul li a").click(function() {
    	var new_viewing_category = "#" + $(this).attr("id") + "-category";

		if (new_viewing_category != cur_viewing_pan_category) {
		    reset_pan_pages(new_viewing_category);
			
			// Get our position in the list
			var $p = $(this).parent().parent().children();
			var n = $p.index($(this).parent());
			//console.log(n);
			
			// Get cur's position in the list
			var c = $p.index($(".pan-panel .pan-menu ul li a.selected").parent());
			//console.log(c);
			
			if (c > n) {	//we're moved up the list, so scroll recipe-panels down
				$(".pan-panel .pan-categories").find(new_viewing_category).animate({top: -(getElementHeight('.pan-panel .pan-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
				$(".pan-panel .pan-categories").find(cur_viewing_pan_category).animate({top: (getElementHeight('.pan-panel .pan-categories'))}, { queue:false, duration:500 });
			} else {		//we moved down the list, scroll recipe-panels up
				$(".pan-panel .pan-categories").find(cur_viewing_pan_category).animate({top: -(getElementHeight('.pan-panel .pan-categories'))}, { queue:false, duration:500 });
				$(".pan-panel .pan-categories").find(new_viewing_category).animate({top: (getElementHeight('.pan-panel .pan-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
			}
			
			// Set hilight
			$(".pan-panel .pan-menu ul li a").attr("class", "");
			$(this).attr("class", "selected");
			
			cur_viewing_pan_category = new_viewing_category;
		}		
    	
    });
    
    $(".pan-panel .pan-categories .pan-category").animate({top: getElementHeight('.pan-panel .pan-categories')}, { queue:false, duration:0 });
	$(".pan-panel .pan-categories").find(cur_viewing_pan_category).animate({top: 0}, { queue:false, duration:0 });
	$(".pan-panel .pan-categories .pan-category .panel").animate({left: getElementWidth('.pan-panel .pan-categories .pan-category .panel')}, { queue:false, duration:0 });
	$(".pan-panel .pan-categories "+cur_viewing_pan_category+" .panel").eq(cur_pan_page).animate({left: 0}, { queue:false, duration:0 });
});

function reset_pan_pages(cur_cat) {
	//console.log(cur_cat);
	// Get Number of Recipe Pages
    num_pan_pages = $(".pan-panel .pan-categories "+cur_cat).children().size();

	cur_pan_page = 0;
	
    $(".pan-panel .pan-categories "+cur_cat+" .panel .next-page").hide();
    $(".pan-panel .pan-categories "+cur_cat+" .panel .prev-page").hide();
    
    if (num_pan_pages > 1)
    {
        if (cur_pan_page < (num_pan_pages - 1))
        {
        	$(".pan-panel .pan-categories "+cur_cat+" .panel .next-page").show();
        }
        if (cur_pan_page > 0)
        {
        	$(".pan-panel .pan-categories "+cur_cat+" .panel .prev-page").show();
        }
    }

	$(".pan-panel .pan-categories "+cur_cat+" .panel").animate({left: getElementWidth('.pan-panel .pan-categories '+cur_cat+' .panel')}, { queue:false, duration:0 });
	$(".pan-panel .pan-categories "+cur_cat+" .panel").eq(cur_pan_page).animate({left: 0}, { queue:false, duration:0 });
}



/* ================== Watermellon Recipe page JS =================== */
var cur_watermelon_recipe_page = 0;
var num_watermelon_recipe_pages = 0;

var cur_viewing_watermelon_recipe = "none";

$(document).ready(function(){
	jQuery.easing.def = 'easeInOutExpo';

	// Get Number of Recipe Pages
    num_watermelon_recipe_pages = $(".watermelon-panel  .panels").children().size();

    $(".watermelon-panel .panels .panel .next-page").hide();
    $(".watermelon-panel .panels .panel .prev-page").hide();

    if (num_watermelon_recipe_pages > 1)
    {
        if (cur_watermelon_recipe_page < (num_watermelon_recipe_pages - 1)) {
        	$(".watermelon-panel .panels .panel .next-page").show();
        }
        if (cur_watermelon_recipe_page > 0)
        {
        	$(".watermelon-panel .panels .panel .prev-page").show();
        }
    }
    
    $(".back-to-watermelon-recipes").hide();

    if (cur_viewing_watermelon_recipe != "none")
    {
        $(".back-to-watermelon-recipes").show();
    }


	// Recipe Animation
	$(".watermelon-panel .panels .panel .watermelon-item").hover(function(){
	    $(this).animate({backgroundColor: "#009de9"}, { queue:false, duration:300 });
	},function(){
	    $(this).animate({backgroundColor: "#000"}, { queue:false, duration:300 });
	});

	
	$(".watermelon-panel .panels .panel").animate({left: getElementWidth('.watermelon-panel .panels .panel')}, { queue:false, duration:0 });
	$(".watermelon-panel .panels .panel").eq(cur_recipe_page).animate({left: 0}, { queue:false, duration:0 });
	$(".watermelon-panel .panels").css("zIndex",20);
	$(".watermelon-panel .info-panels .panel").animate({left: getElementWidth('.watermelon-panel .info-panels .panel')}, { queue:false, duration:0 });
	$(".watermelon-panel .panels .panel").hide();
	$(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).show();

	$(".watermelon-panel .panels .panel .watermelon-item").click(function(){
		
	    $(".watermelon-panel .info-panels").css("zIndex",30);
	    cur_viewing_watermelon_recipe = "#"+$(this).attr("id")+"-info";
		$(".watermelon-panel .info-panels").find(cur_viewing_watermelon_recipe).show();
	    $(".watermelon-panel .info-panels").find(cur_viewing_watermelon_recipe).animate({left: 0}, { queue:false, duration:500 });
		
		
	    $(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).animate({left: -(getElementWidth('.watermelon-panel .panels .panel'))}, { queue:false, duration:500, complete: function() { $(this).hide(); $(".back-to-watermelon-recipes").show();} });
	});

	$(".watermelon-panel .panels .panel .next-page").click(function(){
		var old_watermelon_recipe_page = cur_watermelon_recipe_page;
	    //cur_recipe_page = (cur_recipe_page + 1 < num_recipe_pages) ? cur_recipe_page + 1 : 0;
	    
	    cur_watermelon_recipe_page += 1;
        
        if (cur_watermelon_recipe_page == (num_watermelon_recipe_pages - 1)) {
        	$(".watermelon-panel .panels .panel .next-page").hide();
        	$(".watermelon-panel .panels .panel .prev-page").show();
        }
        else
        {
        	$(".watermelon-panel .panels .panel .next-page").show();
        	$(".watermelon-panel .panels .panel .prev-page").show();
        }
        
	    $(".watermelon-panel .panels .panel").eq(old_watermelon_recipe_page).animate({left: -(getElementWidth('.watermelon-panel .panels .panel'))}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).show();
		$(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).animate({left: getElementWidth('.watermelon-panel .panels .panel')}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	$(".watermelon-panel .panels .panel .prev-page").click(function(){
		var old_watermelon_recipe_page = cur_watermelon_recipe_page;
	    //cur_recipe_page = (cur_recipe_page - 1 >= 0) ? cur_recipe_page - 1 : num_recipe_pages - 1;
	    cur_watermelon_recipe_page -= 1;
        
        if (cur_watermelon_recipe_page == 0) {
        	$(".watermelon-panel .panels .panel .next-page").show();
        	$(".watermelon-panel .panels .panel .prev-page").hide();
        }
        else
        {
        	$(".watermelon-panel .panels .panel .next-page").show();
        	$(".watermelon-panel .panels .panel .prev-page").show();
        }
        
	    $(".watermelon-panel .panels .panel").eq(old_watermelon_recipe_page).animate({left: getElementWidth('.watermelon-panel .panels .panel')}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).show();
		$(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).animate({left: -(getElementWidth('.watermelon-panel .panels .panel'))}, { queue:false, duration:0 }).animate({left: 0}, { queue:false, duration:500 });
	});

	$(".back-to-watermelon-recipes").click(function(){
	    $(".back-to-watermelon-recipes").hide();
	    $(".watermelon-panel .info-panels").css("zIndex",10);
	    $(".watermelon-panel .info-panels").find(cur_viewing_watermelon_recipe).animate({left: getElementWidth('.watermelon-panel .info-panels .panel')}, { queue:false, duration:500, complete: function() { $(this).hide();} });
	    $(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).show();
		$(".watermelon-panel .panels .panel").eq(cur_watermelon_recipe_page).animate({left: 0}, { queue:false, duration:500 });
	    cur_viewing_watermelon_recipe = "none";
	});	
});

// ========================== Word List Page JS

var cur_viewing_wordlist_category = "none";
var cur_viewing_definition_letter = "none";

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';

    if (cur_viewing_wordlist_category == "none")
    {
        cur_viewing_wordlist_category = ($(".wordlist-panel .wordlist-menu ul li a").eq(0).attr("id")) ? "#" + $(".wordlist-panel .wordlist-menu ul li a").eq(0).attr("id") + "-category" : "none";
    	
		$(".wordlist-panel .wordlist-menu ul li a").eq(0).attr("class", "selected");
    }
    
    if ( cur_viewing_wordlist_category != "none")
    {
    	reset_wordlist_pages(cur_viewing_wordlist_category);
    }
    
    $(".wordlist-panel .wordlist-menu ul li a").click(function() {
    	var new_viewing_category = "#" + $(this).attr("id") + "-category";

		if (new_viewing_category != cur_viewing_wordlist_category) {
		    reset_wordlist_pages(new_viewing_category);
			
			// Get our position in the list
			var $p = $(this).parent().parent().children();
			var n = $p.index($(this).parent());
			//console.log(n);
			
			// Get cur's position in the list
			var c = $p.index($(".wordlist-panel .wordlist-menu ul li a.selected").parent());
			//console.log(c);
			
			if (c > n) {	//we're moved up the list, so scroll recipe-panels down
				$(".wordlist-panel .wordlist-categories").find(new_viewing_category).animate({top: -(getElementHeight('.wordlist-panel .wordlist-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
				$(".wordlist-panel .wordlist-categories").find(cur_viewing_wordlist_category).animate({top: (getElementHeight('.wordlist-panel .wordlist-categories'))}, { queue:false, duration:500 });
			} else {		//we moved down the list, scroll recipe-panels up
				$(".wordlist-panel .wordlist-categories").find(cur_viewing_wordlist_category).animate({top: -(getElementHeight('.wordlist-panel .wordlist-categories'))}, { queue:false, duration:500 });
				$(".wordlist-panel .wordlist-categories").find(new_viewing_category).animate({top: (getElementHeight('.wordlist-panel .wordlist-categories'))}, { queue:false, duration:0 }).animate({top: 0}, { queue:false, duration:500 });
			}
			
			// Set hilight
			$(".wordlist-panel .wordlist-menu ul li a").attr("class", "");
			$(this).attr("class", "selected");
			
			cur_viewing_wordlist_category = new_viewing_category;
		}		
    	
    });
    
    $(".wordlist-panel .letters .letter a").click(function() {
    	var new_viewing_section = "#" + $(this).attr("id") + "-section";

		if (new_viewing_section != cur_viewing_wordlist_category) {
			

			$(cur_viewing_wordlist_category + " .letters .letter a").attr("class", "");	
			$(this).attr("class", "selected");
			
			$(cur_viewing_wordlist_category + " .definitions table").hide();	
			$(cur_viewing_wordlist_category + " .definitions").find(new_viewing_section).show();	
			
			cur_viewing_definition_letter = new_viewing_section;
		}		
    	
    });
    
    $(".wordlist-panel .wordlist-categories .wordlist-category").animate({top: getElementHeight('.wordlist-panel .wordlist-categories')}, { queue:false, duration:0 });
	$(".wordlist-panel .wordlist-categories").find(cur_viewing_wordlist_category).animate({top: 0}, { queue:false, duration:0 });
});

function reset_wordlist_pages(cur_cat) {
	//console.log(cur_cat);
	
	cur_viewing_definition_letter = ($(cur_cat + " .letters .letter").eq(0).find("a").attr("id")) ? "#" + $(cur_cat + " .letters .letter").eq(0).find("a").attr("id") + "-section" : "none";
    $(cur_cat + " .letters .letter a").attr("class", "");	
	$(cur_cat + " .letters .letter").eq(0).find("a").attr("class", "selected");
	
	if (cur_viewing_definition_letter != "none")
	{
		$(cur_cat + " .definitions table").hide();	
		$(cur_cat + " .definitions").find(cur_viewing_definition_letter).show();	
	}
}



// Kids Page

var cur_kid_recipe_panel = 0;
var num_kid_recipe_panels = 0;
var active_recipe_id = 0;

$(document).ready(function(){
    jQuery.easing.def = 'easeInOutExpo';
    
    $(".image-menu-nav .menu-nav .menu-item span").vAlignP();
    
    $(".image-menu-nav img").hide();
    
    $(".kids-page-section").hide();
    
    $(".kids-recipe-panel .panels .page-panels .panel").css("left",$(".kids-recipe-panel .panels .panel").css("width"));
    $(".kids-recipe-panel .panels .page-panels .panel").eq(0).css("left",0);
    
    $(".image-menu-nav img#"+$(".image-menu-nav .menu-nav .menu-item").eq(0).attr("id")).show();
    
    $(".image-menu-nav .menu-nav .menu-item").hover(function(){
    	//alert($(this).position().top);
    	$(".image-menu-nav .menu-nav .hover-bg").animate({top: $(this).position().top}, {duration: 500, queue: false});
    	$(".image-menu-nav img").hide();
    	$(".image-menu-nav img#"+$(this).attr("id")).show();
    }, function(){
    	$(".image-menu-nav .menu-nav .hover-bg").animate({top: $(".image-menu-nav .menu-nav .menu-item.active").eq(0).position().top},  {duration: 500, queue: false});
    	$(".image-menu-nav img").hide();
    	$(".image-menu-nav img#"+$(".image-menu-nav .menu-nav .menu-item.active").eq(0).attr("id")).show();
    });
    
    $(".image-menu-nav .menu-nav .menu-item").click(function(event){
    	event.preventDefault();
    	//alert($(this).attr("id"));
    	
    	$(".image-menu-nav .menu-nav .menu-item").removeClass("active");
    	$(this).addClass("active");
    	
    	$(".kids-page-section").hide();
    	$(".kids-page-section#"+$(this).attr("id")+"-page").show();
    	
    	$(".kids-recipe-panel .panels .page-panels .panel .panel-item span").vAlignP();
    	
    	resetKidsRecipes(false);
    });
    
    $(".kids-recipe-panel .panels .page-panels .panel .panel-item").click(function(event){
    	event.preventDefault();
    	
    	active_recipe_id = parseInt($(this).attr("id").replace("item",""));
    	
    	$(".kids-recipe-panel .controls.pages").hide();
    	$(".kids-recipe-panel .controls.print").show();
    	
    	$(".kids-recipe-panel .panels .page-panels").css("left",0).animate({left: "-"+$(".kids-recipe-panel .panels").css("width")}, {duration: 500, queue: false});
	    $(".kids-recipe-panel .panels .recipe-panels").css("left",$(".kids-recipe-panel .panels").css("width")).animate({left: 0}, {duration: 500, queue: false});
	    
	    
		$(".kids-recipe-panel .panels .recipe-panels .panel").hide();
		$(".kids-recipe-panel .panels .recipe-panels .panel#"+$(this).attr("id")+"-info").show();
    });
    
    $(".kids-recipe-panel .controls .back").click(function(event){
    	event.preventDefault();
    	
    	resetKidsRecipes(true);
    });
    
    $(".kids-recipe-panel .controls .print").click(function(event){
    	event.preventDefault();
    	//alert(active_recipe_id);
    	//return;
    	if (active_recipe_id != 'NaN') window.open(base_url+'recipes/print_recipe/'+active_recipe_id+'/','print_recipe_'+active_recipe_id,'toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
    });
    
    function resetKidsRecipes(goback) {
    	cur_kid_recipe_panel = 0;
    	num_kid_recipe_panels = $(".kids-recipe-panel .panels .page-panels").children().size();
    	
    	$(".kids-recipe-panel .panels .page-panels .panel").css("left",$(".kids-recipe-panel .panels").css("width"));
    	$(".kids-recipe-panel .panels .page-panels .panel").eq(cur_kid_recipe_panel).css("left",0);
    	
    	$(".kids-recipe-panel .controls.pages").show();
    	$(".kids-recipe-panel .controls.print").hide();
    	
    	if (goback) {
    		$(".kids-recipe-panel .panels .recipe-panels").css("left",0).animate({left: $(".kids-recipe-panel .panels").css("width")}, {duration: 500, queue: false});
	    	$(".kids-recipe-panel .panels .page-panels").css("left","-"+$(".kids-recipe-panel .panels").css("width")).animate({left: 0}, {duration: 500, queue: false});
    		//$(".kids-recipe-panel .panels .page-panels").css("left",$(".kids-recipe-panel .panels").css("width"));
    		//$(".kids-recipe-panel .panels .recipe-panels").css("left",$(".kids-recipe-panel .panels").css("width"));
    	} else {
    		$(".kids-recipe-panel .panels .page-panels").css("left",0);
    		$(".kids-recipe-panel .panels .recipe-panels").css("left",$(".kids-recipe-panel .panels").css("width"));
    	}
    	
    	updateKidsRecipeControls();
    };
    
    function nextKidsRecipePanel() {
    	//alert($(".kids-recipe-panel .panels").css("width"));
    	//return;
    	
    	if (cur_kid_recipe_panel < (num_kid_recipe_panels - 1))
    	{
    		cur_kid_recipe_panel += 1;
    	
	    	$(".kids-recipe-panel .panels .page-panels .panel").eq(cur_kid_recipe_panel - 1).css("left",0).animate({left: "-"+$(".kids-recipe-panel .panels").css("width")}, {duration: 500, queue: false});
	    	$(".kids-recipe-panel .panels .page-panels .panel").eq(cur_kid_recipe_panel).css("left",$(".kids-recipe-panel .panels").css("width")).animate({left: 0}, {duration: 500, queue: false});
    	}
    	updateKidsRecipeControls();
    }
    
    function prevKidsRecipePanel() {
    	if (cur_kid_recipe_panel > 0)
    	{
    		cur_kid_recipe_panel -= 1;
    	
	    	$(".kids-recipe-panel .panels .page-panels .panel").eq(cur_kid_recipe_panel + 1).css("left",0).animate({left: $(".kids-recipe-panel .panels").css("width")}, {duration: 500, queue: false});
	    	$(".kids-recipe-panel .panels .page-panels .panel").eq(cur_kid_recipe_panel).css("left","-"+$(".kids-recipe-panel .panels").css("width")).animate({left: 0}, {duration: 500, queue: false});
    	}
    	updateKidsRecipeControls();
    }
    
    function updateKidsRecipeControls() {
    	$(".kids-recipe-panel .controls .prev").hide();
    	$(".kids-recipe-panel .controls .next").hide();
    	
    	if (num_kid_recipe_panels > 1)
    	{
    		if (cur_kid_recipe_panel > 0) {
    			$(".kids-recipe-panel .controls .prev").show();
    		}
    		
    		if (cur_kid_recipe_panel < (num_kid_recipe_panels - 1)) {
    			$(".kids-recipe-panel .controls .next").show();
    		}
    	}
    }
    
    $(".kids-recipe-panel .controls .prev").click(function(event) {
    	event.preventDefault();
    	prevKidsRecipePanel();	
    });
    
    $(".kids-recipe-panel .controls .next").click(function(event) {
    	event.preventDefault();
    	nextKidsRecipePanel();	
    });
    
    setTimeout("$('.image-menu-nav .menu-nav .menu-item').eq(0).click();", 300);
    
    $('.kids-gallery-panel .images').cycle({
        fx:      'scrollHorz',
        timeout:  3000,
        prev:    '#prev-photo',
        next:    '#next-photo',
        pager:   '#dots',
        pagerAnchorBuilder: pagerFactory
    });
    
    function pagerFactory(idx, slide) {
    	//alert(idx);
        //var s = idx > 2 ? ' style="display:none"' : '';
        $("#dots").width(21 * (idx + 1));
        return '<li><a href="#" class="dot" title="Image #'+(idx + 1)+'">&nbsp;</a></li>';
    };
    
});