/*! Chaperone.js - v1.0.3 - 2013-01-17
* http://darkliquid.github.com/chaperone.js
* Copyright (c) 2013 Andrew Montgomery-Hurrell; Licensed MIT, GPL */
(function(e,t){function n(t,n){var r=n.data("target")||n.prev().data("target"),i=t.data("chaperone"),s=e.extend(e(i.keepInsideBoundary).offset()||{top:0,left:0},{width:e(i.keepInsideBoundary).width(),height:e(i.keepInsideBoundary).height()});if(r){var o=e(""+r),u=e.extend(o.offset()||{top:0,left:0},{width:o.width(),height:o.height()}),a=n.width(),f=n.height(),l=a+i.margin*2-u.width,c=f+i.margin*2-u.height;n.removeClass("top").removeClass("bottom").removeClass("left").removeClass("right");switch(n.data("placement")){case"top":n.addClass("top"),n.css("top",parseInt(u.top-f-i.margin,10)),u.left-l>s.left?n.css("left",parseInt(u.left-l/2+i.margin,10)):n.css("left",parseInt(s.left+i.margin,10));break;case"bottom":n.addClass("bottom"),n.css("top",parseInt(u.top+u.height+i.margin,10)),u.left-l>s.left?n.css("left",parseInt(u.left-l/2+i.margin,10)):n.css("left",parseInt(s.left+i.margin,10));break;case"left":n.addClass("left"),n.css("left",parseInt(u.left-a-i.margin,10)),u.top-c>s.top?n.css("top",parseInt(u.top-c/2+i.margin,10)):n.css("top",parseInt(s.top+i.margin,10));break;case"right":n.addClass("right"),n.css("left",parseInt(u.left+u.width+i.margin,10)),u.top-c>s.top?n.css("top",parseInt(u.top-c/2+i.margin,10)):n.css("top",parseInt(s.top+i.margin,10));break;default:var h=!1;u.top-(f+i.margin)>s.top?(n.css("top",parseInt(u.top-(f+i.margin),10)),n.addClass("top"),h=!0):u.top+u.height+f+i.margin<s.top+s.height?(n.css("top",parseInt(u.top+u.height+i.margin,10)),n.addClass("bottom"),h=!0):u.top-c>s.top?n.css("top",parseInt(u.top-c/2+i.margin,10)):n.css("top",parseInt(s.top+i.margin,10)),a<u.width?n.css("left",parseInt(u.left-l/2+i.margin,10)):!h&&u.left-(a+i.margin)>s.left?(n.css("left",parseInt(u.left-(a+i.margin),10)),n.addClass("left")):!h&&u.left+u.width+a+i.margin<s.left+s.width?(n.css("left",parseInt(u.left+u.width+i.margin,10)),n.addClass("right")):u.left-l>s.left?n.css("left",parseInt(u.left-l/2+i.margin,10)):n.css("left",parseInt(s.left+i.margin,10))}}}function r(t,r){n(t,r),r.show(),t.data("chaperone").animate&&e("html, body").animate({scrollTop:r.offset().top-e(window).height()/2,scrollLeft:r.offset().left-e(window).width()/2}),t.trigger("showstep.chaperone",[r.get(0),r.data("target")])}function i(e,t){t.hide(),e.trigger("hidestep.chaperone",[t.get(0),t.data("target")])}var s={init:function(t){return t=e.extend({},e.fn.chaperone.defaults,t),this.each(function(){var n=e(this),r=e("body"),i=n.data("chaperone");if(typeof i=="undefined"){i=e.extend({},t),i.container=e('<div class="chaperone-steps" style="display: none;"></div>'),r.append(i.container),n.data("chaperone",i),n.addClass("chaperoned").hide(),n.find(i.step).each(function(t,n){var r=e(i.template),s=e(n),o=e.extend({},i.steps,s.data()),u=s.html();o.title?r.find(".title").html(o.title):r.find(".title").remove(),r.find(".content").html(u),r.hide(),r.data(o),i.container.append(r)}),i.container.on("click.chaperone",".next-chaperone",function(){n.chaperone("next")}),i.container.on("click.chaperone",".prev-chaperone",function(){n.chaperone("prev")}),i.container.on("click.chaperone",".close-chaperone",function(){n.chaperone("stop")});if(i.repositionOnResize){var s=null;i._resize=function(){clearTimeout(s),s=setTimeout(function(){n.chaperone("reposition")},50)},e(window).on("resize",i._resize)}}})},start:function(){return this.each(function(){var t=e(this),n=t.data("chaperone"),i=n.container;e(".chaperone-steps").hide(),t.trigger("started.chaperone"),r(t,i.show().children().hide().eq(0))})},stop:function(){return this.each(function(){var t=e(this),n=t.data("chaperone"),r=n.container,s=r.children(":visible");i(t,s),r.hide(),t.trigger("stopped.chaperone")})},destroy:function(){return this.each(function(){var t=e(this),n=t.data("chaperone");if(!n)return;var r=n.container,s=r.children(":visible");n.repositionOnResize&&e(window).off("resize",n._resize),i(t,s),r.remove(),t.trigger("stopped.chaperone"),t.removeData("chaperone"),t.removeClass("chaperoned"),t.trigger("destroyed.chaperone"),t.show()})},next:function(){return this.each(function(){var t=e(this),n=t.data("chaperone"),s=n.container,o=s.children(":visible"),u=o.next();u.length===0&&(u=s.children().first()),i(t,o),r(t,u)})},prev:function(){return this.each(function(){var t=e(this),n=t.data("chaperone"),s=n.container,o=s.children(":visible"),u=o.prev();u.length===0&&(u=s.children().last()),i(t,o),r(t,u)})},reposition:function(){return this.each(function(){var t=e(this),r=t.data("chaperone"),i=r.container,s=i.children(":visible");n(t,s),t.trigger("repositioned.chaperone")})},settings:function(){return this.length>1?this.map(function(){return e(this).data("chaperone")}):this.first().data("chaperone")}};e.fn.chaperone=function(t){if(s[t])return s[t].apply(this,Array.prototype.slice.call(arguments,1));if(typeof t=="object"||!t)return s.init.apply(this,arguments);e.error("Method "+t+" does not exist on jQuery.chaperone")},e.fn.chaperone.defaults={step:"li",steps:{placement:"auto"},animate:!0,margin:10,template:['<div class="chaperone">','<div class="arrow"></div>','<a class="close-chaperone">&times;</a>','<div class="content-wrapper">','<h4 class="title">Title</h4>','<div class="content">Content</div>','<a class="prev-chaperone">Previous</a>','<a class="next-chaperone">Next</a>',"</div>","</div>"].join(""),keepInsideBoundary:document,repositionOnResize:!0}})(jQuery);