/*
 * jQuery.fracs 0.10
 * http://larsjung.de/fracs
 * 
 * provided under the terms of the MIT License
 */
(function(a,b){"use strict";var c="_mp_api";a.ModPlug=a.ModPlug||{plugin:function(d,e){if(!d||a[d]||a.fn[d])return d?a[d]?2:3:1;var f={statics:{},methods:{},defaultStatic:b,defaultMethod:b},g=a.extend({},f,e),h=function(){var b,c;b=Array.prototype.slice.call(arguments),c=g.defaultStatic instanceof Function?g.defaultStatic.apply(this,b):g.defaultStatic;if(h[c]instanceof Function)return h[c].apply(this,b);a.error("Static method defaulted to '"+c+"' does not exist on 'jQuery."+d+"'")},i={},j=function(b){var c,e;if(i[b]instanceof Function)return c=Array.prototype.slice.call(arguments,1),i[b].apply(this,c);c=Array.prototype.slice.call(arguments),e=g.defaultMethod instanceof Function?g.defaultMethod.apply(this,c):g.defaultMethod;if(i[e]instanceof Function)return i[e].apply(this,c);a.error("Method '"+b+"' defaulted to '"+e+"' does not exist on 'jQuery."+d+"'")},k={addStatics:function(b){return a.extend(h,b),h[c]=k,this},addMethods:function(b){return a.extend(i,b),this}};return k.addStatics(g.statics).addMethods(g.methods),a[d]=h,a.fn[d]=j,0},module:function(b,d){if(!a[b]||!a[b][c])return a[b]?2:1;var e={statics:{},methods:{}},f=a.extend({},e,d);return a[b][c].addStatics(f.statics).addMethods(f.methods),0}}})(jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e=b(a),f=b(document);d.Rect=function(a,b,c,e){if(this instanceof d.Rect)this.left=Math.round(a),this.top=Math.round(b),this.width=Math.round(c),this.height=Math.round(e),this.right=this.left+this.width,this.bottom=this.top+this.height;else return new d.Rect(a,b,c,e)},d.Rect.prototype={equals:function(a){return this.left===a.left&&this.top===a.top&&this.width===a.width&&this.height===a.height},area:function(){return this.width*this.height},intersection:function(a){var b=Math.max(this.left,a.left),e=Math.min(this.right,a.right),f=Math.max(this.top,a.top),g=Math.min(this.bottom,a.bottom),h=e-b,i=g-f;return h>=0&&i>=0?d.Rect(b,f,h,i):c},envelope:function(a){var b=Math.min(this.left,a.left),c=Math.max(this.right,a.right),e=Math.min(this.top,a.top),f=Math.max(this.bottom,a.bottom),g=c-b,h=f-e;return d.Rect(b,e,g,h)},fracs:function(){return d.Fractions.ofRect(this)}},d.Rect.ofDocument=function(){return d.Rect(0,0,f.width(),f.height())},d.Rect.ofViewport=function(){return d.Rect(e.scrollLeft(),e.scrollTop(),e.width(),e.height())},d.Rect.ofElement=function(a){var c=b(a),e;return c.is(":visible")?(e=c.offset(),d.Rect(e.left,e.top,c.outerWidth(),c.outerHeight())):d.Rect(0,0,-1,0)}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{};d.Fractions=function(a,b,e,f,g,h){if(this instanceof d.Fractions)!a||!b||!e||!f||!g||!h?(this.rects=c,this.visible=0,this.viewport=0,this.possible=0):(this.rects={document:a,element:b,viewport:e},this.visible=f,this.viewport=g,this.possible=h);else return new d.Fractions(a,b,e,f,g,h)},d.Fractions.prototype={equals:function(a){return this.fracsEqual(a)&&this.rectsEqual(a)},fracsEqual:function(a){return this.visible===a.visible&&this.viewport===a.viewport&&this.possible===a.possible},rectsEqual:function(a){return!this.rects||!a.rects?this.rects===a.rects:this.rects.document.equals(a.rects.document)&&this.rects.element.equals(a.rects.element)&&this.rects.viewport.equals(a.rects.viewport)}},d.Fractions.ofRect=function(a,b){var c,e,f,g,h;return b=b||d.Rect.ofViewport(),c=a.intersection(b),c?(e=d.Rect(c.left-a.left,c.top-a.top,c.width,c.height),f=d.Rect(c.left-b.left,c.top-b.top,c.width,c.height),g=c.area(),h=Math.min(a.width,b.width)*Math.min(a.height,b.height),d.Fractions(c,e,f,g/a.area(),g/b.area(),g/h)):d.Fractions()},d.Fractions.ofElement=function(a,b){return d.Fractions.ofRect(d.Rect.ofElement(a),b)}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{};d.Cursor=function(a,b){if(this instanceof d.Mouse)this.distX=a,this.distY=b,this.distMin=Math.min(a,b),this.distMax=Math.max(a,b);else return new d.Mouse(a,b)},d.Cursor.prototype={equals:function(a){return this.distX===a.distX&&this.distY===a.distY},dist:function(){return Math.sqrt(this.distX*this.distX+this.distY*this.distY)}},d.Cursor.ofRect=function(a,b,c){var e=a<c.left?c.left-a:a>c.right?a-c.right:0,f=b<c.top?c.top-b:b>c.bottom?b-c.bottom:0;return d.Cursor(e,f)},d.Cursor.ofElement=function(a,b,c){return d.Cursor.ofRect(a,b,d.Rect.ofElement(c))}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e=b(a);d.Callbacks=function(){if(this instanceof d.Callbacks)this.callbacks=[];else return new d.Callbacks},d.Callbacks.prototype={size:function(){return this.callbacks.length},bind:function(a){a instanceof Function&&b.inArray(a,this.callbacks)===-1&&this.callbacks.push(a)},unbind:function(a){var c;a instanceof Function?(c=b.inArray(a,this.callbacks),c>=0&&this.callbacks.splice(c,1)):this.callbacks=[]},trigger:function(a,c){b.each(this.callbacks,function(b,d){d.apply(a,c)})}},d.FracsCallbacks=function(a){if(this instanceof d.FracsCallbacks)this.callbacks=[],this.element=a,this.fracs=c,this.prevFracs=c,this.checkProxy=b.proxy(this.check,this),this.autoCheck();else return new d.FracsCallbacks(a)},d.FracsCallbacks.prototype=b.extend({},d.Callbacks.prototype,{trigger:function(){d.Callbacks.prototype.trigger.call(this,this.element,[this.fracs,this.prevFracs])},check:function(){var a=this.element instanceof d.Rect?this.element:d.Rect.ofElement(this.element),b=d.Fractions.ofRect(a);return!this.fracs||!this.fracs.equals(b)?(this.prevFracs=this.fracs,this.fracs=b,this.trigger(),!0):!1},autoCheck:function(a){var b="resize scroll load",c=a===!1?"unbind":"bind";e[c](b,this.checkProxy)}}),d.ScrollStateCallbacks=function(){if(this instanceof d.ScrollStateCallbacks)this.callbacks=[],this.state=c,this.prevState=c,this.checkProxy=b.proxy(this.check,this),this.autoCheck();else return new d.ScrollStateCallbacks},d.ScrollStateCallbacks.prototype=b.extend({},d.Callbacks.prototype,{trigger:function(){d.Callbacks.prototype.trigger.call(this,a,[this.state,this.prevState])},check:function(){var a=d.ScrollState();return!this.state||!this.state.equals(a)?(this.prevState=this.state,this.state=a,this.trigger(),!0):!1},autoCheck:function(a){var b="resize scroll load",c=a===!1?"unbind":"bind";e[c](b,this.checkProxy)}}),d.GroupCallbacks=function(a,e,f){if(this instanceof d.GroupCallbacks)this.callbacks=[],this.group=d.Group(a),this.type=e,this.property=f,this.best=c,this.prevBest=c,this.checkProxy=b.proxy(this.check,this),this.autoCheck();else return new d.GroupCallbacks(a,e,f)},d.GroupCallbacks.prototype=b.extend({},d.Callbacks.prototype,{trigger:function(){d.Callbacks.prototype.trigger.call(this,this.group,[this.best,this.prevBest])},check:function(){var a=this.group[this.type](this.property),b=a.elements.length===0||a.value===0?c:a.elements[0];return!this.best||this.best!==b?(this.prevBest=this.best,this.best=b,this.trigger(),!0):!1},autoCheck:function(a){var b="resize scroll load",c=a===!1?"unbind":"bind";e[c](b,this.checkProxy)}}),d.CursorCallbacks=function(a){if(this instanceof d.CursorCallbacks)this.callbacks=[],this.element=a,this.cursor=c,this.prevCursor=c,this.checkProxy=b.proxy(this.check,this),this.autoCheck();else return new d.CursorCallbacks(a)},d.CursorCallbacks.prototype=b.extend({},d.Callbacks.prototype,{trigger:function(){d.Callbacks.prototype.trigger.call(this,this.element,[this.cursor,this.prevCursor])},check:function(a){var b=d.Cursor.ofElement(a.pageX,a.pageY,this.element);return!this.cursor||!this.cursor.equals(b)?(this.prevCursor=this.cursor,this.cursor=b,this.trigger(),!0):!1},autoCheck:function(a){var b="cursormove",c=a===!1?"unbind":"bind";e[c](b,this.checkProxy)}})}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e=b(a),f=b("html,body");d.ScrollState=function(a,b,e,f,g,h){if(!(this instanceof d.ScrollState))return new d.ScrollState;var i=d.Rect.ofDocument(),j=d.Rect.ofViewport(),k=i.width-j.width,l=i.height-j.height;this.width=a||k<=0?c:j.left/k,this.height=b||l<=0?c:j.top/l,this.left=e||j.left,this.top=f||j.top,this.right=g||i.right-j.right,this.bottom=h||i.bottom-j.bottom},d.ScrollState.prototype={equals:function(a){return this.width===a.width&&this.height===a.height&&this.left===a.left&&this.top===a.top&&this.right===a.right&&this.bottom===a.bottom}},d.ScrollState.scrollTo=function(a,b,c){c=isNaN(c)?1e3:c,f.stop(!0).animate({scrollLeft:a,scrollTop:b},c)},d.ScrollState.scroll=function(a,b,c){d.ScrollState.scrollTo(e.scrollLeft()+a,e.scrollTop()+b,c)},d.ScrollState.scrollToRect=function(a,b,c,e){b=b||0,c=c||0,d.ScrollState.scrollTo(a.left-b,a.top-c,e)},d.ScrollState.scrollToElement=function(a,b,c,e){var f=d.Rect.ofElement(a);d.ScrollState.scrollToRect(f,b,c,e)}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{};d.Element=function(a){if(this instanceof d.Element)this.element=a,this.fracs=c,this.prevFracs=c,this.rect=c,this.prevRect=c,this.update();else return new d.Element(a)},d.Element.prototype={update:function(){var a=d.Fractions.ofElement(this.element),b=d.Rect.ofElement(this.element),c=!1;if(!this.fracs||!this.fracs.equals(a))this.prevFracs=this.fracs,this.fracs=a,c=!0;if(!this.rect||!this.rect.equals(b))this.prevRect=this.rect,this.rect=b,c=!0;return c}}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e=["possible","visible","viewport"],f=["width","height","left","right","top","bottom"],g=function(a){if(b.inArray(a,e)>=0)return"fracs";if(b.inArray(a,f)>=0)return"rect"},h=function(a,b){return a>b},i=function(a,b){return a<b},j=function(a,d,e){var f,h,i=g(d);return i?(b.each(a,function(a,b){var g;b.update(),g=i==="fracs"?b.fracs[d]:b.rect[d],h===c||e(g,h)?(f=[b],h=g):g===h&&f.push(b)}),{elements:f,value:h}):{elements:[],value:c}},k=function(a){var c=[];return b.each(a,function(a,b){c.push(d.Element(b))}),c},l=function(a){var c=[];return b.each(a,function(a,b){c.push(b.element)}),c};d.Group=function(a){if(this instanceof d.Group)this.elements=k(a);else return new d.Group(a)},d.Group.prototype={max:function(a,b){var c=j(this.elements,a,h);return b===!0?l(c.elements):c},min:function(a,b){var c=j(this.elements,a,i);return b===!0?l(c.elements):c}}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e,f="fracs",g={document:function(){return d.Rect.ofDocument()},fracs:function(a,b){return d.Fractions.ofRect(a,b)},rect:function(a){return d.Rect.ofElement(a)},round:function(a,b){var c;return isNaN(b)||b<=0?Math.round(a):(c=Math.pow(10,b),Math.round(a*c)/c)},scroll:function(a,b,c){return d.ScrollState.scroll(a,b,c),this},scrollState:function(a){return a?(e=e||d.ScrollStateCallbacks(),e.bind(a),this):d.ScrollState()},scrollTo:function(a,b,c){return d.ScrollState.scrollTo(a,b,c),this},viewport:function(){return d.Rect.ofViewport()}},h={bind:function(a){return this.each(function(){var c=b(this),e=c.data(f);e||(e=d.FracsCallbacks(this),c.data(f,e)),e.bind(a)})},check:function(){return this.each(function(){var a=b(this).data(f);a&&a.check()})},cursor:function(a,b){return a instanceof Function?this.each(function(){d.CursorCallbacks(this).bind(a)}):d.Cursor.ofElement(a,b,this.get(0))},envelope:function(){var a,b;return this.each(function(){b=d.Rect.ofElement(this),a=a?a.envelope(b):b}),a},fracs:function(){return d.Fractions.ofElement(this.get(0))},max:function(a,c){return c?(d.GroupCallbacks(this,"max",a).bind(c),this):b(d.Group(this).maxHtmlElements(a))},min:function(a,c){return c?(d.GroupCallbacks(this,"min",a).bind(c),this):b(d.Group(this).minHtmlElements(a))},rect:function(){return d.Rect.ofElement(this.get(0))},softLink:function(a,c,e){return this.filter("a[href^=#]").each(function(){var f=b(this);f.click(function(){d.ScrollState.scrollToElement(b(f.attr("href")).get(0),a,c,e)})})},scrollTo:function(a,b,c){return d.ScrollState.scrollToElement(this.get(0),a,b,c),this},unbind:function(a){return this.each(function(){var c=b(this),d=c.data(f);d&&d.unbind(a)})}},i=function(){return"fracs"},j=function(){if(arguments.length===0)return"fracs";if(arguments[0]instanceof Function)return"bind"};b.ModPlug.plugin("fracs",{statics:g,methods:h,defaultStatic:i,defaultMethod:j})}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e=b(a),f=b("html,body"),g={crop:!1,duration:0,focusWidth:.5,focusHeight:.5,autoFocus:!0,styles:[{selector:"header,footer,section,article",fillStyle:"rgb(230,230,230)"},{selector:"h1",fillStyle:"rgb(240,140,060)"},{selector:"h2",fillStyle:"rgb(200,100,100)"},{selector:"h3",fillStyle:"rgb(100,200,100)"},{selector:"h4",fillStyle:"rgb(100,100,200)"}],viewportStyle:{fillStyle:"rgba(228,77,38,0.3)"},viewportDragStyle:{fillStyle:"rgba(228,77,38,0.6)"},invertViewport:!1};d.Outline=function(a,h){if(!(this instanceof d.Outline))return new d.Outline(a,h);if(!a.nodeName||a.nodeName.toLowerCase()!=="canvas")return c;var i=b.extend({},g,h),j=b(a),k=j.attr("width"),l=j.attr("height"),m=a.getContext("2d"),n=!1,o,p,q,r,s,t=function(a,b,c,d,e){if(c||d)d&&(m.beginPath(),e?(m.rect(0,0,o.width,a.top),m.rect(0,a.top,a.left,a.height),m.rect(a.right,a.top,o.right-a.right,a.height),m.rect(0,a.bottom,o.width,o.bottom-a.bottom)):m.rect(a.left,a.top,a.width,a.height),m.fillStyle=d,m.fill()),c&&(m.beginPath(),m.rect(a.left,a.top,a.width,a.height),m.lineWidth=q?Math.max(b,.2/q):b,m.strokeStyle=c,m.stroke())},u=function(a,c,e,f){var g=b(a),h=d.Rect.ofElement(a);if(g.css("visibility")==="hidden"||h.width===0||h.height===0)return;c=c==="auto"?parseInt(g.css("border-top-width"),10):c,e=e==="auto"?g.css("border-top-color"):e,f=f==="auto"?g.css("background-color"):f,t(h,c,e,f)},v=function(){b.each(i.styles,function(a,c){b(c.selector).each(function(){u(this,c.strokeWidth,c.strokeStyle,c.fillStyle)})})},w=function(){var a=n&&i.viewportDragStyle?i.viewportDragStyle:i.viewportStyle;t(p,a.strokeWidth,a.strokeStyle,a.fillStyle,i.invertViewport)},x=function(){o=d.Rect.ofDocument(),p=d.Rect.ofViewport(),q=Math.min(k/o.width,l/o.height),i.crop&&j.attr("width",o.width*q).attr("height",o.height*q),m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,j.width(),j.height()),m.scale(q,q),v(),w()},y=function(a){var b=j.fracs("rect"),c=a.pageX-b.left,e=a.pageY-b.top;d.ScrollState.scrollTo(c/q-p.width*r,e/q-p.height*s,i.duration)},z=function(a){n=!1,a.preventDefault(),j.css("cursor","pointer").removeClass("dragOn"),f.css("cursor","auto"),e.unbind("mousemove",y),x()},A=function(a){var b;i.autoFocus&&(b=j.fracs("rect"),r=((a.pageX-b.left)/q-p.left)/p.width,s=((a.pageY-b.top)/q-p.top)/p.height);if(!i.autoFocus||r<0||r>1||s<0||s>1)r=i.focusWidth,s=i.focusHeight;n=!0,a.preventDefault(),j.css("cursor","crosshair").addClass("dragOn"),f.css("cursor","crosshair"),e.bind("mousemove",y).one("mouseup",z),y(a)},B=function(){j.css("cursor","pointer").mousedown(A),e.bind("load resize scroll",x),x()};B(),this.redraw=x}}(window,jQuery),function(a,b,c){var d=a.Fracs=a.Fracs||{},e="outline",f={outline:function(a){return this.each(function(){var c;a==="redraw"?(c=b(this).data(e),c&&c.redraw()):(c=d.Outline(this,a),c&&b(this).data(e,c))})}};b.ModPlug.module("fracs",{methods:f})}(window,jQuery)
