/*  jQuery dialog v1.0
    Created by Kaitlyn McLachlan
    http://www.clearskymedia.ca
*/

$(document).ready(function() {
    $.ajaxDialog = function(url, o) {
        $('<img src="/images/indicators/circle_ball.gif" width="16" height="16" alt="" />').dialog(o);
        
        $('<div id="temp"></div>').load(url, function(response) {
            $('#dialog-content').html(response);
        });
    }
    
    $.fn.dialog = function(o) {
        var options = {
			width        : 300,
			height       : 300,
			modal        : true,
			position     : 'center',
			closable     : true,
			title        : null
		};
		var o = o || {}; $.extend(options, o); //Extend and copy options
		
		var content = $(this);
		
        var title = (options.title != null) ? options.title : (content.attr('title')) ? content.attr('title') : '';
        if (title != '' || options.closable) {
            $('#dialog-title').html('<span id="dialog-close"><a href="#" onclick="return $.dialogClose()">X</a></span>' + title)
        } else {
            $('#dialog-title').hide();
        }
        $('#dialog-content').html($(this).show());
        
        var doc = $(document);
        var wnd = $(window);
        var top = left = 0;
        
        if (options.modal) {
            $('#dialog-overlay').height(doc.height()).show();
        }
        
        switch (options.position) {
            case 'tl': // top left
                top = '50px';
                left = '50px';
            break;
            
            case 'tc': // top center
                top = '50px';
                left = (doc.width() / 2) - (options.width / 2);
            break;
            
            case 'tr': // top right
                top = '50px';
                left = doc.width() - options.width - 50;
            break;
            
            case 'bl': // bottom left
                top = wnd.height() - options.height - 50;
                left = '50px';
            break;
            
            case 'bc': // bottom center
                top = wnd.height() - options.height - 50;
                left = (doc.width() / 2) - (options.width / 2);
            break;
            
            case 'br': // bottom right
                top = wnd.height() - options.height - 50;
                left = doc.width() - options.width - 50;
            break;
            
            case 'center':
            default:
                top = (wnd.height() / 2) - (options.height / 2);
                left = (doc.width() / 2) - (options.width / 2);
            break;
        }
        
        $('#dialog').css({
            width : options.width + 'px',
            height : options.height + 'px',
            top : top,
            left : left
		}).removeClass().addClass(options.position).show();
    }
    
    $.dialogClose = function() {
        $('#dialog-overlay, #dialog').hide();
        $('#dialog-holder').append($('#dialog-content').children());
        return false;
    }
    
    $('body').append('<div id="dialog-overlay" style="display:none"></div><div id="dialog" style="display:none"><div id="dialog-title"></div><div id="dialog-content"></div></div><div id="dialog-holder"></div>');
});