$(document).ready(function() {
	$('a.btn-largeimg, a.link-largeimg').click(function(event) {
		event.preventDefault();
		var myUrl = $(this).attr("href");
		var myTitle = $(this).attr("title");
		//alert(myUrl);
		xtOpenDialog(myUrl, 760, 600, myTitle); return false;
	});
	
	/*
	$('.btn-callback').click(function(event) {
			event.preventDefault();
			var myUrl = $(this).attr("href") + '/is_dialog/1';
			//alert(myUrl);
			xtOpenDialog(myUrl, 760, 600, "Call Back Request"); return false;
	});
	*/
});



/**
 * Opens inline editing dialog and loads the given URL into it.
 * 
 * @param url $url 
 * @param width $width 
 * @param height $height 
 * @param title $title 
 * @access public
 * @return void
 */
function xtOpenDialog(url, width, height, title) {
    width = (width ? width : 'auto');
    height = (height ? height : 'auto');
    title = (title ? title : '');

    // insert element to be used as holder for cms edit window
    if ($('#xt-dialog').size() == 0) {
        $('body').append('\n<div id="xt-dialog" title="'+title+'"></div>\n');
    }

    // destroy any existing dialog first
    $('#xt-dialog').dialog('destroy');

    // set dialog title
    $('#xt-dialog').attr('title', title);

    // show dialog for editing
    $('#xt-dialog').dialog({
        width: width,
        height: height,
        height: (height == 'max' ? ($(window).height() - 10) : height),
        autoOpen: false,
        closeOnEscape: false,
        modal: true,
        close: function(event, ui) { 
            $('#xt-dialog-iframe-content').remove();
            $('#xt-dialog-iframe').html();
            _xtHasEditorDialog = false;
            return true;
        }
    });
    $('#xt-dialog').dialog('open');

    // load editor url in the iframe
    $('#xt-dialog').html('<iframe id="xt-dialog-iframe" name="xt-dialog-iframe" src="'+url+'" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto"></iframe>\n');

    _xtHasEditorDialog = true;
}

/**
 * Shows UI dialog alert window with the given message.
 * 
 * @param msg $msg 
 * @access public
 * @return void
 */
function sysShowAlert(msg, actionJS, dialogTitle) {

    // insert dialog element used as holder for cms messages
    if ($('#sys-message').size() == 0) {
        $('body').append('<div id="sys-message" title="System message"></div>\n');
    }

    // destroy any existing dialog first, we don't do this on close event so that we can keep nice closing effects
    $('#sys-message').dialog('destroy');
    
   
    // show status message 
    $('#sys-message').html(msg);
    $('#sys-message').dialog({
        autoOpen: false,
        closeOnEscape: false,
        show: 'blind',
        hide: 'blind',
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
                
                // execute optional javascript code after OK has been pressed
                if (actionJS) {
                    eval(actionJS);
                }
            }
        }
    });
    if (dialogTitle) {
    	$('#sys-message').dialog('option', 'title', dialogTitle);
    }
    $('#sys-message').dialog('open');
}