/*jLog jQuery Plugin
  Copyright 2010 Randy Brandt
  Version: 0.7 13-Oct-2010
  Requires jQuery v1.4.0 or later; http://jquery.com
  Examples and docs:
    http://www.tiredjake.com/index.php?p=jLog
  Licensed under the MIT license:
  http://www.opensource.org/licenses/mit-license.php
  Copyright (c) 2010 Randy Brandt, tiredjake.com
*/
(function($){var defaults={bgChange:true,bgColors:["fuchsia","lime","yellow","aqua"],bgReset:true,dest:null,fName:"jLog",logPHP:"/~lib/jLog.php",outline:true,tLen:40,wantHTML:true,wantTime:false};var opt=defaults;var iColor=0;var bColor=2;var jOL=[];var jLog_hit1={outline:'2px dotted fuchsia'};var jLog_hit2={outline:'2px dotted lime'};var jLog_hit3={outline:'2px dotted yellow'};var jLog_hit4={outline:'2px dotted aqua'};jOL[0]=jLog_hit1;jOL[1]=jLog_hit2;jOL[2]=jLog_hit3;jOL[3]=jLog_hit4;$.fn.jLog=function(opshuns){opt=$.extend(defaults,opshuns);dest=opt.dest;console.log(opt);work="$('"+this.selector+"').jLog(";if(opshuns){work+=Stringify(opshuns)+");";}else{work+=");";}
if(dest=="file"){fWrite(work,"new");}else{$.log(work,"war",dest);}
return this.each(function(){jayLog(this,dest);});};function Stringify(jsonData){var strJsonData='{';var itemCount=0;for(var item in jsonData){if(itemCount>0){strJsonData+=', ';}
strJsonData+='"'+item+'":"'+jsonData[item]+'"';itemCount++;}
strJsonData+='}';return strJsonData;}
function jayLog(e,dest){var tn=e.tagName.toLowerCase();var id=" #"+e.id;var cn=" ."+e.className;var parObj=$(e).parent();p=" #parent:"+$(parObj).attr("id");var ofs=$(e).offset();var x=" x:"+ofs.left;var y=" y:"+ofs.top;var w=" w:"+$(e).css("width");var z=" z:"+$(e).css("z-index");var pos=" pos:"+$(e).css("position");var zp=" zp:"+$(parObj).css("z-index");var t=$(e).text().substr(0,20);txt=" txt:"+t;work=tn+id+cn+x+y+w+z+pos+txt+p;if(opt.wantHTML){$.log(work,"group",dest);sHTML=$('<div>').append($(e).clone()).html();$.log("html","group-",dest);$.log(sHTML,"gre",dest);}else{$.log(work,"",dest);}
$.log("","gre",dest);if(opt.bgChange){if($(e).css("background-color")!=opt.bgColors[iColor]){$(e).css("background-color",opt.bgColors[iColor]);}else{$(e).css("background-color","");}
var bg=" bg:"+opt.bgColors[iColor];iColor++;if(iColor>=opt.bgColors.length){iColor=0;}}else{var bg=" bg:"+$(e).css("background-color");}
var fg=" fg:"+$(e).css("color");if(opt.outline){$(e).css(jOL[bColor]);bColor++;if(bColor>=opt.bgColors.length){bColor=0;}}}
jQuery.log=function(msg,type,dest,pause){t=getTheTime();if(!dest&&window.console&&console.log){var typ;if(type){type=type.toLowerCase();typ=type.substr(0,3);}
switch(typ){case'war':console.warn(msg);break;case'err':console.error(msg);break;case'inf':console.info(msg);break;case'tra':console.trace(msg);break;case'tim':if(console.time){console.time(msg);}
break;case'ten':if(console.timeEnd){console.timeEnd(msg);}
break;case'tab':if(console.table){console.group("table");console.table(msg);console.groupEnd("table");}else{console.log(msg);}
break;case'clr':if(console.clear){console.clear();}
console.log(msg);break;case'gro':if(console.group){if(type=='group-'){console.groupCollapsed(msg);}else{console.group(msg);}}else{console.log(msg);}
if(console.time){console.time(msg);}
break;case'gre':if(msg){console.log(msg);}
if(console.groupEnd){console.groupEnd();}
break;default:if(opt.wantTime&&(typeof(msg)!="object")){msg="{"+t+"} "+msg;}
console.log(msg);}
if(pause){alert(pause);}}else if(dest=="file"){if(opt.wantTime){msg="{"+t+"} "+msg;}
fWrite(msg);}else{if(opt.wantTime&&(typeof(msg)!="object")){msg="{"+t+"} "+msg;}
msg+="<br>";$(dest).append(msg);}
return;}
function fWrite(m,init){if(init){t="_"+getTheTime("_");t="";init=t+".txt:init="+init;}else{init=".txt:init=x";}
jLogParms="jlog="+opt.fName+init+":msg="+m;console.log(jLogParms);$.ajax({type:"POST",data:jLogParms,url:opt.logPHP,error:function(data){console.error(data);},success:function(data){if(data.substr(0,4)!="~OK:"){console.error(data);}else{}}});}
function getTheTime(div){if(!div){div=":"};var d=new Date();var h=d.getHours();var m=d.getMinutes()+"";if(m.length==1){m="0"+m};var s=d.getSeconds()+"";if(s.length==1){s="0"+s};var t=h+div+m+div+s;return t;}})(jQuery);
