function switchVideo(videoId)
{
    var videoList = $$('.videoBox');
    for (var i=0; i<videoList.length; i++)
    {
        if (videoList[i].id == ('videoBox_' + videoId))
        {
            $(videoList[i].id).show();
        }
        else
        {
            $(videoList[i].id).hide();
        }
    }
}

function togglePopular(listId)
{
    var popularIds = new Array('popularRecipes', 'popularTechniques', 'popularSearches');
    for (var i=0; i<popularIds.length; i++)
    {
        if (listId == popularIds[i])
            $(popularIds[i]).show();
        else
            $(popularIds[i]).hide();
    }
}

function fixColumnHeight()
{
    var leftColHeight = $('leftColumnRecipeContent').getHeight();
    var rightColHeight = $('rightColumnLists').getHeight();

    if (leftColHeight > rightColHeight)
    {
        $('rightColumnLists').setStyle({'height': leftColHeight+'px'});
        $('leftColumnRecipeContent').setStyle({'height': leftColHeight+'px'});
    }
    else
    {
        $('rightColumnLists').setStyle({'height': rightColHeight+'px'});
        $('leftColumnRecipeContent').setStyle({'height': rightColHeight+'px'});
    }
}


fixColumnHeight();


//Hide show code

// PLEASE DO NOT REMOVE THIS. THANKS
// FIND GREATE JAVASCRIPT CODES AT http://www.wallpaperama.com
var state = 'hidden';

function showhide(layer_ref) {

if (state == 'visible') {
state = 'hidden';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}


// Rating javascript

/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;   // Is the maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num){
    sMax = 0;    // Is the maximum number of stars
    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }

    if(!rated){
        s = num.id.replace("_", ''); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){
                document.getElementById("_"+i).className = "on";
                document.getElementById("rateStatus").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("_"+i).className = "";
            }
        }
    }
}

// For when you roll out of the the whole thing //
function off(me){
    if(!rated){
        if(!preSet){
            for(i=1; i<=sMax; i++){
                document.getElementById("_"+i).className = "";
                //document.getElementById("rateStatus").innerHTML = me.parentNode.title;
                document.getElementById("rateStatus").innerHTML = "rate this recipe";
            }
        }else{
            rating(preSet);
            document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
        }
    }
}

// When you actually rate something //
function rateIt(me){
    if(!rated){
        document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
        preSet = me;
        rated=1;
        showhide('agent99');
        sendRate(me);
        rating(me);
    }
}

// Send the rating information using Ajax.
function sendRate(sel){
    new Ajax.Request('/js/addRating.php',
    {
        method: 'post',
        parameters: {'rating': sel.title, 'recipeId': recipe, 'userId': user},
        onSuccess: function(data)
        {
            //show echo from ajax call.
            //alert(data.responseText);
            //if we wanted to update the recipe average rating we could pass it back here.
//            if (data.responseText != 'fail')
//            {
//                $('rating_display').innerHTML = data.responseText;
//            }
//            $('load_msg').setStyle({'display': 'none'});
//            hide_rating();
        }
    });
    //alert("Your rating was: "+sel.title);
}


var RecipeComments = Class.create(
{
    save: function(recipeId, commentText)
    {
        // send if text is not empty
        if (commentText !== '')
        {
            var options = {
                parameters: {
                    IsAjax : true,
                    RecipeId : recipeId,
                    CommentText: commentText
                },

                method: 'post',

                onComplete: function(obj) {
                    var responseText = obj.responseText.strip();
                    if (responseText !== '')
                        $('commentsBlock').insert({ top: responseText });

                    $('comments').value = '';
                }.bind(this),

                onFailure: function(obj) {
                }.bind(this)
            };

            new Ajax.Request('/recipes/addcomment/', options);
        }
    }
});

function addrecipeandhide(layer_ref) {
    if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval( "document.all." + layer_ref + ".style.visibility = state");
        }
        if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].visibility = state;
        }
        if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.visibility = state;
        }
    new Ajax.Request('/js/addToRecipeBook.php',
    {
        method: 'post',
        parameters: {'recipeId': recipe, 'userId': user},
        onSuccess: function(data)
        {
            //show echo from ajax call. (for testing)
            // alert(data.responseText);
        }
    });
}

