﻿// Moveable framework for jQuery
// V1.0 - MAY 2010
// James MacFarlane


var closeTimer //used for mouseover close events

//utility functions - common library
function findPos(obj) {
    //returns x,y coordinates of an element
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}

function closeInit(element) {
    //timer for mouseout on panels
    clearTimeout(closeTimer)
    closeTimer = window.setTimeout(function() { closePanel(element) }, 100)
}

function closePanel(element) {
    $(element).fadeOut({duration:100})
}

function mousePanel(src, panel, initFunction) {
    if (initFunction != '') {
        $(src).mouseover(function() { window[initFunction]() })
    }
    else {
    	$(src).mouseover(function() { $(panel).fadeIn('fast') })
    }
    $(src).mouseout(function() { closeInit(panel) })
    $(panel).mouseover(function() { clearTimeout(closeTimer) })
    $(panel).mouseout(function() { closeInit(panel) })
}

function openDialog(element) {
    //this is the general dialog handler.
    //pass the element name and this will copy
    //the contents of the element to the doalog box


    $('#overlayGreen').css('height', $('#root').height() + 5 + 'px')
    $('#overlayGreen').show()
    $('#dialog').html($(element).html())
    centerMe('#dialog')
    $('#dialog').show();
}

function closeDialog() {
    $('#overlayGreen').hide()
    $('#dialog').hide()
    $('#dialog').html('')
}

function centerMe(element) {
    //pass element name to be centered on screen
    var pWidth = $(window).width();
    var pTop = $(window).scrollTop()
    var eWidth = $(element).width()
    var height = $(element).height()
    $(element).css('top', pTop + 100 + 'px')
    $(element).css('left', parseInt((pWidth / 2) - (eWidth / 2)) + 'px')
}



