
//========================================================================
$(function() {
//========================================================================

    var mainpic = $("#mainpic").attr("src");
    $(".thumbnail").mouseover(function() {
        $("#mainpic").attr("src",$(this).attr("src"));
    });

    $(".thumbnail").mouseout(function() {
        $("#mainpic").attr("src",mainpic);
    });

    $(".thumbnail").click(function() {
        mainpic=$(this).attr("src");
    });

    var vars = getUrlVars();

    $("#refresh").change(function() {
        var newpage = "http://les5th.org/showitem.php";
        var rval = $(this).val();
        var ct =0;
        var rct=0;
        $.each(vars,function(key,value) {
            if (ct>0) {
                p="&";
            } else {
                p="?";
                ct++;
            }

            if (key=="refresh") {
                value=rval;
                rct++;
            }

            newpage += p + key + "=" + value;

        });
        p="&";

        if (rct==0) { // the calling page did not have a refresh...
            newpage += p + "refresh" + "=" + rval;
        }

        // alert(newpage);
        location.replace(newpage);
    });


    // set up the auto refresh feature
    var refreshrate = $("#refresh").val() * 1000;
    // alert ("REfresh Rate: " + refreshrate);
    if (refreshrate>0) {
        setTimeout("location.reload(true);",refreshrate);
    };


    var refreshrate2 = $("#refresh2").val() * 1000;
    var id = vars['id'];

    $("#itemdetail").load('ajaxitem.php?id='+id);

    if (refreshrate2>0) {
        var refreshId = setInterval(function() {
            $("#itemdetail").fadeOut("fast").load('ajaxitem.php?id='+id + '&randval='+ Math.random()).fadeIn("slow");
        }, refreshrate2);
    }
   $.ajaxSetup({ cache: false });

   $("#refresh2").change(function() {
       clearInterval(refreshId);
       refreshrate2 = $("#refresh2").val() * 1000;
       if (refreshrate2>0) {
            var refreshId = setInterval(function() {
                $("#itemdetail").fadeOut("fast").load('ajaxitem.php?id='+id + '&randval='+ Math.random()).fadeIn("slow");
            }, refreshrate2);
       }
   });


});

function  showItem(id) {
    $('#itemdetail').load('ajaxitem.php?id='+id);
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}



