/*
 jquery.jqDock.js v1.3 
*/
(function(k,q){if(!k.jqDock){var o=["Top","Right","Bottom","Left"],H={src:"Source",altsrc:"AltSource"},w=['<div style="position:relative;padding:0;',"margin:0;border:0 none;background-color:transparent;",'">'],t={v:{wh:"height",xy:1,tl:"top",lead:o[0],trail:o[2],act:"TransInv"},h:{wh:"width",xy:0,tl:"left",lead:o[3],trail:o[1],act:"Trans"}},m=[],A=[0,0],I=function(c){return(c=k(c).attr("alt"))&&c.match(/\.(gif|jpg|jpeg|png)$/i)?c:false},v=function(c){c=parseInt(c,10);return isNaN(c)?0:c},B=function(c){var d=
c.Opts.vh,b=0;if(c=c.Current!==false?c.Elem[c.Current]:0){b=c.Pad[d.lead]+c.Pad[d.trail];b=Math.floor((A[d.xy]-c.Wrap.parent().offset()[d.tl])*(b+c.Initial)/(b+c.Trans))+c.Offset}return b},C=function(c,d,b){var a={},e=t[b.vh].wh;b=t[b.inv].wh;a[e]=d;a[b]=Math.round(d*c[b]/c[e]);return a},x=function(c){var d=c.Opts.labels,b=c.Opts.vh,a={},e;if(d&&c.Current!==false&&/[mc]/.test(d)){d=d.split("");c=c.Elem[c.Current];e=c.Label;if(d[0]=="m")a.top=Math.floor((c[b.inv.act]-e.height-e.heightPad)/2);if(d[1]==
"c")a.left=Math.floor((c[b.act]-e.width-e.widthPad)/2);e.el.css(a)}},D=function(c){for(var d=c.childNodes.length,b;d;){b=c.childNodes[--d];if(b.childNodes&&b.childNodes.length)D(b);else b.nodeType==3&&c.removeChild(b)}},J=function(c,d){var b=c.Opts.labels,a=d.Label,e,g;if(a.txt){a.el.click(function(){d.Img.trigger("click")});if(/[mc]/.test(b)){e={};k.each(o,function(h,i){e[i]=v(a.el.css("padding"+i))});k.each(t,function(h,i){a[i.wh]=a.el[i.wh]();a[i.wh+"Pad"]=e[i.lead]+e[i.trail]})}g=b.split("");
b={top:0,left:0,bottom:"auto",right:"auto"};if(g[0]=="b"){b.top="auto";b.bottom=0}if(g[1]=="r"){b.left="auto";b.right=0}a.el.css(b);e=b=g=null}},u=function(c,d){var b=m[c],a=b.Opts,e=b.Elem.length,g,h;for(d=d||B(b);e;){g=b.Elem[--e];h=Math.abs(d-g.Centre);g.Final=h<a.distance?g[a.vh.wh]-Math.floor((g[a.vh.wh]-g.Initial)*Math.pow(h,a.coefficient)/a.attenuation):g.Initial}},r=function(c,d){var b;if(c.Opts.labels&&c.Current!==false){b=c.Elem[c.Current].Label;b.el[b.txt&&d?"show":"hide"]()}},E=function(c,
d,b,a){c=m[c];var e=c.Elem[d],g=c.Opts,h=g.vh.inv,i=e.Source!=e.AltSource,l,j,f;if(a||e.Trans!=b){l=k.boxModel||g.orient.vh=="v"?0:c.Borders[g.vh.lead]+c.Borders[g.vh.trail];if(i&&!a&&e.Trans==e.Initial)e.Img[0].src=e.AltSource;c.Spread+=b-e.Trans;j=C(e,b,g.orient);f=g.size-j[h.wh];switch(g.align){case "bottom":case "right":j["margin"+h.lead]=f;break;case "middle":case "center":j["margin"+h.lead]=(f+f%2)/2;j["margin"+h.trail]=(f-f%2)/2;break;default:j["margin"+h.trail]=f}if(b!=e.Trans||a&&!d)c.Yard[g.vh.wh](c.Spread+
l);e.Wrap.css(j);c.Yard.css(g.vh.tl,Math.floor(Math.max(0,(c[g.vh.wh]-c.Spread)/2)));c.OnDock&&x(c);e.Trans=b;e.TransInv=j[h.wh];if(i&&!a&&e.Trans==e.Initial)e.Img[0].src=e.Source}},y=function(c,d){var b=m[c],a=b.Opts,e=a.duration+a.step,g=0,h;if(b.Timestamp){e=(new Date).getTime()-b.Timestamp;if(e>=a.duration)b.Timestamp=0}if(e>a.step){for(e=e<a.duration?e/a.duration:0;g<b.Elem.length;){h=b.Elem[g];h=d?e?Math.floor(h.Final-(h.Final-h.Initial)*e):h.Initial:e?Math.floor(h.Initial+(h.Final-h.Initial)*
e):h.Final;E(c,g++,h)}if(b.Spread>b[a.vh.wh]){b.Yard.parent()[a.vh.wh](b.Spread+b.Borders[a.vh.lead]+b.Borders[a.vh.trail]);b[a.vh.wh]=b.Spread}}},F=function(c){var d=m[c],b=d.Elem,a=b.length;if(!d.OnDock){for(;a--&&b[a].Trans<=b[a].Initial;);B(d);if(a<0){for(a=b.length;a--;)b[a].Trans=b[a].Final=b[a].Initial;d.Current=false}else{y(c,true);q.setTimeout(function(){F(c)},d.Opts.step)}}},G=function(c){var d=m[c],b=d.Elem,a=b.length;if(d.OnDock){for(;a--&&b[a].Trans>=b[a].Final;);if(a<0){d.Expanded=true;
r(d,true)}else{u(c);y(c);q.setTimeout(function(){G(c)},d.Opts.step)}}},s=function(c,d,b){var a=m[d],e=a.Elem;switch(c){case "mousemove":if(b!==a.Current){r(a);a.Current=b}x(a);a.Expanded&&r(a,true);if(a.OnDock&&a.Expanded){u(d);y(d)}break;case "mouseenter":a.OnDock=true;a.Current!==false&&a.Current!==b&&r(a);a.Current=b;x(a);a.Expanded&&r(a,true);a.Timestamp=(new Date).getTime();u(d);G(d);break;case "mouseleave":if(a.Inactive){q.clearTimeout(a.Inactive);a.Inactive=null}a.OnDock=a.Expanded=false;r(a);
a.Timestamp=(new Date).getTime();for(c=e.length;c--;)e[c].Final=e[c].Trans;F(d);break;default:}},K=function(c){var d=1*(this.id.match(/^jqDock(\d+)$/)||[0,-1])[1],b=d>=0?m[d]:0,a=b?c.target.className.toString().match(/jqDockMouse(\d+)/):0,e=a?1*a[1]:false;if(b){A=[c.pageX,c.pageY];if(c.type=="mouseleave")b.OnDock&&s(c.type,d,e);else{if(b.Opts.inactivity){if(b.Inactive){q.clearTimeout(b.Inactive);b.Inactive=null}b.Inactive=q.setTimeout(function(){s("mouseleave",d,e)},b.Opts.inactivity)}if(c.type==
"mousemove")if(e===false)b.OnDock&&b.Current!==false&&s("mouseleave",d,e);else!b.OnDock||b.Current===false?s("mouseenter",d,e):s(c.type,d,e);else e!==false&&!b.OnDock&&s(c.type,d,e)}}return false};k.jqDock=function(){return{version:1.3,defaults:{size:48,distance:72,coefficient:1.5,duration:300,align:"bottom",labels:false,source:false,loader:null,inactivity:0,fadeIn:0,step:50},useJqLoader:k.browser.opera||k.browser.safari,initDock:function(c){var d=m[c],b=d.Opts,a=b.vh,e=b.orient,g=d.Borders,h=w.join(""),
i=0,l=0,j,f,n;D(d.Menu);for(k(d.Menu).children().each(function(z,p){var L=d.Elem[z].Wrap=k(p).wrap(h+h+"</div></div>").parent();e.vh=="h"&&L.parent().css("float","left")}).find("img").andSelf().css({position:"relative",padding:0,margin:0,borderWidth:0,borderStyle:"none",verticalAlign:"top",display:"block",width:"100%",height:"100%"});l<d.Elem.length;){f=d.Elem[l++];n=C(f,b.size,{vh:e.inv,inv:e.vh});f.Trans=f.Final=f.Initial=n[a.wh];f.Wrap.css(n);f.Img.attr({alt:""}).parent("a").andSelf().removeAttr("title");
d[a.inv.wh]=Math.max(d[a.inv.wh],b.size+f.Pad[a.inv.lead]+f.Pad[a.inv.trail]);f.Offset=i;f.Centre=i+f.Pad[a.lead]+f.Initial/2;i+=f.Initial+f.Pad[a.lead]+f.Pad[a.trail]}for(l=0;l<d.Elem.length;){f=d.Elem[l++];j=d.Elem.length;n=f.Pad[a.lead]+f.Pad[a.trail];d.Spread+=f.Initial+n;u(c,f.Centre);for(i=0;j;)i+=d.Elem[--j].Final+n;if(i>d[a.wh])d[a.wh]=i;u(c,f.Offset);for(i=0;j<d.Elem.length;)i+=d.Elem[j++].Final+n;if(i>d[a.wh])d[a.wh]=i}for(;l;){f=d.Elem[--l];f.Final=f.Initial}a=[w[0],w[2],'<div id="jqDock',
c,'" class="jqDock" style="position:absolute;top:0;left:0;padding:0;margin:0;overflow:visible;height:',d.height,"px;width:",d.width,'px;"></div></div>'].join("");d.Yard=k(d.Menu).wrapInner(a).find("div.jqDock");k.each(o,function(z,p){g[p]=v(d.Yard.css("border"+p+"Width"))});for(d.Yard.parent().addClass("jqDockWrap").width(d.width+g.Left+g.Right).height(d.height+g.Top+g.Bottom);l<d.Elem.length;){f=d.Elem[l];n=f.Wrap.parent();for(j in f.Pad)f.Pad[j]&&n.css("padding"+j,f.Pad[j]);E(c,l,f.Final,true);
n.add(f.Img).addClass("jqDockMouse"+l);f.Label.el=k('<div class="jqDockLabel jqDockMouse'+l+" jqDockLabel"+(f.Linked?"Link":"Image")+'" style="position:absolute;margin:0px;">'+f.Label.txt+"</div>").hide().appendTo(f.Img.parent());l+=1}c=function(){b.labels&&k.each(d.Elem,function(){J(d,this)});d.Yard.bind("mouseenter mouseleave mousemove",K)};if(b.fadeIn)k(d.Menu).fadeIn(b.fadeIn,c);else{k(d.Menu).show();c()}}}}();k.fn.jqDock=function(c){this.length&&!this.not("img").length?this.each(function(d,b){var a=
b.className.toString().match(/jqDockMouse(\d+)/),e=a?(k(b).parents("div.jqDock").attr("id")||"").match(/^jqDock(\d+)$/):0,g=0,h,i;c=c||{};if(e){e=1*e[1];a=1*a[1];h=m[e].Elem[a];i=h.Trans==h.Initial;k.each(H,function(l,j){var f;if(c[l]){f=(k.isFunction(c[l])?c[l].call(b,h[j],l):c[l]).toString();if(h[j]!==f){h[j]=f;g=(l=="src"?i:!i)?j:g}}});g&&k(b).attr("src",h[g])}}):this.not(".jqDocked").filter(function(){return!k(this).parents(".jqDocked").length&&!k(this).children().not("img").filter(function(){return k(this).filter("a").children("img").parent().children().length!==
1}).length}).hide().addClass("jqDocked").each(function(){var d=m.length,b=function(i){var l=m[i.data.id],j=l.Elem[i.data.idx];j.height=this.height;j.width=this.width;++l.Loaded>=l.Elem.length&&q.setTimeout(function(){k.jqDock.initDock(i.data.id)},0)},a,e,g,h;m[d]={Elem:[],Menu:this,OnDock:false,Expanded:false,Timestamp:0,width:0,height:0,Spread:0,Borders:{},Yard:false,Opts:k.extend({},k.jqDock.defaults,c||{},k.metadata?k(this).metadata():{}),Current:false,Loaded:0,Inactive:null};a=m[d];e=a.Opts;g=
!e.loader&&k.jqDock.useJqLoader||e.loader==="jquery";k.each(["size","distance","duration","inactivity","fadeIn","step"],function(i,l){e[l]=v(e[l])});h=e.coefficient*1;e.coefficient=isNaN(h)?1.5:h;e.attenuation=Math.pow(e.distance,e.coefficient);e.orient={left:1,center:1,right:1}[e.align]?{vh:"v",inv:"h"}:{vh:"h",inv:"v"};e.vh=k.extend({},t[e.orient.vh],{inv:t[e.orient.inv]});e.labels=e.labels===true?{top:"br",left:"tr"}[e.align]||"tl":/^[tmb][lcr]$/.test(e.labels.toString())?e.labels:false;k("img",
this).each(function(i,l){var j=k(l),f=j.attr("src"),n=j.parent("a");a.Elem[i]={Img:j,Source:f,AltSource:(e.source?e.source.call(l,i):"")||I(l)||f,Label:{txt:j.attr("title")||n.attr("title")||"",width:0,height:0,widthPad:0,heightPad:0,el:0},Initial:0,Trans:0,TransInv:0,Final:0,Offset:0,Centre:0,Pad:{},Linked:!!n.length,width:0,height:0};k.each(o,function(z,p){a.Elem[i].Pad[p]=v(j.css("padding"+p))})});k.each(a.Elem,function(i,l){var j,f=l.AltSource;if(g)k("<img />").bind("load",{id:d,idx:i},b).attr({src:f});
else{j=new Image;j.onload=function(){b.call(this,{data:{id:d,idx:i}});j.onload="";j=null};j.src=f}})});return this}}})(jQuery,window);
