/**
 * jQuery List DragSort v0.3.10
 * Website: http://dragsort.codeplex.com/
 * License: http://dragsort.codeplex.com/license
**/
(function(a){a.fn.dragsort=function(c){var d=a.extend({},a.fn.dragsort.defaults,c);var b=new Array();var f=null,e=null;if(this.selector){a("head").append("<style type='text/css'>"+(this.selector.split(",").join(" "+d.dragSelector+",")+" "+d.dragSelector)+" { cursor: pointer; }</style>")}this.each(function(h,g){if(a(g).is("table")&&a(g).children().size()==1&&a(g).children().is("tbody")){g=a(g).children().get(0)}var j={draggedItem:null,placeHolderItem:null,pos:null,offset:null,offsetLimit:null,container:g,init:function(){a(this.container).attr("listIdx",h).mousedown(this.grabItem).find(d.dragSelector).css("cursor","pointer")},grabItem:function(l){if(l.button==2||a(l.target).is(d.dragSelectorExclude)){return}var n=l.target;while(!a(n).is("[listIdx="+a(this).attr("listIdx")+"] "+d.dragSelector)){if(n==this){return}n=n.parentNode}if(f!=null&&f.draggedItem!=null){f.dropItem()}a(l.target).css("cursor","move");f=b[a(this).attr("listIdx")];f.draggedItem=a(n).closest(d.itemSelector);var i=parseInt(f.draggedItem.css("marginTop"));var m=parseInt(f.draggedItem.css("marginLeft"));f.offset=f.draggedItem.offset();f.offset.top=l.pageY-f.offset.top+(isNaN(i)?0:i)-1;f.offset.left=l.pageX-f.offset.left+(isNaN(m)?0:m)-1;if(!d.dragBetween){var k=a(f.container).outerHeight()==0?Math.max(1,Math.round(0.5+a(f.container).children(d.itemSelector).size()*f.draggedItem.outerWidth()/a(f.container).outerWidth()))*f.draggedItem.outerHeight():a(f.container).outerHeight();f.offsetLimit=a(f.container).offset();f.offsetLimit.right=f.offsetLimit.left+a(f.container).outerWidth()-f.draggedItem.outerWidth();f.offsetLimit.bottom=f.offsetLimit.top+k-f.draggedItem.outerHeight()}f.draggedItem.css({position:"absolute",opacity:0.8,"z-index":999}).after(d.placeHolderTemplate);f.placeHolderItem=f.draggedItem.next().css("height",f.draggedItem.height()).attr("placeHolder",true);a(b).each(function(p,o){o.ensureNotEmpty();o.buildPositionTable()});f.setPos(l.pageX,l.pageY);a(document).bind("selectstart",f.stopBubble);a(document).bind("mousemove",f.swapItems);a(document).bind("mouseup",f.dropItem);return false},setPos:function(i,m){var l=m-this.offset.top;var k=i-this.offset.left;if(!d.dragBetween){l=Math.min(this.offsetLimit.bottom,Math.max(l,this.offsetLimit.top));k=Math.min(this.offsetLimit.right,Math.max(k,this.offsetLimit.left))}this.draggedItem.parents().each(function(){if(a(this).css("position")!="static"&&(!a.browser.mozilla||a(this).css("display")!="table")){var n=a(this).offset();l-=n.top;k-=n.left;return false}});this.draggedItem.css({top:l,left:k})},buildPositionTable:function(){var i=this.draggedItem==null?null:this.draggedItem.get(0);var k=new Array();a(this.container).children(d.itemSelector).each(function(l,n){if(n!=i){var m=a(n).offset();m.right=m.left+a(n).width();m.bottom=m.top+a(n).height();m.elm=n;k.push(m)}});this.pos=k},dropItem:function(){if(f.draggedItem==null){return}a(f.container).find(d.dragSelector).css("cursor","pointer");f.placeHolderItem.before(f.draggedItem);f.draggedItem.css({position:"",top:"",left:"",opacity:"","z-index":""});f.placeHolderItem.remove();a("*[emptyPlaceHolder]").remove();d.dragEnd.apply(f.draggedItem);f.draggedItem=null;a(document).unbind("selectstart",f.stopBubble);a(document).unbind("mousemove",f.swapItems);a(document).unbind("mouseup",f.dropItem);return false},stopBubble:function(){return false},swapItems:function(n){if(f.draggedItem==null){return false}f.setPos(n.pageX,n.pageY);var m=f.findPos(n.pageX,n.pageY);var l=f;for(var k=0;m==-1&&d.dragBetween&&k<b.length;k++){m=b[k].findPos(n.pageX,n.pageY);l=b[k]}if(m==-1||a(l.pos[m].elm).attr("placeHolder")){return false}if(e==null||e.top>f.draggedItem.offset().top||e.left>f.draggedItem.offset().left){a(l.pos[m].elm).before(f.placeHolderItem)}else{a(l.pos[m].elm).after(f.placeHolderItem)}a(b).each(function(p,o){o.ensureNotEmpty();o.buildPositionTable()});e=f.draggedItem.offset();return false},findPos:function(k,m){for(var l=0;l<this.pos.length;l++){if(this.pos[l].left<k&&this.pos[l].right>k&&this.pos[l].top<m&&this.pos[l].bottom>m){return l}}return -1},ensureNotEmpty:function(){if(!d.dragBetween){return}var i=this.draggedItem==null?null:this.draggedItem.get(0);var l=null,k=true;a(this.container).children(d.itemSelector).each(function(m,n){if(a(n).attr("emptyPlaceHolder")){l=n}else{if(n!=i){k=false}}});if(k&&l==null){a(this.container).append(d.placeHolderTemplate).children(":last").attr("emptyPlaceHolder",true)}else{if(!k&&l!=null){a(l).remove()}}}};j.init();b.push(j)});return this};a.fn.dragsort.defaults={itemSelector:"li",dragSelector:"li",dragSelectorExclude:"input, a[href]",dragEnd:function(){},dragBetween:false,placeHolderTemplate:"<li>&nbsp;</li>"}})(jQuery);
/**
 * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/11/2009
 * @author Ariel Flesler
 * @version 1.2.7
 **/
;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$('<a> </a>').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery);
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/*
 * jQuery.SerialScroll - Animated scrolling of series
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 06/14/2009
 * @author Ariel Flesler
 * @version 1.2.2
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 */
;(function(a){var b=a.serialScroll=function(c){return a(window).serialScroll(c)};b.defaults={duration:1e3,axis:"x",event:"click",start:0,step:1,lock:!0,cycle:!0,constant:!0};a.fn.serialScroll=function(c){return this.each(function(){var t=a.extend({},b.defaults,c),s=t.event,i=t.step,r=t.lazy,e=t.target?this:document,u=a(t.target||this,e),p=u[0],m=t.items,h=t.start,g=t.interval,k=t.navigation,l;if(!r){m=d()}if(t.force){f({},h)}a(t.prev||[],e).bind(s,-i,q);a(t.next||[],e).bind(s,i,q);if(!p.ssbound){u.bind("prev.serialScroll",-i,q).bind("next.serialScroll",i,q).bind("goto.serialScroll",f)}if(g){u.bind("start.serialScroll",function(v){if(!g){o();g=!0;n()}}).bind("stop.serialScroll",function(){o();g=!1})}u.bind("notify.serialScroll",function(x,w){var v=j(w);if(v>-1){h=v}});p.ssbound=!0;if(t.jump){(r?u:d()).bind(s,function(v){f(v,j(v.target))})}if(k){k=a(k,e).bind(s,function(v){v.data=Math.round(d().length/k.length)*k.index(this);f(v,this)})}function q(v){v.data+=h;f(v,this)}function f(B,z){if(!isNaN(z)){B.data=z;z=p}var C=B.data,v,D=B.type,A=t.exclude?d().slice(0,-t.exclude):d(),y=A.length,w=A[C],x=t.duration;if(D){B.preventDefault()}if(g){o();l=setTimeout(n,t.interval)}if(!w){v=C<0?0:y-1;if(h!=v){C=v}else{if(!t.cycle){return}else{C=y-v-1}}w=A[C]}if(!w||t.lock&&u.is(":animated")||D&&t.onBefore&&t.onBefore(B,w,u,d(),C)===!1){return}if(t.stop){u.queue("fx",[]).stop()}if(t.constant){x=Math.abs(x/i*(h-C))}u.scrollTo(w,x,t).trigger("notify.serialScroll",[C])}function n(){u.trigger("next.serialScroll")}function o(){clearTimeout(l)}function d(){return a(m,p)}function j(w){if(!isNaN(w)){return w}var x=d(),v;while((v=x.index(w))==-1&&w!=p){w=w.parentNode}return v}})}})(jQuery);
/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		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;
	}
});
/**
 * jQuery Image Preloader
 * Copyright (c) 20011 Idered - IderedPL(at)gmail(dot)com | http://idered.pl/news/jquery/preloader/
 * Dual licensed under MIT and GPL.
 * Date: 2011.01.31
 * @author Idered
 * @version 1.1
 */
$.fn.preloader = function(options) {
	var defaults = {
		onDone : function() {
		},
		onEachLoad : function(img) {
		},
		onLoadError : function(img) {
		},
		fadeIn : 500,
		delay : 300,
		interval : 200,
		parentWrap : 'a',
		loader : '/img/loading2.gif'
	},
	options = $.extend(defaults, options),
	images = $(this).find('img'),
	loaderCss = {
		background : 'url(' + options.loader + ') 50% 50% no-repeat #e6e6e6',
		display : 'inline-block'
	},
	delayTime = 0
	loadError = false;
	
	images.css({
			visibility : 'visible',
			opacity : 0
		}).each(function() {
			if($(this).parent(options.parentWrap).length) 
				$(this).parent(options.parentWrap).css(loaderCss);
			else 
				$(this).wrap('<a class="unwrap"/>').parent().css(loaderCss);
		});
	
	var timer = setInterval(function() {
			init();
		}, options.interval);
	
	init = function() {
		images = images.filter(function() {
		
				this.onerror = function() {
					loadError = true;
				};				
				
				if(loadError == 1) {
				
					$(this).css({ visibility : 'visible',	opacity : 1 });
					
					if($(this).parent().hasClass('unwrap')) 
						$(this).unwrap();
					else 
						$(this).parent().attr('style', '');
						
					options.onLoadError($(this));
					
					return null;					
				} else if(this.complete && this.naturalWidth !== 0) {				
				
					delayTime = delayTime + options.delay;
					$(this).css({ visibility : 'visible' })
						.delay(delayTime).animate({ opacity : 1 }, options.fadeIn, function() {
						
							if($(this).parent().hasClass('unwrap')) 
								$(this).unwrap();
							else 
								$(this).parent().attr('style', '');
								
							options.onEachLoad($(this));
						});
				} else
					return this;
			}
		);
		
		if(images.length == 0) {
			clearInterval(timer);
			options.onDone();
		}		
	};
}
