var cats;
var recs;
var detail;
var tacosalad;

var wh;
var ww;
var backimg = new Image();
backimg.src = "../images/bg.jpg";
var slider = new Array();
var si = 0;
var sel;

$(document).ready(function() {

    if ($("#cats").length > 0) {
        $(".recImg").click(function(obj) {
            imgView($(this).attr("src"));
        });    
        loadCats();
    }
    loadTitle();
});

function doSlide(sid) {
    $("#featuredPic").attr("src", slider[sid][2]);
    var html = "";
    for (xx = slider.length - 1; xx > -1; xx--) {
        html += "<img class=sliderSelect src=../images/selectOff.jpg slideid=" + xx + " align=right>"
    }
    html += "<br><a href=http://www.tacosalad.com/post.aspx?postid=" + slider[sid][3] + ">" + slider[sid][0] + "</a><br>" + slider[sid][1] + "";
    $("#featuredTitle").html(html);
    $(".sliderSelect").each(function(obj) {
        if ($(this).attr("slideid") == sid) {
            $(this).attr("src", "../images/selectOn.jpg");
        }
        else {
            $(this).attr("src", "../images/selectOff.jpg");
        }
    });
    $(".sliderSelect").each(function(obj) {
        $(this).css("cursor", "pointer");
        $(this).mouseover(function() {
            doSlide($(this).attr("slideid"));
        });
    });
}

function goPost(pid) {
    document.location.href = "post.aspx?postid=" + pid;
}

function loadTitle(){
    $("#tacosalad").fadeIn("slow", function() {
        if ($("#googleAdPost").length > 0) {
            $("#googleAdPost").css("left", "205px");
            $("#googleAdPost").animate({ top: 10 }, 500);

        }
        if ($("#detailPost").length > 0) {
            $("#detailPost").css("top", "-900px");
            $("#detailPost").css("left", "440px");
            $("#detailPost").animate({ top: 10 }, 500);
        }
        if ($("#featuredList").length > 0) {
            $(".featuredItem").each(function(obj) {
                slider[si] = new Array();
                slider[si][0] = $(this).attr("title");
                slider[si][1] = $(this).attr("summarY");
                slider[si][2] = $(this).attr("src");
                slider[si][3] = $(this).attr("postid");
                si++;
            });
            $("#featuredList").animate({ top: 10 }, 500);
            doSlide(0);
        }
    });
}

function loadCats() {
    $("#cats").animate({top:10},500);

    $(".catLink").click(function() {
        var cat = $(this).attr("name");
        loadRecs(cat);
    });
}

function loadRecs(cat) {
    $("#recs").css("display", "none");
    $(".detail").css("display", "none");
    $("#googleAd").css("display","none");

    $.get("recs.asp?category=" + cat, function(data) {
        $("#recs").html(data);
        $("#recs").css("display", "block");

        $("#recs").css("top","-750");

        $("#recs").animate({ top: 10 });

        $(".recLink").click(function() {
            var postid = $(this).attr("name");
            loadDetail(postid);
        });
    });
}

function loadDetail(postid) {
    $("#googleAd").css("display","none");
    $(".detail").css("display", "none")
    $(".detail").each(function() {
        if (postid == $(this).attr("postid")) {
            $("#googleAd").css("display", "block");
            $(this).css("display", "block");
            $(this).animate({ top: 10 });
            $("#googleAd").animate({ top: 10 });
        }
    });
}

function imgView(src) {
    var wh = $(window).height();
    var ww = $(window).width();
    var dh = $(document).height();

    $("#bg").html("&nbsp;");
    $("#bg").css("width", ww);
    $("#bg").css("height", dh);

    $("#pic").attr("src",src);

    var pw = $("#pic").width();
    var ph = $("#pic").height();

    $("#pic").css("top", wh / 2 - ph / 2);
    $("#pic").css("left", ww / 2 - pw / 2);

    $("#bg").fadeIn("slow", function() {
        $("#pic").fadeIn("slow", function() {
            $("#bg").click(function() {
            $("#bg").fadeOut("slow");
                $("#pic").fadeOut("slow");
            });
            $("#pic").click(function() {
                $("#bg").fadeOut("slow");
                $("#pic").fadeOut("slow");
            });
        });
    });
}






