// http://copiousinc.com/javascripts/jquery.easing.1.3.js
jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d);},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b;},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b;},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b;},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b;},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b;},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b;},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b;},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b;},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b;},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b;},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b;},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b;},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b;},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b;},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b;},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b;},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b;},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b;},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b;},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b;},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b;},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b;},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b;},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b;},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b;},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b;}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b;}}); 
// http://copiousinc.com/javascripts/jquery-animate-css-rotate-scale.js
 (function($){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+')');}}
$.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+')');}
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);}
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); 
// http://copiousinc.com/javascripts/jquery-css-transform.js
(function($){function getTransformProperty(element)
{var properties=['transform','WebkitTransform','MozTransform'];var p;while(p=properties.shift())
{if(typeof element.style[p]!='undefined')
{return p;}}
return'transform';}
var proxied=$.fn.css;$.fn.css=function(arg)
{if
(typeof $.props['transform']=='undefined'&&(arg=='transform'||(typeof arg=='object'&&typeof arg['transform']!='undefined')))
{$.props['transform']=getTransformProperty(this.get(0));}
if(arg=='transform')
{arg=$.props['transform'];}
return proxied.apply(this,arguments);};})(jQuery);
// http://copiousinc.com/javascripts/jquery.sort.js
(function($){$.fn.sorted=function(customOptions){var options={reversed:false,by:function(a){return a.text();}};$.extend(options,customOptions);$data=$(this);arr=$data.get();arr.sort(function(a,b){var valA=options.by($(a));var valB=options.by($(b));if(options.reversed){return(valA<valB)?1:(valA>valB)?-1:0;}else{return(valA<valB)?-1:(valA>valB)?1:0;}});return $(arr);};})(jQuery);
// http://copiousinc.com/javascripts/jquery.quicksand.js
/* (function($){$.fn.quicksand=function(collection,customOptions){var options={duration:750,easing:'swing',attribute:'data-id',adjustHeight:'auto',useScaling:true,selector:'> *'};$.extend(options,customOptions);if($.browser.msie||(typeof($.fn.scale)=='undefined')){options.useScaling=true;}
var callbackFunction;if(typeof(arguments[1])=='function'){var callbackFunction=arguments[1];}else if(typeof(arguments[2]=='function')){var callbackFunction=arguments[2];}
return this.each(function(i){var val;var animationQueue=[];var $collection=$(collection).clone();var $sourceParent=$(this);var sourceHeight=$(this).css('height');var destHeight;var adjustHeightOnCallback=false;var offset=$($sourceParent).offset();var offsets=[];var $source=$(this).find(options.selector);if($.browser.msie&&$.browser.version.substr(0,1)<7){$sourceParent.html('').append($collection);return;}
var postCallbackPerformed=0;var postCallback=function(){if(!postCallbackPerformed){$sourceParent.html($dest.html());if(typeof callbackFunction=='function'){callbackFunction.call(this);}
if(adjustHeightOnCallback){$sourceParent.css('height',destHeight);}
postCallbackPerformed=1;}};var $correctionParent=$sourceParent.offsetParent();var correctionOffset=$correctionParent.offset();if($correctionParent.css('position')=='relative'){if($correctionParent.get(0).nodeName.toLowerCase()=='body'){}else{correctionOffset.top+=parseFloat($correctionParent.css('border-top-width'));correctionOffset.left+=parseFloat($correctionParent.css('border-left-width'));}}else{correctionOffset.top-=parseFloat($correctionParent.css('border-top-width'));correctionOffset.left-=parseFloat($correctionParent.css('border-left-width'));correctionOffset.top-=parseFloat($correctionParent.css('margin-top'));correctionOffset.left-=parseFloat($correctionParent.css('margin-left'));}
$sourceParent.css('height',$(this).height());$source.each(function(i){offsets[i]=$(this).offset();});$(this).stop();$source.each(function(i){$(this).stop();var rawObj=$(this).get(0);rawObj.style.position='absolute';rawObj.style.margin='0';rawObj.style.top=(offsets[i].top-parseFloat(rawObj.style.marginTop)-correctionOffset.top)+'px';rawObj.style.left=(offsets[i].left-parseFloat(rawObj.style.marginLeft)-correctionOffset.left)+'px';});var $dest=$($sourceParent).clone()
var rawDest=$dest.get(0);rawDest.innerHTML='';rawDest.setAttribute('id','');rawDest.style.height='auto';rawDest.style.width=$sourceParent.width()+'px';$dest.append($collection);$dest.insertBefore($sourceParent);$dest.css('opacity',0.0);rawDest.style.zIndex=-1;rawDest.style.margin='0';rawDest.style.position='absolute';rawDest.style.top=offset.top-correctionOffset.top+'px';rawDest.style.left=offset.left-correctionOffset.left+'px';if(options.adjustHeight==='dynamic'){$sourceParent.animate({height:$dest.height()},options.duration,options.easing);}else if(options.adjustHeight==='auto'){destHeight=$dest.height();if(parseFloat(sourceHeight)<parseFloat(destHeight)){$sourceParent.css('height',destHeight);}else{adjustHeightOnCallback=true;}}
$source.each(function(i){var destElement=[];if(typeof(options.attribute)=='function'){val=options.attribute($(this));$collection.each(function(){if(options.attribute(this)==val){destElement=$(this);return false;}});}else{destElement=$collection.filter('['+options.attribute+'='+$(this).attr(options.attribute)+']');}
if(destElement.length){if(!options.useScaling){animationQueue.push({element:$(this),animation:{top:destElement.offset().top-correctionOffset.top,left:destElement.offset().left-correctionOffset.left,opacity:1.0}});}else{animationQueue.push({element:$(this),animation:{top:destElement.offset().top-correctionOffset.top,left:destElement.offset().left-correctionOffset.left,opacity:1.0,scale:'1.0'}});}}else{if(!options.useScaling){animationQueue.push({element:$(this),animation:{opacity:'0.0'}});}else{animationQueue.push({element:$(this),animation:{opacity:'0.0',scale:'0.0'}});}}});$collection.each(function(i){var sourceElement=[];var destElement=[];if(typeof(options.attribute)=='function'){val=options.attribute($(this));$source.each(function(){if(options.attribute(this)==val){sourceElement=$(this);return false;}});$collection.each(function(){if(options.attribute(this)==val){destElement=$(this);return false;}});}else{sourceElement=$source.filter('['+options.attribute+'='+$(this).attr(options.attribute)+']');destElement=$collection.filter('['+options.attribute+'='+$(this).attr(options.attribute)+']');}
var animationOptions;if(sourceElement.length===0){if(!options.useScaling){animationOptions={opacity:'1.0'};}else{animationOptions={opacity:'1.0',scale:'1.0'};}
d=destElement.clone();var rawDestElement=d.get(0);rawDestElement.style.position='absolute';rawDestElement.style.margin='0';rawDestElement.style.top=destElement.offset().top-correctionOffset.top+'px';rawDestElement.style.left=destElement.offset().left-correctionOffset.left+'px';d.css('opacity',0.0);if(options.useScaling){d.css('transform','scale(0.0)');}
d.appendTo($sourceParent)
animationQueue.push({element:$(d),animation:animationOptions});}});$dest.remove();for(i=0;i<animationQueue.length;i++){animationQueue[i].element.animate(animationQueue[i].animation,options.duration,options.easing,postCallback);}});};})(jQuery); */
/*

Quicksand 1.2.1

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 ($) {
    $.fn.quicksand = function (collection, customOptions) {     
        var options = {
            duration: 750,
            easing: 'swing',
            attribute: 'data-id', // attribute to recognize same items within source and dest
            adjustHeight: 'auto', // 'dynamic' animates height during shuffling (slow), 'auto' adjusts it before or after the animation, false leaves height constant
            useScaling: true, // disable it if you're not using scaling effect or want to improve performance
            enhancement: function(c) {}, // Visual enhacement (eg. font replacement) function for cloned elements
            selector: '> *',
            dx: 0,
            dy: 0
        };
        $.extend(options, customOptions);
        
        if ($.browser.msie || (typeof($.fn.scale) == 'undefined')) {
            // Got IE and want scaling effect? Kiss my ass.
            options.useScaling = false;
        } 
        
        var callbackFunction;
        if (typeof(arguments[1]) == 'function') {
            var callbackFunction = arguments[1];
        } else if (typeof(arguments[2] == 'function')) {
            var callbackFunction = arguments[2];
        }
    
        
        return this.each(function (i) {
            var val;
            var animationQueue = []; // used to store all the animation params before starting the animation; solves initial animation slowdowns
            var $collection = $(collection).clone(); // destination (target) collection
            var $sourceParent = $(this); // source, the visible container of source collection
            var sourceHeight = $(this).css('height'); // used to keep height and document flow during the animation
            
            var destHeight;
            var adjustHeightOnCallback = false;
            
            var offset = $($sourceParent).offset(); // offset of visible container, used in animation calculations
            var offsets = []; // coordinates of every source collection item            
            
            var $source = $(this).find(options.selector); // source collection items
            
            // Replace the collection and quit if IE6
            if ($.browser.msie && $.browser.version=="6.0" && !window.XMLHttpRequest) {
                $sourceParent.html('').append($collection);
                return;
            } 

            // Gets called when any animation is finished
            var postCallbackPerformed = 0; // prevents the function from being called more than one time
            var postCallback = function () {
                if (!postCallbackPerformed) {
                    $sourceParent.html($dest.html()); // put target HTML into visible source container        
                    if (typeof callbackFunction == 'function') {
                        callbackFunction.call(this);
                    }
                    if (adjustHeightOnCallback) {
                        $sourceParent.css('height', destHeight);
                    }
                    options.enhancement($sourceParent); // Perform custom visual enhancements on a newly replaced collection
                    postCallbackPerformed = 1;
                }
            };
            
            // Position: relative situations
            var $correctionParent = $sourceParent.offsetParent();
            var correctionOffset = $correctionParent.offset();
            if ($correctionParent.css('position') == 'relative') {
                if ($correctionParent.get(0).nodeName.toLowerCase() == 'body') {

                } else {
                    correctionOffset.top += parseFloat($correctionParent.css('border-top-width'));
                    correctionOffset.left += parseFloat($correctionParent.css('border-left-width'));
                }
            } else {
                correctionOffset.top -= parseFloat($correctionParent.css('border-top-width'));
                correctionOffset.left -= parseFloat($correctionParent.css('border-left-width'));
                correctionOffset.top -= parseFloat($correctionParent.css('margin-top'));
                correctionOffset.left -= parseFloat($correctionParent.css('margin-left'));
            }
            
            // perform custom corrections from options (use when Quicksand fails to detect proper correction)
            if (isNaN(correctionOffset.left)) {
                correctionOffset.left = 0;
            }
            if (isNaN(correctionOffset.top)) {
                correctionOffset.top = 0;
            }
            
            correctionOffset.left -= options.dx;
            correctionOffset.top -= options.dy;

            // keeps nodes after source container, holding their position
            $sourceParent.css('height', $(this).height());
            
            // get positions of source collections
            $source.each(function (i) {
                offsets[i] = $(this).offset();
            });
            
            // stops previous animations on source container
            $(this).stop();
            var dx = 0; var dy = 0;
            $source.each(function (i) {
                $(this).stop(); // stop animation of collection items
                var rawObj = $(this).get(0);
                if (rawObj.style.position == 'absolute') {
                    dx = -options.dx;
                    dy = -options.dy;
                } else {
                    dx = options.dx;
                    dy = options.dy;                    
                }

                rawObj.style.position = 'absolute';
                rawObj.style.margin = '0';

                rawObj.style.top = (offsets[i].top - parseFloat(rawObj.style.marginTop) - correctionOffset.top + dy) + 'px';
                rawObj.style.left = (offsets[i].left - parseFloat(rawObj.style.marginLeft) - correctionOffset.left + dx) + 'px';
            });
                    
            // create temporary container with destination collection
            var $dest = $($sourceParent).clone();
            var rawDest = $dest.get(0);
            rawDest.innerHTML = '';
            rawDest.setAttribute('id', '');
            rawDest.style.height = 'auto';
            rawDest.style.width = $sourceParent.width() + 'px';
            $dest.append($collection);      
            // insert node into HTML
            // Note that the node is under visible source container in the exactly same position
            // The browser render all the items without showing them (opacity: 0.0)
            // No offset calculations are needed, the browser just extracts position from underlayered destination items
            // and sets animation to destination positions.
            $dest.insertBefore($sourceParent);
            $dest.css({'opacity': '0.0'});
            rawDest.style.zIndex = -1;
            
            rawDest.style.margin = '0';
            rawDest.style.position = 'absolute';
            rawDest.style.top = offset.top - correctionOffset.top + 'px';
            rawDest.style.left = offset.left - correctionOffset.left + 'px';
            
            
    
            

            if (options.adjustHeight === 'dynamic') {
                // If destination container has different height than source container
                // the height can be animated, adjusting it to destination height
                $sourceParent.animate({height: $dest.height()}, options.duration, options.easing);
            } else if (options.adjustHeight === 'auto') {
                destHeight = $dest.height();
                if (parseFloat(sourceHeight) < parseFloat(destHeight)) {
                    // Adjust the height now so that the items don't move out of the container
                    $sourceParent.css('height', destHeight);
                } else {
                    //  Adjust later, on callback
                    adjustHeightOnCallback = true;
                }
            }
                
            // Now it's time to do shuffling animation
            // First of all, we need to identify same elements within source and destination collections    
            $source.each(function (i) {
                var destElement = [];
                if (typeof(options.attribute) == 'function') {
                    
                    val = options.attribute($(this));
                    $collection.each(function() {
                        if (options.attribute(this) == val) {
                            destElement = $(this);
                            return false;
                        }
                    });
                } else {
                    destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                }
                if (destElement.length) {
                    // The item is both in source and destination collections
                    // It it's under different position, let's move it
                    if (!options.useScaling) {
                        animationQueue.push(
                                            {
                                                element: $(this), 
                                                animation: 
                                                    {top: destElement.offset().top - correctionOffset.top, 
                                                     left: destElement.offset().left - correctionOffset.left, 
                                                     opacity: 1.0
                                                    }
                                            });

                    } else {
                        animationQueue.push({
                                            element: $(this), 
                                            animation: {top: destElement.offset().top - correctionOffset.top, 
                                                        left: destElement.offset().left - correctionOffset.left, 
                                                        'opacity': 1, 
                                                        scale: '1.0'
                                                       }
                                            });

                    }
                } else {
                    // The item from source collection is not present in destination collections
                    // Let's remove it
                    if (!options.useScaling) {
                        animationQueue.push({element: $(this), 
                                             animation: {'opacity': 0}});
                    } else {
                        animationQueue.push({element: $(this), 
									animation:{	
											'opacity': 0, 
											scale: '0.0'
											}
									});
                    }
                }
            });
            
            $collection.each(function (i) {
                // Grab all items from target collection not present in visible source collection
                
                var sourceElement = [];
                var destElement = [];
                if (typeof(options.attribute) == 'function') {
                    val = options.attribute($(this));
                    $source.each(function() {
                        if (options.attribute(this) == val) {
                            sourceElement = $(this);
                            return false;
                        }
                    });                 

                    $collection.each(function() {
                        if (options.attribute(this) == val) {
                            destElement = $(this);
                            return false;
                        }
                    });
                } else {
                    sourceElement = $source.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                    destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                }
                
                var animationOptions;
                if (sourceElement.length === 0) {
                    // No such element in source collection...
                    if (!options.useScaling) {
                        animationOptions = {
                            opacity: '1.0'
                        };
                    } else {
                        animationOptions = {
                            opacity: '1.0',
                            scale: '1.0'
                        };
                    }
                    // Let's create it
                    d = destElement.clone();
                    var rawDestElement = d.get(0);
                    rawDestElement.style.position = 'absolute';
                    rawDestElement.style.margin = '0';
                    rawDestElement.style.top = destElement.offset().top - correctionOffset.top + 'px';
                    rawDestElement.style.left = destElement.offset().left - correctionOffset.left + 'px';
                    d.css({'opacity':'0.0'}); // IE
				//d.css('filter','progid:DXImageTransform.Microsoft.Alpha(opacity=0.0)'); 
                    if (options.useScaling) {
                        d.css('transform', 'scale(0.0)');
                    }
                    d.appendTo($sourceParent);
                    
                    animationQueue.push({element: $(d), 
                                         animation: animationOptions});
                }
            });
            
            $dest.remove();
            options.enhancement($sourceParent); // Perform custom visual enhancements during the animation
            for (i = 0; i < animationQueue.length; i++) {
                animationQueue[i].element.animate(animationQueue[i].animation, options.duration, options.easing, postCallback);
            }
        });
    };
})(jQuery);
// http://copiousinc.com/javascripts/custom.sort.js
$(function() {

//===== Setting Variables =====//

var read_button = function(class_names) {
	var r = {
		selected: false,
		type: 0
	};
	for (var i=0; i < class_names.length; i++) {
		if (class_names[i].indexOf('selected-') == 0) {
			r.selected = true;
		}
		if (class_names[i].indexOf('segment-') == 0) {
			r.segment = class_names[i].split('-')[1];
		}
	};
	return r;
};
var determine_sort = function($buttons) {
	var $selected = $buttons.parent().filter('[class*="selected-"]');
	return $selected.find('a').attr('data-value');
};
var determine_kind = function($buttons) {
	var $selected = $buttons.parent().filter('[class*="selected-"]');
	return $selected.find('a').attr('data-value');
};
var $preferences = {
	duration: 800,
	easing: 'easeInOutQuad',
	useScaling: true,
	adjustHeight: false
};
var hasBackBtn = function($back_button)
{
	if($back_button.length > 0)
	{
		return true;
	}else{
		return false;
	}
}
var $list = $('#list');
//var $data = $list;
var $data = $list.clone();
var $controls = $('div.sub_nav ul#source');
var $back_button = $('#portfolio_detail').find('a.back');
var $back_button_link = $back_button.attr('href');
var current_filter = "all";

if(hasBackBtn($back_button))
{
	$(document).ready(function()
	{	
		$back_button.attr('href', '/portfolio_grid' + window.location.search);
	});
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


$controls.each(function(i) {

	var $control = $(this);
	var $buttons = $control.find('a');
	
	if(!hasBackBtn($back_button))
	{
		$(document).ready(function()
		{
			if(window.location.search != '')
			{
				//var hash = window.location.search;
				//hash = hash.replace(/^.*?#/, '');
				
				//if(hash == 'all')
				if(gup('filter') == 'all')
				{
					var $filtered_data = $data.find('li');
					
					$controls.find('#all').addClass('active');
				}else{
					$controls.find('#'+gup('filter')).addClass('active');
					
					var $filtered_data = $data.find('li.' + gup('filter'));
				}
			}else{
				var $filtered_data = $data.find('li');
				
				$controls.find('#all').addClass('active');
			}
			var $sorted_data = $filtered_data.sorted({
				by: function(v) {
				return $(v).find('strong').text().toLowerCase();
				}
			});
			
			$(".image-grid li").live('mouseover', function()
			{
				
				var self = this;
				var thumbOver = $(this).find("img").attr("src");
				var caption = $(this).children('.cover.boxcaption');
				
				$(this).find('.cover').animate({top: '-200px'},{queue:false, duration:240}); 
				$(this).find("img").animate({top: '-200px'}, {queue:false, duration:240});
			});
			
			$(".image-grid li").live('mouseout', function()
			{
				$(this).find('.cover').stop().animate({top: '-140px'}, {gueue:false, duration:240});
				$(this).find("img").stop().animate({top: '0px'}, {queue:false, duration:240});
			});
			
			$(".image-grid li").live('click', function()
			{
				var current_filter = $control.find('a.active').attr('id');
					
				$(this).children('a').attr('href', $(this).children('a').attr('href')+'?filter='+current_filter);
			});
			
			$list.quicksand($sorted_data, $preferences);
		});
	}

	$buttons.bind('click', function(e) {

		var $button = $(this);
		var $button_container = $button.parent();
		var button_properties = read_button($button_container.attr('class').split(' '));
		var selected = button_properties.selected;
		var button_segment = button_properties.segment;

		if (!selected) {

			$buttons.parent().removeClass('selected-0').removeClass('selected-1').removeClass('selected-2');
			$buttons.removeClass('active'); //Removes all existing active classes from any of the buttons.
			$button_container.addClass('selected-' + button_segment);
			$button.addClass('active'); //Adds an active class to the current button.
			
			var sorting_type = determine_sort($controls.eq(1).find('a'));
			var sorting_kind = determine_kind($controls.eq(0).find('a'));
			
			if (sorting_kind == 'all') {
				var $filtered_data = $data.find('li');
			} else {
				var $filtered_data = $data.find('li.' + sorting_kind);
			}

			if (sorting_type == 'size') {
				var $sorted_data = $filtered_data.sorted({
					by: function(v) {
					return parseFloat($(v).find('span').text());
					}
				});
			 } else {
				var $sorted_data = $filtered_data.sorted({
					by: function(v) {
					return $(v).find('strong').text().toLowerCase();
					}
				});
			 }
			 $list.quicksand($sorted_data, $preferences);
		}
		e.preventDefault();
	});
 });
 
 var high_performance = true;
 var $performance_container = $('#performance-toggle');
 var $original_html = $performance_container.html();

 $performance_container.find('a').live('click', function(e) {
	 if (high_performance) {
		$preferences.useScaling = false;
		$performance_container.html('CSS3 scaling turned off. Try the demo again. <a href="#toggle">Reverse</a>.');
		high_performance = false;
	 } else {
		$preferences.useScaling = true;
		$performance_container.html($original_html);
		high_performance = true;
	 }
	 e.preventDefault();
});
});
// http://copiousinc.com/javascripts/tools.scrollable-1.1.1.js
(function($){$.tools=$.tools||{};$.tools.scrollable={version:'1.1.2',conf:{size:5,vertical:false,speed:400,keyboard:true,keyboardSteps:null,disabledClass:'disabled',hoverClass:null,clickable:true,activeClass:'active',easing:'swing',loop:false,items:'.items',item:null,prev:'.prev',next:'.next',prevPage:'.prevPage',nextPage:'.nextPage',api:false}};var current;function Scrollable(root,conf){var self=this,$self=$(this),horizontal=!conf.vertical,wrap=root.children(),index=0,forward;if(!current){current=self;}
$.each(conf,function(name,fn){if($.isFunction(fn)){$self.bind(name,fn);}});if(wrap.length>1){wrap=$(conf.items,root);}
function find(query){var els=$(query);return conf.globalNav?els:root.parent().find(query);}
root.data("finder",find);var prev=find(conf.prev),next=find(conf.next),prevPage=find(conf.prevPage),nextPage=find(conf.nextPage);$.extend(self,{getIndex:function(){return index;},getClickIndex:function(){var items=self.getItems();return items.index(items.filter("."+conf.activeClass));},getConf:function(){return conf;},getSize:function(){return self.getItems().size();},getPageAmount:function(){return Math.ceil(this.getSize()/conf.size);},getPageIndex:function(){return Math.ceil(index/conf.size);},getNaviButtons:function(){return prev.add(next).add(prevPage).add(nextPage);},getRoot:function(){return root;},getItemWrap:function(){return wrap;},getItems:function(){return wrap.children(conf.item);},getVisibleItems:function(){return self.getItems().slice(index,index+conf.size);},seekTo:function(i,time,fn){if(i<0){i=0;}
if(index===i){return self;}
if($.isFunction(time)){fn=time;}
if(i>self.getSize()-conf.size){return conf.loop?self.begin():this.end();}
var item=self.getItems().eq(i);if(!item.length){return self;}
var e=$.Event("onBeforeSeek");$self.trigger(e,[i]);if(e.isDefaultPrevented()){return self;}
if(time===undefined||$.isFunction(time)){time=conf.speed;}
function callback(){if(fn){fn.call(self,i);}
$self.trigger("onSeek",[i]);}
if(horizontal){wrap.animate({left:-item.position().left},time,conf.easing,callback);}else{wrap.animate({top:-item.position().top},time,conf.easing,callback);}
current=self;index=i;e=$.Event("onStart");$self.trigger(e,[i]);if(e.isDefaultPrevented()){return self;}
prev.add(prevPage).toggleClass(conf.disabledClass,i===0);next.add(nextPage).toggleClass(conf.disabledClass,i>=self.getSize()-conf.size);return self;},move:function(offset,time,fn){forward=offset>0;return this.seekTo(index+offset,time,fn);},next:function(time,fn){return this.move(1,time,fn);},prev:function(time,fn){return this.move(-1,time,fn);},movePage:function(offset,time,fn){forward=offset>0;var steps=conf.size*offset;var i=index%conf.size;if(i>0){steps+=(offset>0?-i:conf.size-i);}
return this.move(steps,time,fn);},prevPage:function(time,fn){return this.movePage(-1,time,fn);},nextPage:function(time,fn){return this.movePage(1,time,fn);},setPage:function(page,time,fn){return this.seekTo(page*conf.size,time,fn);},begin:function(time,fn){forward=false;return this.seekTo(0,time,fn);},end:function(time,fn){forward=true;var to=this.getSize()-conf.size;return to>0?this.seekTo(to,time,fn):self;},reload:function(){$self.trigger("onReload");return self;},focus:function(){current=self;return self;},click:function(i){var item=self.getItems().eq(i),klass=conf.activeClass,size=conf.size;if(i<0||i>=self.getSize()){return self;}
if(size==1){if(conf.loop){return self.next();}
if(i===0||i==self.getSize()-1){forward=(forward===undefined)?true:!forward;}
return forward===false?self.prev():self.next();}
if(size==2){if(i==index){i--;}
self.getItems().removeClass(klass);item.addClass(klass);return self.seekTo(i,time,fn);}
if(!item.hasClass(klass)){self.getItems().removeClass(klass);item.addClass(klass);var delta=Math.floor(size/2);var to=i-delta;if(to>self.getSize()-size){to=self.getSize()-size;}
if(to!==i){return self.seekTo(to);}}
return self;},bind:function(name,fn){$self.bind(name,fn);return self;},unbind:function(name){$self.unbind(name);return self;}});$.each("onBeforeSeek,onStart,onSeek,onReload".split(","),function(i,ev){self[ev]=function(fn){return self.bind(ev,fn);};});prev.addClass(conf.disabledClass).click(function(){self.prev();});next.click(function(){self.next();});nextPage.click(function(){self.nextPage();});if(self.getSize()<conf.size){next.add(nextPage).addClass(conf.disabledClass);}
prevPage.addClass(conf.disabledClass).click(function(){self.prevPage();});var hc=conf.hoverClass,keyId="keydown."+Math.random().toString().substring(10);self.onReload(function(){if(hc){self.getItems().hover(function(){$(this).addClass(hc);},function(){$(this).removeClass(hc);});}
if(conf.clickable){self.getItems().each(function(i){$(this).unbind("click.scrollable").bind("click.scrollable",function(e){if($(e.target).is("a")){return;}
return self.click(i);});});}
if(conf.keyboard){$(document).unbind(keyId).bind(keyId,function(evt){if(evt.altKey||evt.ctrlKey){return;}
if(conf.keyboard!='static'&&current!=self){return;}
var s=conf.keyboardSteps;if(horizontal&&(evt.keyCode==37||evt.keyCode==39)){self.move(evt.keyCode==37?-s:s);return evt.preventDefault();}
if(!horizontal&&(evt.keyCode==38||evt.keyCode==40)){self.move(evt.keyCode==38?-s:s);return evt.preventDefault();}
return true;});}else{$(document).unbind(keyId);}});self.reload();}
$.fn.scrollable=function(conf){var el=this.eq(typeof conf=='number'?conf:0).data("scrollable");if(el){return el;}
var globals=$.extend({},$.tools.scrollable.conf);conf=$.extend(globals,conf);conf.keyboardSteps=conf.keyboardSteps||conf.size;this.each(function(){el=new Scrollable($(this),conf);$(this).data("scrollable",el);});return conf.api?el:this;};})(jQuery);
// http://copiousinc.com/javascripts/tools.scrollable.autoscroll-1.0.1.js
(function($){var t=$.tools.scrollable;t.plugins=t.plugins||{};t.plugins.autoscroll={version:'1.0.1',conf:{autoplay:true,interval:3000,autopause:true,steps:1,api:false}};$.fn.autoscroll=function(conf){if(typeof conf=='number'){conf={interval:conf};}
var opts=$.extend({},t.plugins.autoscroll.conf),ret;$.extend(opts,conf);this.each(function(){var api=$(this).scrollable();if(api){ret=api;}
var timer,hoverTimer,stopped=true;api.play=function(){if(timer){return;}
stopped=false;timer=setInterval(function(){api.move(opts.steps);},opts.interval);api.move(opts.steps);};api.pause=function(){timer=clearInterval(hoverTimer);};api.stop=function(){api.pause();stopped=true;};if(opts.autopause){api.getRoot().add(api.getNaviButtons()).hover(function(){api.pause();clearInterval(hoverTimer);},function(){if(!stopped){hoverTimer=setTimeout(api.play,opts.interval);}});}
if(opts.autoplay){setTimeout(api.play,opts.interval);}});return opts.api?ret:this;};})(jQuery);
// http://copiousinc.com/javascripts/tools.scrollable.navigator-1.0.2.js
(function($){var t=$.tools.scrollable;t.plugins=t.plugins||{};t.plugins.navigator={version:'1.0.2',conf:{navi:'.navi',naviItem:null,activeClass:'active',indexed:false,api:false,idPrefix:null}};$.fn.navigator=function(conf){var globals=$.extend({},t.plugins.navigator.conf),ret;if(typeof conf=='string'){conf={navi:conf};}
conf=$.extend(globals,conf);this.each(function(){var api=$(this).scrollable(),root=api.getRoot(),navi=root.data("finder").call(null,conf.navi),els=null,buttons=api.getNaviButtons();if(api){ret=api;}
api.getNaviButtons=function(){return buttons.add(navi);};function reload(){if(!navi.children().length||navi.data("navi")==api){navi.empty();navi.data("navi",api);for(var i=0;i<api.getPageAmount();i++){navi.append($("<"+(conf.naviItem||'a')+"/>"));}
els=navi.children().each(function(i){var el=$(this);el.click(function(e){api.setPage(i);return e.preventDefault();});if(conf.indexed){el.text(i);}
if(conf.idPrefix){el.attr("id",conf.idPrefix+i);}});}else{els=conf.naviItem?navi.find(conf.naviItem):navi.children();els.each(function(i){var el=$(this);el.click(function(evt){api.setPage(i);return evt.preventDefault();});});}
els.eq(0).addClass(conf.activeClass);}
api.onStart(function(e,index){var cls=conf.activeClass;els.removeClass(cls).eq(api.getPageIndex()).addClass(cls);});api.onReload(function(){reload();});reload();var el=els.filter("[href="+location.hash+"]");if(el.length){api.move(els.index(el));}});return conf.api?ret:this;};})(jQuery);
// http://copiousinc.com/javascripts/copious_js.js
$(document).ready(function()
{this.start=function()
{Add_scrollable("#single_item_gallery",true,true);Add_tabs("#blog #slides");Create_columns($("#services"),2);Reset_search("#search input#searchBox");HD_btn($("#services_page").find(".demoReelHD"));}
this.start();});function HD_btn($element)
{var self=this;var _$element=$element;if(_$element.length>0)
{_$element.hover(function(){_$element.css({"background":"url(/images/services/HDbtn3_hover.jpg) no-repeat scroll 0 0"});},function(){_$element.css({"background":"url(/images/services/HDbtn3.jpg) no-repeat scroll 0 0"});});_$element.fancybox({'type':'swf','width':800,'height':450,'swf':{'wmode':'transparent','allowfullscreen':'false'},'href':'http://vimeo.com/moogaloop.swf?clip_id=9261955&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00adef&fullscreen=1'});}}
function Reset_search(element)
{var self=this;var $element=$(element);var text='';if($element.length>0)
{$element.focus(function(){if($element.val()=="Search Here")
{$element.val('');}});$element.blur(function(){if($element.val()=='')
{$element.val('Search Here');}});}}
function Add_tabs(element)
{var self=this;var $element=$(element);if($element.length>0)
{$("#blog #slides").scrollable({size:1,clickable:false}).navigator({navi:"#tabs",naviItem:"a",activeClass:"active"});}}
function Fancy_letters($element)
{var self=this;var _$element=$element;this.start=function()
{if(_$element.length>0)
{_$element.fancyletter();}}
this.start();}
function Add_scrollable(element,isRepeating,isAutoPlay)
{var self=this;var $element=$(element);var _isRepeating=isRepeating;var _isAutoPlay=isAutoPlay;var _interval=9000;if($element.length>0)
{if(_isRepeating)
{if(_isAutoPlay)
{$element.scrollable({clickable:false,size:1}).circular().autoscroll({autoplay:_isAutoPlay,interval:_interval});}else{$element.scrollable({size:1,clickable:false,speed:200}).circular();}}else{$element.scrollable({size:1})}}}
function Create_columns($element,colNum)
{var self=this;this._colNum=colNum;this.colContainer=$element;this.items=this.colContainer.children('li');this.col='<div class="column"></div>';this.itemsInColumn=5;this.itemCount=0;this.activeColumn=0;this.start=function()
{self.addColumns();self.insertItems();}
this.insertItems=function()
{for(var i=0;i<self.colContainer.children('.column').length;i++)
{for(var j=0;j<self.items.length;j++){if(j<self.itemsInColumn)
{self.colContainer.children('.column').eq(0).append(self.items.eq(j));}else{self.colContainer.children('.column').eq(1).append(self.items.eq(j));}}}}
this.addColumns=function()
{for(var i=0;i<self.items.length;i++)
{if(i%self.itemsInColumn==0)
{self.colContainer.append(self.col);}}}
this.start();}