﻿$(document).ready(function() {
    //get the hash
    var page = window.location.hash.replace("#", "");
    if (page.length < 2) {
        page = "blueberry-bundt-cake";
    }

    popRecipe(page);
        
});

function popRecipe(hash) {
    $.ajax({
        type: "GET",
        url: "/CatCora/Controls/VideoRecipes.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find("recipe").each(function() {
                var slug = $(this).attr("slug");
                if (slug == hash) {
                    popThumbs($(this).find('id').text());
                    var sClass = $(this).find('class').text();
                    $("#catcora-video-recipe-title").find("h2").attr("class", sClass);
                    $("#catcora-video-recipe-title").find("h2").html($(this).find('title').text());
                    $("#catcora-video-recipe-content").html($(this).find('content').text());
                }
            });
        }
    });
   
   //Set Flash vid 
   var funcall = "showVids(\""+ hash + "\")";
   setTimeout(funcall,1000);       
}

function showVids(hash) {
    var flash = getMovie('catcoraFlashContent');
    if (hash == "blueberry-bundt-cake") {
        flash.doVideo("blueberry_bundt");
    } else if (hash == "passion-truffles") {
        flash.doVideo('truffles');
    } else if (hash == "unfried-vegetble-dumplings") {
        flash.doVideo('veg_dumplings');
    } else if (hash == "mini-spinach-feta-tarts") {
        flash.doVideo('feta_tarts');
    }

}

function popThumbs(id) {
    $("#catcora-video-thumb1").attr("class", "thumb1");
    $("#catcora-video-thumb2").attr("class", "thumb2");
    $("#catcora-video-thumb3").attr("class", "thumb3");
    $("#catcora-video-thumb4").attr("class", "thumb4");

    $("#catcora-video-thumb" + id).attr("class", "thumb" + id + "-active");
}