/*

Quicksand 1.2.2

Reorder and filter items with a nice shuffling animation.

Copyright (c) 2010 Jacek Galanciak (razorjack.net) and agilope.com
Big thanks for Piotr Petrus (riddle.pl) for deep code review and wonderful docs & demos.

Dual licensed under the MIT and GPL version 2 licenses.
http://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt
http://github.com/jquery/jquery/blob/master/GPL-LICENSE.txt

Project site: http://razorjack.net/quicksand
Github site: http://github.com/razorjack/quicksand

*/(function(a){a.fn.quicksand=function(b,c){var e={duration:750,easing:"swing",attribute:"data-id",adjustHeight:"auto",useScaling:!0,enhancement:function(a){},selector:"> *",dx:0,dy:0};a.extend(e,c);if(a.browser.msie||typeof a.fn.scale=="undefined")e.useScaling=!1;var f;if(typeof arguments[1]=="function")var f=arguments[1];else if(typeof (arguments[2]=="function"))var f=arguments[2];return this.each(function(c){var g,h=[],i=a(b).clone(),j=a(this),k=a(this).css("height"),l,m=!1,n=a(j).offset(),o=[],p=a(this).find(e.selector);if(a.browser.msie&&a.browser.version.substr(0,1)<7)j.html("").append(i);else{var q=0,r=function(){q||(q=1,$toDelete=j.find("> *"),j.prepend(w.find("> *")),$toDelete.remove(),m&&j.css("height",l),e.enhancement(j),typeof f=="function"&&f.call(this))},s=j.offsetParent(),t=s.offset();s.css("position")=="relative"?s.get(0).nodeName.toLowerCase()!="body"&&(t.top+=parseFloat(s.css("border-top-width"))||0,t.left+=parseFloat(s.css("border-left-width"))||0):(t.top-=parseFloat(s.css("border-top-width"))||0,t.left-=parseFloat(s.css("border-left-width"))||0,t.top-=parseFloat(s.css("margin-top"))||0,t.left-=parseFloat(s.css("margin-left"))||0),isNaN(t.left)&&(t.left=0),isNaN(t.top)&&(t.top=0),t.left-=e.dx,t.top-=e.dy,j.css("height",a(this).height()),p.each(function(b){o[b]=a(this).offset()}),a(this).stop();var u=0,v=0;p.each(function(b){a(this).stop();var c=a(this).get(0);c.style.position=="absolute"?(u=-e.dx,v=-e.dy):(u=e.dx,v=e.dy),c.style.position="absolute",c.style.margin="0",c.style.top=o[b].top-parseFloat(c.style.marginTop)-t.top+v+"px",c.style.left=o[b].left-parseFloat(c.style.marginLeft)-t.left+u+"px"});var w=a(j).clone(),x=w.get(0);x.innerHTML="",x.setAttribute("id",""),x.style.height="auto",x.style.width=j.width()+"px",w.append(i),w.insertBefore(j),w.css("opacity",0),x.style.zIndex=-1,x.style.margin="0",x.style.position="absolute",x.style.top=n.top-t.top+"px",x.style.left=n.left-t.left+"px",e.adjustHeight==="dynamic"?j.animate({height:w.height()},e.duration,e.easing):e.adjustHeight==="auto"&&(l=w.height(),parseFloat(k)<parseFloat(l)?j.css("height",l):m=!0),p.each(function(b){var c=[];typeof e.attribute=="function"?(g=e.attribute(a(this)),i.each(function(){if(e.attribute(this)==g){c=a(this);return!1}})):c=i.filter("["+e.attribute+"="+a(this).attr(e.attribute)+"]"),c.length?e.useScaling?h.push({element:a(this),animation:{top:c.offset().top-t.top,left:c.offset().left-t.left,opacity:1,scale:"1.0"}}):h.push({element:a(this),animation:{top:c.offset().top-t.top,left:c.offset().left-t.left,opacity:1}}):e.useScaling?h.push({element:a(this),animation:{opacity:"0.0",scale:"0.0"}}):h.push({element:a(this),animation:{opacity:"0.0"}})}),i.each(function(b){var c=[],f=[];typeof e.attribute=="function"?(g=e.attribute(a(this)),p.each(function(){if(e.attribute(this)==g){c=a(this);return!1}}),i.each(function(){if(e.attribute(this)==g){f=a(this);return!1}})):(c=p.filter("["+e.attribute+"="+a(this).attr(e.attribute)+"]"),f=i.filter("["+e.attribute+"="+a(this).attr(e.attribute)+"]"));var k;if(c.length===0){e.useScaling?k={opacity:"1.0",scale:"1.0"}:k={opacity:"1.0"},d=f.clone();var l=d.get(0);l.style.position="absolute",l.style.margin="0",l.style.top=f.offset().top-t.top+"px",l.style.left=f.offset().left-t.left+"px",d.css("opacity",0),e.useScaling&&d.css("transform","scale(0.0)"),d.appendTo(j),h.push({element:a(d),animation:k})}}),w.remove(),e.enhancement(j);for(c=0;c<h.length;c++)h[c].element.animate(h[c].animation,e.duration,e.easing,r)}})}})(jQuery)
