﻿/**
 * Utility and common functions required by the webtoolkit. Requires jQuery 1.1.4
 *
 * Graeme Wilkinson mail@graemewilkinson.com
 **/

var PLEASE_WAIT_DIALOG = '<div id="pleaseWait">Please Wait</div>';
var PAGE_FADE = '<div id="pageFade">&nbsp;</div>';

$(document).ready(function(){intiWebToolkit();});

function intiWebToolkit()
{
    $(".attachPW").click(displayPleaseWait);
    hideWebsiteImageControls();
    hideDownloadControls();
}

function fadeBackground()
{
    $("body").append(PAGE_FADE);
    $("#pageFade").width($(window).innerWidth());
    $("#pageFade").height($(document).height());
    $("#pageFade").css("opacity","0");
    $("#pageFade").fadeTo(500,0.9);
}

function displayPleaseWait()
{
    fadeBackground();
    $("body").append(PLEASE_WAIT_DIALOG);
    $("#pleaseWait").css("top",($(window).innerHeight()/2) - ($("#pleaseWait").height()/2) + $(window).scrollTop());
    $("#pleaseWait").css("left",($(window).innerWidth()/2) - ($("#pleaseWait").width()/2));
    $("#pleaseWait").show();
}

/**
 * Hides the upload controls for a website image
 **/
function hideWebsiteImageControls()
{
    $(".websiteImage .controls").hide();
    $(".websiteImage .changeBtn").click(displayWebsiteImageControls);
}

/**
 * Displayes the upload controls for a website image
 **/
function displayWebsiteImageControls()
{
    $(".websiteImage .changeBtn").hide();
    $(".websiteImage .controls").fadeIn();
}

/**
 * Hides the upload controls for a download
 **/
function hideDownloadControls()
{
    $(".download .controls").hide();
    $(".download .changeBtn").click(displayDownloadControls);
}

/**
 * Displays the upload controls for a download
 **/
function displayDownloadControls()
{
    $(".download .changeBtn").hide();
    $(".download .controls").fadeIn();
}