﻿/// <reference path="/js/jquery-1.3.2.js" />
var curNavSection = "";


$(document).ready(function() {
loadEffects();



});

var pos = 0;

function animateScrollerRight() {
    var obj = $("#scrollerArea");
    obj.stop();
    obj.css("left", pos);
    var width = obj.css("width").replace("px", "");
    var newpos = obj.css("left").replace("px", "").replace("pt", "");

    newpos = newpos - 102;
    if (width - (-newpos) > 204) {
        pos = newpos;
        obj.animate({
            left: pos
        }, 500);
    }
}

function animateScrollerLeft() {
    var obj = $("#scrollerArea");
    obj.stop();

    obj.css("left", pos);
    var width = obj.css("width").replace("px", "");
    var newpos = obj.css("left").replace("px", "").replace("pt", "");
    newpos = newpos - (-102);

    if (newpos <= 0) {
        pos = newpos;
        obj.animate({
            left: pos
        }, 500);
    }
}




function stopSlotWheel(obj) {


    $(obj).children(".intro").hide();
    $(obj).children(".meat").show();
    $(obj).children(".side").show();
    $(obj).children(".animation").hide();

    if ($(obj).attr("id") == "wheelLeft") {
        var selectedItem = randomVal(1, 4);

        $(obj).children(".meat").children(".list").css("top", -162 * (selectedItem - 1));

        $("#slotMeatSelected").html($("#slotMachine .window #wheelLeft .list img[rel='" + selectedItem + "']").attr("alt") + " + ");
    }

    if ($(obj).attr("id") == "wheelRight") {
        var selectedItem = randomVal(1, 21);

        $(obj).children(".side").children(".list").css("top", -162 * (selectedItem - 1));

        $("#slotSideSelected").html($("#slotMachine .window #wheelRight .list img[rel='" + selectedItem + "']").attr("alt"));
    }


}

var meatTimeout = 0;
var sideTimeout = 0;

function pullSlotHandle() {
    aSound.play();
    clearTimeout(meatTimeout);
    clearTimeout(sideTimeout);

    $("#slotMachine .window .wheel .intro").hide();
    $("#slotMachine .window .wheel .meat").hide();
    $("#slotMachine .window .wheel .side").hide();
    $("#slotMachine .window .wheel .animation").show();

    $("#slotMeatSelected").html("");
    $("#slotSideSelected").html("");

    meatTimeout = setTimeout(function() { stopSlotWheel('#wheelLeft'); }, 1300);
    sideTimeout = setTimeout(function() { stopSlotWheel('#wheelRight'); }, 2000);

}

function loadEffects()
{
    $(".ui-fade-rollover").each(function(){
        if($(this).attr("effect_loaded") == "true") return;
        $(this).attr("effect_loaded", "true"); 

		if ($(this).attr("alt") != null && curNavSection != "" && $(this).attr("alt").indexOf(curNavSection) != -1) {
            $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
            isOn = true;
        }
        else
		{
			$(this).bind("mouseenter", function(e){
				$(this).attr("src", $(this).attr("src").replace("_off", "_over"));
			});
			$(this).bind("mouseleave", function(e){
			$(this).attr("src", $(this).attr("src").replace("_over", "_off"));
			});
		}

    });
}

function nextLCP()
{
    getNewLCP();

    if(lcp > -1)
    {
        $("#g" + lcp).fadeOut("slow", function()
        {
            $("#g" + cp).fadeIn("fast");
        });
    }
    else
    {
        $("#g" + cp).fadeIn("fast");
    }

    lcp = cp;
}

function getNewLCP()
{
    cp = getRandNumber(lcpT);

    if((cp % 4) == (lcp % 4))
        getNewLCP();
}

function randomVal(min, max) {
    return Math.floor(Math.random() * max - min + 1) + min;
}

function getRandNumber(max)
{
    return Math.floor(Math.random() * max)
}

function loadPageData(t, img) {


    $.get(t + "&ele=" + img, function(data) {
        if (data != "") {
            $("#RecipeImage").html(data);
        }
    });

    $.get(t + "&ele=head", function(data) {
        if (data != "") {
            $("#head").html(data);
        }
    });

    $.get(t + "&ele=body", function(data) {
        if (data != "") {
            $("#body").html(data);
        }
    });

    $(".link").html("<a href=\"javascript:chosensidemate();\">choose me as a sidemate</a>");
}

function getSideMateEle() {

    var h = "";
    $(".sideMateEle").each(function(i) {
        h += $(this).attr("id") + "|";
    });
    return h.substr(0, (h.length - 1)).split("|");
}

// share with a lonely friend

$(function()
{
    $('.custom_button, .hover_menu').mouseenter(function()
    {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });

    var delay = 400;
    function hideMenu()
    {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden'))
        {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }


});





