// licensing information: http://ukcom.org/l/j/licenseing.txt
(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)<M.distance){break}L.target=M.target;J=C(L,"dragstart",K);if(J!==false){F.dragging=K;F.proxy=L.dragProxy=E(J||K)[0]}case"mousemove":if(F.dragging){J=C(L,"drag",K);if(B.drop){B.drop.allowed=(J!==false);B.drop.handler(L)}if(J!==false){break}L.type="mouseup"}case"mouseup":A.remove(document,"mousemove mouseup",H);if(F.dragging){if(B.drop){B.drop.handler(L)}C(L,"dragend",K)}G(K,true);F.dragging=F.proxy=M.elem=false;break}return true}function C(M,K,L){M.type=K;var J=E.event.handle.call(L,M);return J===false?false:J||M.result}function I(J){return Math.pow(J,2)}function D(){return(F.dragging===false)}function G(K,J){if(!K){return }K.unselectable=J?"off":"on";K.onselectstart=function(){return J};if(K.style){K.style.MozUserSelect=J?"":"none"}}})(jQuery);

jQuery.cookie=function(_1,_2,_3){ if(typeof _2!="undefined"||(_1&&typeof _1!="string")){ if(typeof _1=="string"){ _3=_3||{}; if(_2===null){ _2=""; _3.expires=-1; } var _4=""; if(_3.expires&&(typeof _3.expires=="number"||_3.expires.toUTCString)){ var _5; if(typeof _3.expires=="number"){ _5=new Date(); _5.setTime(_5.getTime()+(_3.expires*24*60*60*1000)); }else{ _5=_3.expires; } _4="; expires="+_5.toUTCString(); } var _6=_3.path?"; path="+(_3.path):""; var _7=_3.domain?"; domain="+(_3.domain):""; var _8=_3.secure?"; secure":""; document.cookie=_1+"="+encodeURIComponent(_2)+_4+_6+_7+_8; }else{ for(var n in _1){ jQuery.cookie(n,_1[n],_2||_3); } } }else{ var _a={}; if(document.cookie){ var _b=document.cookie.split(";"); for(var i=0;i<_b.length;i++){ var _d=jQuery.trim(_b[i]); if(!_1){ var _e=_d.indexOf("="); _a[_d.substr(0,_e)]=decodeURIComponent(_d.substr(_e+1)); }else{ if(_d.substr(0,_1.length+1)==(_1+"=")){ _a=decodeURIComponent(_d.substr(_1.length+1)); break; } } } } return _a; } };

(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);

(function($){
$.populate = function(data, selector){
$.each(data, function(name, value){
var type = typeof value,
element = $(selector+' [name='+name+'],'+selector+' [name='+name+'\\[\\]]'),
check = element.is(':radio,:checkbox');
if (type === 'boolean' && check)
element.attr({checked: value ? 'checked' : null});
else if (type === 'object' && !$.isArray(value))
for (var key in value)
arguments.callee(name+'\\['+key+'\\]', value[key]);// very cool!
else
element.val(check ? $.makeArray(value).map(function(key){return key.toString();}) : value);
});
};
$.fn.extend({
populate: function(data, options){
if (!data)
return this.reset();
var selector = this.selector;
if (typeof data === 'string')
$.getJSON(data, options, function(data){ $.populate(data, selector); });
else if (typeof data === 'object')
$.populate(data, selector);
return this;
},
reset: function(){
return this.filter('form').each(function(){this.reset();}).end();
},
smartForm:function(){$(":input",this).each(function(){var a=this,b=$(this);if(a.title!=""){if(a.attributes&&a.attributes.value)a.def=a.attributes.value.value;else a.def=b.attr("value");(b.val()==""||b.val()==a.def)&&b.css({color:"#999"});b.blur(function(){var a=$(this);if(a.val()==""){a.val(this.def);a.css({color:"#999"})}});b.focus(function(){var a=$(this);a.css({color:"#000"});a.val()==this.def&&a.val("")})}});$(this).submit(function(){var c=this,b=$(this),a="";$(":input",c).each(function(){var c=this,b=$(this);if(b.prop("title")&&(b.val()==c.def||b.val()=="")){a==""&&c.focus();a+=b.prop("title")+"\n"}});if(a!=""){alert(a);return false}if(b.attr("ajax")!=undefined){$.post(b.attr("action")+"&method=ajax",b.serialize(),function(a){$(".ajax_response",c).html(a)});return false}})},
});
})(jQuery);

$.replaceAssoc=function(b,a){
return b.replace(/{[a-z0-9_]+}/g,function(b){var d=b.substr(1,b.length-2),c=a[d];
	return c==undefined?b:a[b]==undefined?c:a[b].replace(b,c)})};

$.loadTemplate=function(c,a,b){$.get("/l/t/jquery/"+c+".tpl?"+Math.random(),function(d){
if(b!=undefined)d=$.replaceAssoc(d,b);if(a)$(a).innerHTML=d;else $("body").append(d);
$("#_"+c+" script").each(function(){$.globalEval($(this).html());});
})};
$.fillTemplate=function(t,e,d){ //t=template text e=element to fill d=data replacements
	var r="";
	if (typeof(d)!="object") d=[d];
	if (typeof(e)=="string") e=$(e)[0];
	for (var i=d.length; i-->0;1) r=$.replaceAssoc(t,d[i])+r;
	e.innerHTML=r;
}
$.ffSelect=function(e,i,h,s,r){ // e=event i=input o=other to hide
	e=e.currentTarget;
	if (r) $(e).unbind();
	$(e.parentNode.children).hide("slow");
	$(h).hide("slow");
	$(s).show("slow");
	return $(i).val($(e).show("slow").attr("value")).val();
}


