jQuery.dialog = {
	open: function (message, callback, custom_options) {
			jQuery(document.body).append('<div id="jquery_dialog" title="InterAdmin" style="display:none"><div id="jquery_dialog_txt"></div></div>');
			// Exemplo de mudança do Title $("#jquery_dialog").attr( 'title', "New Title" );
			jQuery.dialog.callback = callback;
			jQuery.dialog.val = null;
			message = message.replace('\r\n', '<br />');
			message = message.replace('\n', '<br />');
			jQuery("#jquery_dialog_txt").html(message);
			jQuery("#jquery_dialog").show();
			dialog_options = {
				modal: true,
				height: 85 + Math.ceil(message.length / 40) * 15,
				resizable: false,
				draggable: false,
				overlay: { opacity: 0.4, background: "black" },
				close: function() {
					if (jQuery.isFunction(jQuery.dialog.callback)) setTimeout("jQuery.dialog.callback(" + jQuery.dialog.val + ")", 10);
					jQuery(this).dialog("destroy");
					jQuery("#jquery_dialog").remove();
				},
				buttons: {
					"OK": function() {
						jQuery(this).dialog("close");
					}
				}
			}
		
			for(key in custom_options) dialog_options[key] = custom_options[key];
			jQuery("#jquery_dialog").dialog(dialog_options);
			
			frame = jQuery("#jquery_dialog").parent().parent();
			jQuery("div.ui-dialog-buttonpane button:contains('OK')", frame).addClass("ok");
			jQuery("div.ui-dialog-buttonpane button:contains('Cancel')", frame).addClass("cancel");
			jQuery("#jquery_dialog").keypress(function (e) {
				if (e.which == 13) jQuery("div.ui-dialog-buttonpane button.ok").click();
		    });
		},
	callback: null,
	val: null
}

jQuery.alert = function (message) {
	jQuery.dialog.open(message, null, null);
	jQuery("#jquery_dialog_txt").before('<img src="/_default/img/dialog/alert.gif" alt="" align="left" style="margin-right:10px"/>');
	jQuery("div.ui-dialog-buttonpane button.ok").focus();
}

jQuery.confirm = function (message, callback) {
	jQuery.dialog.open(message, callback, {
		buttons: {
			"OK": function() {
				jQuery.dialog.val = true;
				jQuery(this).dialog("close");
			},
			"Cancel": function() {
				jQuery.dialog.val = false;
				jQuery(this).dialog("close");
			}
		}
	});
	jQuery("div.ui-dialog-buttonpane button.ok").focus();
}

jQuery.prompt = function (message, default_val, callback) {
	jQuery.dialog.open(message, callback, {
		buttons: {
			"OK": function() {
				jQuery.dialog.val = "'" + jQuery("#jquery_dialog_input input").val() + "'";
				jQuery(this).dialog("close");
			},
			"Cancel": function() {
				jQuery(this).dialog("close");
			}
		}
	});
	jQuery("#jquery_dialog").append('<div id="jquery_dialog_input"><input type="text" value="' + default_val + '"/></div>');
	jQuery("#jquery_dialog_input input").focus();
}


/*
 * Copyright (c) 2008 Paulo Rodrigues (jp7.com.br)
 * Colaborattor: João Pedro Barbosa  
 * Version: 1.0.5 - Rewritten by Carlos Rodrigues as a prototype
 * Release: 2008-08-15 
 */

jQuery.mediabox = function(boxes, controllers){
	this.boxes = boxes;
	this.controllers = controllers;
	this.mediaboxId = jQuery.mediabox.instances.length;
	jQuery.mediabox.instances[this.mediaboxId] = this;
};
jQuery.mediabox.instances = []; 
jQuery.mediabox.prototype = {
	/*
	 * array Array of objects (divs) with the boxes
	 */
	boxes: null,
	/*
	 * array Array of objects (divs) with the controllers
	 */
	controllers:  null,
	/*
	 * int Interval between each rotation
	 */
	interval: 15000,
	/*
	 * bool If FALSE the Next and Previous buttons won´t change the current item if its the last or the first.
	 */
	looping: true,
	/*
	 * int Index of the current item
	 */
	selected: 0,
	change: function(number, fromrotate) {
		this.selected = number;
		this.boxes.hide();
		jQuery(this.boxes[number - 1]).fadeIn();
		this.controllers.removeClass("pointer_selected");
		jQuery(this.controllers[number - 1]).addClass("pointer_selected");
		if (this.timeout && !fromrotate) {
			this.stop();
			this.rotate();
		}
	},
	rotate: function(){
		this.next(true);
		this.timeout = setTimeout('jQuery.mediabox.instances[' + this.mediaboxId + '].rotate()', this.interval);
	},
	stop: function(){
		this.timeout = clearTimeout(this.timeout);
	},
	next: function(fromrotate) {
		number = this.selected + 1;
		if (number > this.boxes.length) { 
			if (this.looping) number = 1;
			else return false;
		}
		this.change(number, fromrotate);	
	},
	previous: function() {
		number = this.selected - 1;
		if (number  < 1) { 
			if (this.looping) number = this.boxes.length;
			else return false;
		}
		this.change(number);	
	}
}
