// JavaScript Document

$(document).ready( function()
{

    // move the window around on the background
    // NOTE: This uses the jQuery UI plugin ui.draggable.js which must be loaded beforehand!
    $("#stage .window img").draggable();

    // position the windows according to the saved X and Y coordinates
    $("#window_1.window img").css("left", variables_config.x1 + "px");
    $("#window_1.window img").css("top", variables_config.y1 + "px");
    $("#window_2.window img").css("left", variables_config.x2 + "px");
    $("#window_2.window img").css("top", variables_config.y2 + "px");

    // save the position when rolled over
    $("#stage .window img").mouseup( function()
    {
        var newX = $(this).attr("offsetLeft");
        var newY = $(this).attr("offsetTop");
        var expire = 60*60*24*7;
        winNo = $(this).parent().attr("id").split('_')[1];

        if (winNo == '1')
        {
            variables_config.x1 = newX;
            variables_config.y1 = newY;
            document.cookie = "x" + winNo + "=" + variables_config.x1 + "; max-age=" + expire;
            document.cookie = "y" + winNo + "=" + variables_config.y1 + "; max-age=" + expire;
        }
        else
        {
            variables_config.x2 = newX;
            variables_config.y2 = newY;
            document.cookie = "x" + winNo + "=" + variables_config.x2 + "; max-age=" + expire;
            document.cookie = "y" + winNo + "=" + variables_config.y2 + "; max-age=" + expire;
        }
        document.body.focus();
    });
    // move the magnifier over the window on rollover
    //$("#stage .window img").mouseenter(function(){
    //		var newX = $(this).attr("offsetLeft") + $(this).width() - 16;
    //		var newY = $(this).attr("offsetTop") + $(this).height() - 16;
    //		$("#stage .zoom").css("left", newX + "px");
    //		$("#stage .zoom").css("top", newY + "px");
    //		$("#stage .zoom").fadeIn();
    //	});
    //	$("#stage .window img").mouseout(function(){
    //		$("#stage .zoom").fadeOut();
    //	});

});
