
$(document).ready(function(){$('a[rel*=modal]').click(function(){$.modal(this);return false;});});(function($){$.modal=function(obj){if($(obj).length==1){var url=$(obj).attr("href");$.modal.loading();$.getJSON(url,function(data){$.modal.reveal(data);});}}
$.extend($.modal,{settings:{loading:'<div class="loading">Loading...</div>',content:'<div class="header"><h2></h2></div><div class="content"></div><div class="footer"><div class="buttons top"></div></div>'},loading:function(){if($('#modal').length==0){$('body').append('<div id="modal"></div>');$('body').append('<div id="overlay"></div>');$('#overlay').height($(document).height());}
$('#modal').html($.modal.settings.loading);$('#modal').width(200);$.modal.center();$('#overlay').bind('click',$.modal.close);},reveal:function(data){if($('#modal').length==0){$.modal.loading();}
if(data){$('#modal').removeClass('success').removeClass('notice').removeClass('error').removeClass('download');$('#modal').addClass(data.type);$('#modal').html($.modal.settings.content);var instruction=(data.instruction!=undefined)?data.instruction:'';$('#modal .header').html('<h2>'+data.title+' <span>'+instruction+'</span></h2>');$('#modal .content').html('').append(data.content);if(data.buttons!=undefined){for(var x=0;x<data.buttons.length;x++)
{$('#modal .footer .buttons').append('<a onClick="'+data.buttons[x].action+'" class="button"><span id="'+data.buttons[x].id+'">'+data.buttons[x].text+'</span></a>');}}else{$('#modal .footer .buttons').append('<a onClick="$.modal.close()" class="button"><span>Close</span></a>');}
$('#modal .footer').append('<div class="clear"></div>');if(data.width){$('#modal').width(data.width);}else{$('#modal').width(400);}
$.modal.center();$('#modal a[rel*=modal]').click(function(){$.modal(this);return false;});if(data.load){eval(data.load);}}},close:function(){$('#modal').hide(1,function(){$('#overlay').hide();});},center:function(){$('#modal').css({top:10,left:($('body').width()/2)-($('#modal').width()/2)});$('#overlay').show(1).fadeTo(1,0.5,function(){$('#modal').show();});}})})(jQuery);