(function ($) {
    // Monkey patch jQuery 1.3.1+ to add support for setting or animating CSS
    // scale and rotation independently.
    // 2009 Zachary Johnson www.zachstronaut.com
    var rotateUnits = 'deg';
    
    $.fn.rotate = function (val)
    {
        var style = $(this).css('transform') || 'none';
        
        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/rotate\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }
            
            return 0;
        }
        
        var m = val.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/);
        if (m)
        {
            if (m[3])
            {
                rotateUnits = m[3];
            }
            
            $(this).css(
                'transform',
                style.replace(/none|rotate\([^)]*\)/, '') + 'rotate(' + m[1] + rotateUnits + ')'
            );
        }
    }
    
    // Note that scale is unitless.
    $.fn.scale = function (val, duration, options)
    {
        var style = $(this).css('transform');
        
        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/scale\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }
            
            return 1;
        }
        
        $(this).css(
            'transform',
            style.replace(/none|scale\([^)]*\)/, '') + 'scale(' + val + ')'
        );
    }

    // fx.cur() must be monkey patched because otherwise it would always
    // return 0 for current rotate and scale values
    var curProxied = $.fx.prototype.cur;
    $.fx.prototype.cur = function ()
    {
        if (this.prop == 'rotate')
        {
            return parseFloat($(this.elem).rotate());
        }
        else if (this.prop == 'scale')
        {
            return parseFloat($(this.elem).scale());
        }
        
        return curProxied.apply(this, arguments);
    }
    
    $.fx.step.rotate = function (fx)
    {
        $(fx.elem).rotate(fx.now + rotateUnits);
    }
    
    $.fx.step.scale = function (fx)
    {
        $(fx.elem).scale(fx.now);
    }
    
    /*
    
    Starting on line 3905 of jquery-1.3.2.js we have this code:
    
    // We need to compute starting value
    if ( unit != "px" ) {
        self.style[ name ] = (end || 1) + unit;
        start = ((end || 1) / e.cur(true)) * start;
        self.style[ name ] = start + unit;
    }
    
    This creates a problem where we cannot give units to our custom animation
    because if we do then this code will execute and because self.style[name]
    does not exist where name is our custom animation's name then e.cur(true)
    will likely return zero and create a divide by zero bug which will set
    start to NaN.
    
    The following monkey patch for animate() gets around this by storing the
    units used in the rotation definition and then stripping the units off.
    
    */
    
    var animateProxied = $.fn.animate;
    $.fn.animate = function (prop)
    {
        if (typeof prop['rotate'] != 'undefined')
        {
            var m = prop['rotate'].toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/);
            if (m && m[5])
            {
                rotateUnits = m[5];
            }
            
            prop['rotate'] = m[1];
        }
        
        return animateProxied.apply(this, arguments);
    }
})(jQuery);


(function ($) {
    // Monkey patch jQuery 1.3.1+ css() method to support CSS 'transform'
    // property uniformly across Webkit/Safari/Chrome and Firefox 3.5.
    // 2009 Zachary Johnson www.zachstronaut.com
    function getTransformProperty(element)
    {
        // Try transform first for forward compatibility
        var properties = ['transform', 'WebkitTransform', 'MozTransform'];
        var p;
        while (p = properties.shift())
        {
            if (typeof element.style[p] != 'undefined')
            {
                return p;
            }
        }
        
        // Default to transform also
        return 'transform';
    }
    
    var proxied = $.fn.css;
    $.fn.css = function (arg)
    {
        // Find the correct browser specific property and setup the mapping using
        // $.props which is used internally by jQuery.attr() when setting CSS
        // properties via either the css(name, value) or css(properties) method.
        // The problem with doing this once outside of css() method is that you
        // need a DOM node to find the right CSS property, and there is some risk
        // that somebody would call the css() method before body has loaded or any
        // DOM-is-ready events have fired.
        if
        (
            typeof $.props['transform'] == 'undefined'
            &&
            (
                arg == 'transform'
                ||
                (
                    typeof arg == 'object'
                    && typeof arg['transform'] != 'undefined'
                )
            )
        )
        {
            $.props['transform'] = getTransformProperty(this.get(0));
        }
        
        // We force the property mapping here because jQuery.attr() does
        // property mapping with jQuery.props when setting a CSS property,
        // but curCSS() does *not* do property mapping when *getting* a
        // CSS property.  (It probably should since it manually does it
        // for 'float' now anyway... but that'd require more testing.)
        if (arg == 'transform')
        {
            arg = $.props['transform'];
        }
        
        return proxied.apply(this, arguments);
    };
})(jQuery);


(function(a){a.fn.quicksand=function(s,m,p){function q(e){var c=[];if(a(e).get(0)==undefined)return"";var h=a(e).get(0).nodeName.toLowerCase();if(a(e).attr("id"))h+="#"+a(e).attr("id");c.push(h);for(var i=[];a(e).get(0).nodeName.toLowerCase()!="html";){i.push(e);e=e.parent()}a(i).each(function(){h=a(this).get(0).nodeName.toLowerCase();if(a(this).attr("id"))h+="#"+a(this).attr("id");c.push(h)});return c.reverse().join(" > ")}var b={duration:750,easing:"swing",attribute:"data-id",adjustHeight:true};
a.extend(b,m);b.selector=null;a.extend(b,{selector:"> *"});var k;if(typeof m=="function")k=m;else if(typeof(p=="function"))k=p;return this.each(function(){var e=a(s).clone(),c=a(this);a(this).css("height");var h=a(c).offset(),i=[],l=a(this).find(b.selector);if(a.browser.msie&&a.browser.version.substr(0,1)<7)c.html("").append(e);else{var r=0,j=function(){if(!r){c.html(n.html());a("[data-quicksand-owner="+q(c)+"]").remove();typeof k=="function"&&k.call(this);r=1}},g=c.offsetParent(),d=g.offset();if(g.css("position")==
"relative"){if(g.get(0).nodeName.toLowerCase()!="body"){d.top+=parseFloat(g.css("border-top-width"));d.left+=parseFloat(g.css("border-left-width"))}}else{d.top-=parseFloat(g.css("border-top-width"));d.left-=parseFloat(g.css("border-left-width"));d.top-=parseFloat(g.css("margin-top"));d.left-=parseFloat(g.css("margin-left"))}c.css("height",a(this).height());l.each(function(f){i[f]=a(this).offset()});a(this).stop();l.each(function(f){a(this).stop();a(this).css("position","absolute").css("margin",0).css("top",
i[f].top-parseFloat(a(this).css("margin-top"))-d.top).css("left",i[f].left-parseFloat(a(this).css("margin-left"))-d.left)});var n=a(c).clone().html("").attr("id","").attr("data-quicksand-owner",c.selector).css("height","auto").css("width",c.width()+"px").append(e);n.insertBefore(c).css("z-index",1).css("opacity",0).css("margin",0).css("position","absolute").css("top",h.top-d.top).css("left",h.left-d.left).attr("data-quicksand-owner",q(c));b.adjustHeight&&c.animate({height:n.height()},b.duration,b.easing);
l.each(function(){var f=e.filter("["+b.attribute+"="+a(this).attr(b.attribute)+"]");if(f.length)a.browser.msie?a(this).animate({top:f.offset().top-d.top,left:f.offset().left-d.left,opacity:1},b.duration,b.easing,j):a(this).animate({top:f.offset().top-d.top,left:f.offset().left-d.left,opacity:1,scale:"1.0"},b.duration,b.easing,j);else a.browser.msie?a(this).animate({opacity:"0.0"},b.duration,b.easing,j):a(this).animate({opacity:"0.0",scale:"0.0"},b.duration,b.easing,j)});e.each(function(){var f=l.filter("["+
b.attribute+"="+a(this).attr(b.attribute)+"]"),o=e.filter("["+b.attribute+"="+a(this).attr(b.attribute)+"]");if(f.length===0){f=a.browser.msie?{opacity:"1.0"}:{opacity:"1.0",scale:"1.0"};o.clone().css("position","absolute").css("margin",0).css("top",o.offset().top-d.top).css("left",o.offset().left-d.left).css("opacity",0).css("transform","scale(0.0)").appendTo(c).animate(f,b.duration,b.easing,j)}})}})}})(jQuery);
