/*
# ShoutCloud - Flexible PHP Shoutbox
# File: ShoutCloud.js
# Author: Big Ross Labs
# Version: 1.0.2
# Date: 9/20/2010
# Copyright (c) 2010 Big Ross Labs. All Rights Reserved.
# Part of the ShoutCloud package sold only on codecanyon.net!
*/
$(document).ready(function() {
	$('#ShoutCloud-Container').ShoutCloud({
		refreshTime: 4000,
		shoutcloudFile: 'shoutcloud.php',
	  	nameText: 'Your Name',
	  	messageText: 'Message'	
	});
});

(function(d){d.fn.ShoutCloud=function(f){f=d.extend({refreshTime:4000,shoutcloudFile:"shoutcloud.php",nameText:"Your Name",messageText:"Message"},f);d(this).each(function(){var l=d(this);var g=f;var o=setInterval(function(){c(g,"ajax")},g.refreshTime);var p=d("#ShoutCloud-MsgBox",l);var n=d("#ShoutCloud-User",l);var j=d("#ShoutCloud-Color",l);var k=d(".ShoutCloud-Swatches",l);var h=d("#ShoutCloud-Msg",l);var m=d("#ShoutCloud-Shout",l);var i=null;a(p);if(n.val()==""){n.val(g.nameText)}h.val(g.messageText);h.bind("change keyup",function(){if(d(this).val()!==g.messageText){var q=d(this).val().length;d("div#ShoutCloud-Counter").html(q+"/500 characters")}});n.focus(function(){if(d(this).val()==""||d(this).val()==g.nameText){d(this).val("")}}).blur(function(){if(d(this).val()==""||d(this).val()==g.nameText||d(this).val()==" "){d(this).val(g.nameText)}});h.focus(function(){if(d(this).val()==""||d(this).val()==g.messageText){d(this).val("")}}).blur(function(){if(d(this).val()==""||d(this).val()==g.messageText||d(this).val()==" "){d(this).val(g.messageText)}});n.keypress(function(q){code=(q.keyCode?q.keyCode:q.which);if(code==13){h.focus()}});h.keypress(function(q){code=(q.keyCode?q.keyCode:q.which);if(code==13){m.trigger("click")}});d("#ShoutCloud-Pass",l).live("keypress",function(q){code=(q.keyCode?q.keyCode:q.which);if(code==13){d("#ShoutCloud-Admin-Login",l).trigger("click")}});m.live("click",function(s){s.preventDefault();var t=n.val();var q=h.val();if(t==""||t==g.nameText){n.focus();e("Please enter your name!");return false}if(q==""||q==g.messageText){shoutcloud_msg.focus();e("Please enter a message!");return false}if(q=="!admin"){d("#ShoutCloud-InputBox",l).append('<div id="ShoutCloud-Login"><div id="ShoutCloud-Input-Wrapper" class="margintop"><strong>Password</strong><br /><input type="password" name="ShoutCloud-Pass" id="ShoutCloud-Pass" /></div><input type="button" name="ShoutCloud-Admin-Login" id="ShoutCloud-Admin-Login" value="Login" /></div><div class="clear"></div>');h.val(g.messageText);d("#ShoutCloud-Pass",l).focus();return false}else{if(q=="!help"){p.append('<div id="ShoutCloud-Help" class="shout-system-msg"><strong id="shouthelp">!help</strong><br /><span class="title">Bold:</span><span class="contents">[your text] produces <b>your text</b></span><div class="clear"></div><span class="title">Italics:</span><span class="contents">{your text} produces <i>your text</i></span><div class="clear"></div><span class="title">Underline:</span><span class="contents">_your text_ produces <u>your text</u></span><div class="clear"></div><span class="title">Links:</span><span class="contents">Just enter a url</span><div class="clear"></div><span class="title">Reply:</span><span class="contents">Click on a user\'s name to reply</span><div class="clear"></div><span class="title">Multi-Lines:</span><span class="contents">Put 2 spaces in-between words</span><div class="clear"></div></div>');a(p);h.val(g.messageText);return false}else{if(h.val().length>500){e("Please limit your message to 500 characters.");return false}else{clearInterval(o);var r=k.attr("id");d.post(g.shoutcloudFile,{sc_com:"post",name:t,color:r,msg:q},function(u){if(u.error){h.focus();e(u.error)}else{if(u.status=="posted"){h.val("").focus();c(g,"ajax")}}},"json");o=setInterval(function(){c(g,"ajax")},g.refreshTime)}}}});j.live("click",function(){if(k.is(":visible")){k.slideUp("normal")}else{var q=["Pink","Purple","Blue","LightBlue","Teal","Green","DarkGreen","Lime","Yellow","Orange","Red","Default"];var r;k.html("");var s=k.attr("id");for(r in q){if(s==q[r]){k.append('<span class="ShoutCloud-Swatch ShoutCloud-Swatch-'+q[r]+' sel" title="'+q[r]+'">')}else{k.append('<span class="ShoutCloud-Swatch ShoutCloud-Swatch-'+q[r]+'" title="'+q[r]+'">')}}k.slideDown("normal")}});d("span.ShoutCloud-Swatch",l).live("click",function(){d("span.ShoutCloud-Swatch",l).each(function(){d(this).removeClass("sel")});d(this).addClass("sel");k.attr("id",d(this).attr("title"))});d("img.ShoutCloud-Smilie",l).live("click",function(){var q=d(this).attr("id");if(h.val()==g.messageText){h.val(q+" ").focus()}else{h.val(h.val()+" "+q+" ").focus()}});d(".ShoutCloud-Reply",l).live("click",function(q){var r=d(this).attr("id");if(h.val()==g.messageText){h.val("[@"+r+"] - ").focus()}else{h.val(h.val()+" [@"+r+"] - ").focus()}});d(".ShoutCloud-Admin-Reply",l).live("click",function(r){var q=d(this).parent("span.shout-user-opts").parent();q=q.metadata();if(h.val()==g.messageText){h.val("[@"+q.name+"] - ").focus()}else{h.val(h.val()+" [@"+q.name+"] - ").focus()}});d("span.shout-user-opts .shout-del",l).live("click",function(s){var r=d(this).parent("span.shout-user-opts").parent(".ShoutCloud-Admin-User-Controls").parent("div.shout-msg").attr("id");var q=confirm("Are you sure you want to delete this post?");if(q){d.post(g.shoutcloudFile,{sc_com:"delete",sid:r},function(t){if(t.error){e(t.error)}else{if(t.status=="deleted"){d("div.shout-msg[id='"+r+"']",l).fadeOut("normal");alert("Successfully deleted the requested post!");c(g,"admin")}}},"json")}});d(".shout-admin-user",l).live("click",function(q){d(".ShoutCloud-Admin-User-Controls").fadeOut("fast");d(this).parent("div.shout-msg").find(".ShoutCloud-Admin-User-Controls").fadeIn("fast")});d(".ShoutCloud-Admin-User-Controls").hover(function(){if(i!==null){clearTimeout(i)}},function(){i=setTimeout(function(){d(".ShoutCloud-Admin-User-Controls").fadeOut("fast")},1000)});d("#ShoutCloud-Admin-Login",l).live("click",function(r){r.preventDefault();var s=d("#ShoutCloud-Pass",l).val();var q=n.val();if(s==""){d("#ShoutCloud-Pass",l).focus();e("Please enter the password!")}else{d.post(g.shoutcloudFile,{sc_com:"login",pass:s,name:q},function(t){if(t.error){e(t.error);d("#ShoutCloud-Pass",l).focus()}else{if(t.status=="loggedin"){d("#ShoutCloud-Login",l).slideUp("fast");if(!d("#ShoutCloud-Admin-Panel").is(":visible")){d("#ShoutCloud-InputBox",l).after('<div id="ShoutCloud-Admin-Panel"><span class="admin-btn shout-on" id="ShoutCloud-InputsPage">Shout</span><span class="admin-btn" id="ShoutCloud-BanList">Bans</span><span class="admin-btn" id="ShoutCloud-ClearChat">Clear All</span><span class="admin-btn" id="ShoutCloud-Admin-Logout">Logout</span></div><div class="clear"></div>');c(g,"admin")}}}},"json")}});d("#ShoutCloud-Admin-Logout",l).live("click",function(q){q.preventDefault();d.post(g.shoutcloudFile,{sc_com:"logout"},function(r){if(r.status=="loggedout"){d("#ShoutCloud-Admin-Panel, span.shout-ban",l).remove()}window.location.reload()},"json")});d("#ShoutCloud-InputsPage",l).live("click",function(){d("#ShoutCloud-Admin-Panel span.admin-btn",l).each(function(){d(this).removeClass("shout-on")});d(this).addClass("shout-on");d("#ShoutCloud-Wrapper-Admin",l).hide();d("#ShoutCloud-Wrapper",l).show()});d("#ShoutCloud-BanList",l).live("click",function(){d("#ShoutCloud-Admin-Panel span.admin-btn",l).each(function(){d(this).removeClass("shout-on")});d(this).addClass("shout-on");d("#ShoutCloud-Wrapper, #ShoutCloud-Wrapper-Admin",l).hide();d.post(g.shoutcloudFile,{display:"banlist"},function(q){if(q.error){e(q.error)}else{d("#ShoutCloud-Error",l).after(q.content)}},"json")});d("#ShoutCloud-ClearChat",l).live("click",function(){d("#ShoutCloud-Admin-Panel span.admin-btn",l).each(function(){d(this).removeClass("shout-on")});d(this).addClass("shout-on");d("#ShoutCloud-Wrapper, #ShoutCloud-Wrapper-Admin",l).hide();d.post(g.shoutcloudFile,{display:"clear"},function(q){if(q.error){e(q.error)}else{d("#ShoutCloud-Error",l).after(q.content)}},"json")});d("#ShoutCloud-DoClear",l).live("click",function(){d.post(g.shoutcloudFile,{sc_com:"clear"},function(q){if(q.error){e(q.error)}else{if(q.status=="cleared"){alert("The shoutbox has been cleared!");c(g,"refresh")}}},"json")});d("span.shout-ban",l).live("click",function(){var s=d(this).attr("id");var r=d(this).parent("span.shout-ban-opts").parent();r=r.metadata();var q=confirm("Are you sure you want to ban "+r.name+"?");if(q){d.post(g.shoutcloudFile,{sc_com:"ban-user",user:r.name,ip:r.ip,expire:s},function(t){if(t.status=="banned"){alert(r.name+" has been successfully banned!")}else{e("Unable to ban "+r.name+" at this time. Please try again.")}},"json")}});d(".ShoutCloud-BannedUser div.ShoutCloud-UnBan",l).live("click",function(){var q=d(this).attr("id");var r=confirm("Remove this user from the Ban List?");if(r){d.post(g.shoutcloudFile,{sc_com:"unban-user",ip:q},function(s){if(s.status=="removed"){alert("User has been removed from the Ban List");d(".ShoutCloud-BannedUser[id='"+q+"']",l).fadeOut("normal")}else{if(s.error){e(s.error)}else{e("Unable to remove the ban at this time. Please try again.")}}},"json")}})})};function a(f){f.animate({scrollTop:f.attr("scrollHeight")},500)}function c(j,i){var f=d("#ShoutCloud-MsgBox");var h=d("div.shout-msg");var g=h.last().attr("id");if(i=="admin"){g="-1"}if(i=="refresh"){i="ajax";g="-1";d("div.shout-msg[id!='shoutid-0']").each(function(){d(this).fadeOut("fast")})}b();d.post(j.shoutcloudFile,{sc_com:i,last:g},function(l){if(l&&l.msgs){if(i=="admin"){f.empty()}f.append(l.msgs);b();if(h.size()>50){var m=h.size()-50;var k=0;while(m>=k){h.first().remove();k++}}f.animate({scrollTop:f.attr("scrollHeight")},500)}},"json")}function b(){var f={};d("div.shout-msg").each(function(){var g=d(this).attr("id");if(f[g]){d(this).fadeOut("fast")}else{f[g]=true}})}function e(f){d("#ShoutCloud-Error").html("<strong>Error!</strong>"+f).stop().slideDown("fast").delay(4000).slideUp("fast")}})(jQuery);(function($){$.extend({metadata:{defaults:{type:"attr",name:"data",cre:/({.*})/,single:"metadata"},setType:function(type,name){this.defaults.type=type;this.defaults.name=name},get:function(elem,opts){var settings=$.extend({},this.defaults,opts);if(!settings.single.length){settings.single="metadata"}var data=$.data(elem,settings.single);if(data){return data}data="{}";if(settings.type=="class"){var m=settings.cre.exec(elem.className);if(m){data=m[1]}}else{if(settings.type=="elem"){if(!elem.getElementsByTagName){return}var e=elem.getElementsByTagName(settings.name);if(e.length){data=$.trim(e[0].innerHTML)}}else{if(elem.getAttribute!=undefined){var attr=elem.getAttribute(settings.name);if(attr){data=attr}}}}if(data.indexOf("{")<0){data="{"+data+"}"}data=eval("("+data+")");$.data(elem,settings.single,data);return data}}});$.fn.metadata=function(opts){return $.metadata.get(this[0],opts)}})(jQuery);
