// This file was generated by Dashcode from Apple Inc.
// You may edit this file to customize your Dashboard widget.

//
// Function: load()
// Called by HTML body element's onload event when the widget is ready to start
//
function load()
{
    setupParts();
    CreateGrabber("grabber", "front");
}

//
// Function: remove()
// Called when the widget has been removed from the Dashboard
//
function remove()
{
    // Stop any timers to prevent CPU usage
    // Remove any preferences as needed
    // widget.setPreferenceForKey(null, createInstancePreferenceKey("your-key"));
}

//
// Function: hide()
// Called when the widget has been hidden
//
function hide()
{
    // Get all composition elements and pause or stop them
    var compositions = document.getElementsByTagName("embed");
    for (var f = 0; f < compositions.length; f++) {
        if (compositions[f].type == "application/x-quartzcomposer" &&
            !compositions[f].paused()) {
            if (attributes.pauseResume == 0) {
                compositions[f].pause();
            }
            else {
                compositions[f].stop();
            }
        }
    }
}

//
// Function: show()
// Called when the widget has been shown
//
function show()
{
    // Get all composition elements and play them
    var compositions = document.getElementsByTagName("embed");
    for (var f = 0; f < compositions.length; f++) {
        if (compositions[f].type == "application/x-quartzcomposer" &&
            (!compositions[f].playing() || compositions[f].paused())) {
            compositions[f].play();
        }
    }
}

//
// Function: sync()
// Called when the widget has been synchronized with .Mac
//
function sync()
{
    // Retrieve any preference values that you need to be synchronized here
    // Use this for an instance key's value:
    // instancePreferenceValue = widget.preferenceForKey(null, createInstancePreferenceKey("your-key"));
    //
    // Or this for global key's value:
    // globalPreferenceValue = widget.preferenceForKey(null, "your-key");
}

//
// Function: showBack(event)
// Called when the info button is clicked to show the back of the widget
//
// event: onClick event from the info button
//
function showBack(event)
{
    var front = document.getElementById("front");
    var back = document.getElementById("back");

    if (window.widget) {
        widget.prepareForTransition("ToBack");
    }

    front.style.display = "none";
    back.style.display = "block";

    if (window.widget) {
        setTimeout("widget.performTransition();", 0);
    }
}

//
// Function: showFront(event)
// Called when the done button is clicked from the back of the widget
//
// event: onClick event from the done button
//
function showFront(event)
{
    var front = document.getElementById("front");
    var back = document.getElementById("back");

    if (window.widget) {
        widget.prepareForTransition("ToFront");
    }

    front.style.display = "block";
    back.style.display = "none";

    if (window.widget) {
        setTimeout("widget.performTransition();", 0);
    }
}

// Initialize the Dashboard event handlers
if (window.widget) {
    widget.onremove = remove;
    widget.onhide = hide;
    widget.onshow = show;
    widget.onsync = sync;
}
