/*
 
	Awkward Showcase - jQuery plugin 
	http://www.jquery.com
	http://www.awkwardgroup.com/sandbox/awkward-showcase-a-jquery-plugin
	http://demo.awkwardgroup.com/showcase
	Version: 1.1.1

	Copyright (C) 2011 Awkward Group (http://www.awkwardgroup.com)
	Licensed under Attribution-ShareAlike 3.0 Unported
	http://creativecommons.org/licenses/by-sa/3.0/

	Markup example for jQuery("#showcase").awShowcase();
 
	<div id="showcase" class="showcase">
		<!-- Each child div in #showcase represents a slide -->
		<div class="showcase-slide">
			<!-- Put the slide content in a div with the class .showcase-content -->
			<div class="showcase-content">
				<!-- If the slide contains multiple elements you should wrap them in a div with the class .showcase-content-wrapper. 
				We usually wrap even if there is only one element, because it looks better. :-) -->
				<div class="showcase-content-wrapper">
					<img src="images/01.jpg" alt="01" />
				</div>
			</div>
			<!-- Put the caption content in a div with the class .showcase-caption -->
			<div class="showcase-caption">
				The Caption
			</div>
			<!-- Put the tooltips in a div with the class .showcase-tooltips. -->
			<div class="showcase-tooltips">
				<!-- Each anchor in .showcase-tooltips represents a tooltip. The coords attribute represents the position of the tooltip. -->
				<a href="http://www.awkward.se" coords="634,130">
					<!-- The content of the anchor-tag is displayed in the tooltip. -->
					This is a tooltip that displays the anchor html in a nice way.
				</a>
				<a href="http://www.awkward.se" coords="356, 172">
					<!-- You can add multiple elements to the anchor-tag which are display in the tooltip. -->
					<img src="images/glasses.png" />
					<span style="display: block; font-weight: bold; padding: 3px 0 3px 0; text-align: center;">
						White Glasses: 500$
					</span>
				</a>
			</div>
		</div>
		<div class="showcase-slide">
			<div class="showcase-content">
				<div class="showcase-content-wrapper">
					Content...
				</div>
			</div>
		</div>
	</div>

*/

(function(b){b.fn.awShowcase=function(a){function L(g){g=b(document.createElement("div")).attr("id","showcase-content-"+g).css("overflow","hidden").css("position","absolute").addClass("showcase-content").html(P[g]);a.viewline||g.css("width",a.content_width);a.fit_to_parent&&!a.viewline&&g.css("left",w/2-a.content_width/2);return g}function R(){var b=parseInt(e)+1;b===n&&a.continuous?b=0:b!==n||a.continuous||(M=!0,clearInterval(l));M||A(b,"next")}function A(g,f){if(e!==g&&!C){var d,c,s=0,h,m=a.fit_to_parent?
w/2-a.content_width/2:0;if(g>e&&"previous"!==f||"next"===f)if(a.viewline){if(e<n-1){a.speed_change||(C=!0);S();a.pauseonover&&window.clearInterval(l);G=0;h=e+1;for(len=n;h<len;++h)d=N[h],G+=d.find(".showcase-content").children().width();G>w?(H=E,E-=N[e].find(".showcase-content").children().width()):b(".showcase-arrow-next").is(":visible")&&(H=E,E=-(J-(G+(w-G))),b(".showcase-arrow-next").fadeOut(300));r.animate({left:E+"px"},a.transition_speed,function(){C=!1});b(".showcase-arrow-next").is(":visible")&&
e++;b(".showcase-arrow-previous").fadeIn(300)}}else a.speed_change||(C=!0),d=b(k).find("#showcase-content-"+parseInt(e)),c=L(g),r.append(c),a.dynamic_height?c.css("height",c.find(".showcase-content").children().height()):c.css("height",a.content_height),d.find(".showcase-content").children().height()>c.find(".showcase-content").children().height()&&a.dynamic_height&&(r.stop(!0,!0).animate({height:c.find(".showcase-content").children().height()},200),s=100),"hslide"===a.transition?b(d).delay(s).animate({left:-a.content_width},
a.transition_speed+a.transition_delay,function(){d.remove()}):"vslide"===a.transition?b(d).delay(s).animate({top:-a.content_height},a.transition_speed+a.transition_delay,function(){d.remove()}):b(d).delay(s).fadeOut(a.transition_speed,function(){d.remove()}),t(d,!0),u(d,!0),"hslide"===a.transition?(c.css("left",w),b(c).delay(s).animate({left:m},a.transition_speed,function(){t(c);u(c);I(c)})):"vslide"===a.transition?(c.css("top",k.height()),b(c).delay(s).animate({top:"0px"},a.transition_speed,function(){t(c);
u(c);I(c)})):(c.css("left",m),c.css("display","none"),b(c).delay(s).fadeIn(a.transition_speed,function(){t(c);u(c);I(c)}));else if(g<e||"previous"===f)a.viewline?(0!==e&&(a.speed_change||(C=!0),S(),a.pauseonover&&window.clearInterval(l),r.animate({left:H+"px"},a.transition_speed,function(){C=!1}),E=H,e--,0===e&&b(".showcase-arrow-previous").fadeOut(300),old_id=e-1,sub_width=b(N[old_id]).width(),H+=sub_width),b(".showcase-arrow-next").fadeIn(300)):(a.speed_change||(C=!0),d=b(k).find("#showcase-content-"+
parseInt(e)),c=L(g),r.append(c),a.dynamic_height?c.css("height",c.find(".showcase-content").children().height()):c.css("height",a.content_height),d.find(".showcase-content").children().height()>c.find(".showcase-content").children().height()&&a.dynamic_height&&(r.stop(!0,!0).animate({height:c.find(".showcase-content").children().height()},200),s=100),"hslide"===a.transition?b(d).delay(s).animate({left:w+"px"},a.transition_speed+a.transition_delay,function(){t(d,!0);u(d,!0);d.remove()}):"vslide"===
a.transition?b(d).delay(s).animate({top:a.content_height+"px"},a.transition_speed+a.transition_delay,function(){t(d,!0);u(d,!0);d.remove()}):b(d).delay(s).fadeOut(a.transition_speed,function(){t(d,!0);u(d,!0);d.remove()}),"hslide"===a.transition?(c.css("left","-"+a.content_width+"px"),b(c).delay(s).animate({left:m},a.transition_speed,function(){t(c);u(c);I(c)})):"vslide"===a.transition?(c.css("top","-"+k.height()+"px"),b(c).delay(s).animate({top:"0px"},a.transition_speed,function(){t(c);u(c);I(c)})):
(c.css("left",m),c.css("display","none"),b(c).delay(s).fadeIn(a.transition_speed,function(){t(c);u(c);I(c)})),r.append(c));a.viewline||(Q=e,e=g,a.thumbnails&&(e>Q&&"previous"!==f||"next"===f?O("forward",!0):(e<Q||"previous"===f)&&O("backward",!0)),a.arrows&&(b(k).find(".showcase-arrow-previous").unbind("click").click(function(){l&&(a.stoponclick&&(B=!0),clearInterval(l));A(0===e?n-1:parseInt(e)-1,"previous")}),b(k).find(".showcase-arrow-next").unbind("click").click(function(){l&&(a.stoponclick&&(B=
!0),clearInterval(l));A(e===n-1?0:parseInt(e)+1,"next")})),a.thumbnails&&(h=0,k.find(".showcase-thumbnail").each(function(){var a=b(this);a.removeClass("active");h===e&&a.addClass("active");h++})),"show"===a.show_caption&&b(c).find(".showcase-caption").show());a.buttons&&(h=0,k.find(".showcase-button-wrapper span").each(function(){var a=b(this);a.removeClass("active");h===e&&a.addClass("active");h++}));"function"==typeof a.custom_function&&a.custom_function()}}function I(b){a.dynamic_height&&r.stop(!0,
!0).animate({height:b.find(".showcase-content").children().height()},200);C=!1}function O(g,f,d){var c=!0,h=y(b(m).find(".showcase-thumbnail"));"horizontal"===a.thumbnails_direction&&(h=x(b(m).find(".showcase-thumbnail")));var k=1;0===a.thumbnails_slidex&&(a.thumbnails_slidex=K);if(f){var l=q;for(f=0;0>l;)l="horizontal"===a.thumbnails_direction?l+x(b(D[0])):l+y(b(D[0])),f++;l=f;f=K+f-1;e>=l&&e<=f&&(c=!1);if(e-f>a.thumbnails_slidex)for(f=e-f;f>a.thumbnails_slidex;)f-=a.thumbnails_slidex,k++;else if(l-
e>a.thumbnails_slidex)for(f=l-e;f>a.thumbnails_slidex;)f-=a.thumbnails_slidex,k++;else k=1}"forward"===g&&c?("vertical"===a.thumbnails_direction&&a.content_height<F+q?q-=h*a.thumbnails_slidex*k:"horizontal"===a.thumbnails_direction&&a.content_width<F+q?q-=h*a.thumbnails_slidex*k:0===e&&(d||(q=0)),"horizontal"===a.thumbnails_direction?m.animate({left:q},300):m.animate({top:q},300)):c&&(0>q?q+=h*a.thumbnails_slidex*k:e===n-1?d||(q-=h*a.thumbnails_slidex*k):q=0,"horizontal"===a.thumbnails_direction?
m.animate({left:q},300):m.animate({top:q},300))}function u(g,f){var d=g.find(".showcase-caption");f?d.stop(!0,!0).fadeOut(300):"onload"===a.show_caption?d.fadeIn(300):"onhover"===a.show_caption&&(b(g).mouseenter(function(){d.fadeIn(300)}),b(g).mouseleave(function(){d.stop(!0,!0).fadeOut(100)}))}function t(g,f){g.find(".showcase-tooltips a").each(function(){if(f)b(this).stop(!0,!0).fadeOut(300);else{var d=b(this).attr("coords"),d=d.split(",");b(this).addClass("showcase-plus-anchor");b(this).css("position",
"absolute");b(this).css("display","none");b(this).css("width",a.tooltip_icon_width);b(this).css("height",a.tooltip_icon_height);b(this).css("left",parseInt(d[0])-parseInt(a.tooltip_icon_width)/2);b(this).css("top",parseInt(d[1])-parseInt(a.tooltip_icon_height)/2);var c=b(this).html();b(this).mouseenter(function(){T(g,d[0],d[1],c)});b(this).mouseleave(function(){T(g,d[0],d[1],c)});b(this).html("");b(this).fadeIn(300)}})}function T(g,f,d,c){null===p?(p=b(document.createElement("div")).addClass("showcase-tooltip").css("display",
"none").css("position","absolute").css("max-width",a.tooltip_width).html(c),g.append(p),g=2*parseInt(p.css("padding-right"))+2*parseInt(p.css("border-right-width")),c=2*parseInt(p.css("padding-bottom"))+2*parseInt(p.css("border-bottom-width")),lastx=parseInt(f)+p.width()+g,lasty=parseInt(d)+p.height()+c,lastx<a.content_width?p.css("left",parseInt(f)+parseInt(a.tooltip_offsetx)):p.css("left",parseInt(f)-parseInt(a.tooltip_offsetx)-(parseInt(p.width())+parseInt(a.tooltip_offsetx))),lasty<a.content_height?
p.css("top",parseInt(d)+parseInt(a.tooltip_offsety)):p.css("top",parseInt(d)-parseInt(a.tooltip_offsety)-(parseInt(p.height())+parseInt(c))),p.fadeIn(400)):(p.fadeOut(400),p.remove(),p=null)}function y(a,f,d,c,e){d="undefined"!==typeof d?d:!0;c="undefined"!==typeof c?c:!0;e="undefined"!==typeof e?e:!0;f=("undefined"!==typeof f?f:1)?b(a).height():0;d=d?parseFloat(b(a).css("margin-top"))+parseFloat(b(a).css("margin-bottom")):0;c=c?parseFloat(b(a).css("padding-top"))+parseFloat(b(a).css("padding-bottom")):
0;a=e?parseFloat(b(a).css("border-top-width"))+parseFloat(b(a).css("border-bottom-width")):0;return f+(d+c+a)}function x(a,f,d,c,e){d="undefined"!==typeof d?d:!0;c="undefined"!==typeof c?c:!0;e="undefined"!==typeof e?e:!0;f=("undefined"!==typeof f?f:1)?b(a).width():0;d=d?parseFloat(b(a).css("margin-left"))+parseFloat(b(a).css("margin-right")):0;c=c?parseFloat(b(a).css("padding-left"))+parseFloat(b(a).css("padding-right")):0;a=e?parseFloat(b(a).css("border-left-width"))+parseFloat(b(a).css("border-right-width")):
0;return f+(d+c+a)}function S(){J=0;r.children("div").each(function(){J+=b(this).find(".showcase-content").children().width();N.push(b(this))})}a=b.extend({content_width:938,content_height:360,fit_to_parent:!1,auto:!1,interval:3E3,continuous:!1,loading:!0,tooltip_width:200,tooltip_icon_width:32,tooltip_icon_height:32,tooltip_offsetx:18,tooltip_offsety:0,arrows:!0,buttons:!0,btn_numbers:!1,keybord_keys:!1,mousetrace:!1,pauseonover:!0,stoponclick:!0,transition:"hslide",transition_delay:300,transition_speed:500,
show_caption:"onload",thumbnails:!1,thumbnails_position:"outside-last",thumbnails_direction:"vertical",thumbnails_slidex:0,dynamic_height:!1,speed_change:!1,viewline:!1,fullscreen_width_x:15,custom_function:null},a);var e=0,Q=0,M=!1,B=!1,l=null,k=b(this),w=a.content_width,C=!1,J=1E4,E=0,H=0,G=0,r=b(document.createElement("div")).css("overflow","hidden").css("position","relative").addClass("showcase-content-container").prependTo(k);a.fit_to_parent&&(w=b(k).width()+a.fullscreen_width_x);a.viewline&&
(a.thumbnails=!1,a.dynamic_height=!1,r.css("width",J),k.css("overflow","hidden"),$(".showcase-arrow-previous").hide());var P=[],D=[],n=0;k.children(".showcase-slide").each(function(){var g=b(this);n++;if(a.thumbnails){var f=g.find(".showcase-thumbnail");D.push(f);f.remove()}var f=g.find(".showcase-content").children().width(),d=g.find(".showcase-content").children().height();P.push(g.html());g.remove();g=L(n-1);(a.viewline||1===n)&&r.append(g);a.viewline&&(g.css("position","relative"),g.css("float",
"left"),g.css("width",f));a.dynamic_height?(g.css("height",d),1===n&&r.css("height",d)):(g.css("height",a.content_height),1===n&&r.css("height",a.content_height));if(a.viewline||1===n)t(g),u(g),"show"===a.show_caption&&b(g).find(".showcase-caption").show()});var m,F=0,K=0;if(a.thumbnails){thumb_container=b("<div />");thumb_restriction=b("<div />");m=b("<div />");for(i=D.length-1;0<=i;--i){var h=b(D[i]).css({overflow:"hidden"});h.attr("id","showcase-thumbnail-"+i);h.addClass(0===i?"active":"");h.click(function(a,
b){return function(){l&&(B=!0,clearInterval(l));A(a,b)}}(i,""));m.prepend(h)}"outside-first"===a.thumbnails_position||"outside-last"===a.thumbnails_position?("horizontal"!==a.thumbnails_direction?(r.css("float","left"),r.css("width",a.content_width),thumb_container.css("float","left"),thumb_container.css("height",a.content_height)):b(m).find(".showcase-thumbnail").css("float","left"),"outside-last"===a.thumbnails_position?k.append(thumb_container):k.prepend(thumb_container),"horizontal"!==a.thumbnails_direction&&
k.append(b("<div />").addClass("clear"))):(thumb_container.css({position:"absolute","z-index":20}),"horizontal"===a.thumbnails_direction?(thumb_container.css({left:0,right:0}),b(m).find(".showcase-thumbnail").css("float","left"),b(m).append(b("<div />").addClass("clear")),"inside-first"===a.thumbnails_position?thumb_container.css("top",0):thumb_container.css("bottom",0)):(thumb_container.css({top:0,bottom:0}),"inside-first"===a.thumbnails_position?thumb_container.css("left",0):thumb_container.css("right",
0)),r.prepend(thumb_container));thumb_container.addClass("showcase-thumbnail-container");thumb_container.css("overflow","hidden");thumb_restriction.addClass("showcase-thumbnail-restriction");thumb_restriction.css({overflow:"hidden",position:"relative"});"horizontal"===a.thumbnails_direction&&thumb_restriction.css({"float":"left"});m.addClass("showcase-thumbnail-wrapper");"horizontal"===a.thumbnails_direction?m.addClass("showcase-thumbnail-wrapper-horizontal"):m.addClass("showcase-thumbnail-wrapper-vertical");
m.css("position","relative");thumb_restriction.append(m);thumb_container.append(thumb_restriction);h=b('<div class="showcase-thumbnail-button-backward" />');"horizontal"!==a.thumbnails_direction?h.html('<span class="showcase-thumbnail-vertical"><span>Up</span></span>'):(h.css({"float":"left"}),h.html('<span class="showcase-thumbnail-horizontal"><span>Left</span></span>'));h.click(function(){O("backward",!1,!0)});thumb_container.prepend(h);var z=b('<div class="showcase-thumbnail-button-forward" />');
"horizontal"!==a.thumbnails_direction?z.html('<span class="showcase-thumbnail-vertical"><span>Down</span></span>'):(z.css({"float":"left"}),z.html('<span class="showcase-thumbnail-horizontal"><span>Right</span></span>'));z.click(function(){O("forward",!1,!0)});thumb_container.append(z);var v=0;if("horizontal"!==a.thumbnails_direction)for(v=y(m,!1),v+=y(h)+y(z);v<a.content_height;)v+=y(b(D[0])),K++;else for(v=x(m,!1),v+=x(h)+x(z);v<w;)v+=x(b(D[0])),K++;K+1>D.length&&("horizontal"!==a.thumbnails_direction?
thumb_restriction.css("margin-top",y(h)):thumb_restriction.css("margin-left",x(h)),h.hide(),z.hide());"horizontal"!==a.thumbnails_direction?(h=y(h)+y(z),thumb_restriction.css("height",a.content_height-h)):(h=x(h)+x(z),thumb_restriction.css("width",w-h));"horizontal"===a.thumbnails_direction?(b(".showcase-thumbnail").each(function(){F+=x(b(this))}),m.css("width",F)):b(".showcase-thumbnail").each(function(){F+=y(b(this))})}a.thumbnails&&-1!==a.thumbnails_position.indexOf("outside")&&"horizontal"!==
a.thumbnails_direction&&!a.viewline?k.css("width",w+x(m,!0,!1)):a.fit_to_parent||k.css("width",w);1<n&&a.auto&&(l=window.setInterval(R,a.interval));a.auto&&a.pauseonover&&(k.mouseenter(function(){M=!0;clearInterval(l)}),k.mouseleave(function(){B||(M=!1,l=window.setInterval(R,a.interval))}));a.arrows&&1<n&&(b(document.createElement("div")).addClass("showcase-arrow-previous").prependTo(k).click(function(){l&&(a.stoponclick&&(B=!0),clearInterval(l));A(0===e?n-1:parseInt(e)-1,"previous")}),b(document.createElement("div")).addClass("showcase-arrow-next").prependTo(k).click(function(){l&&
(a.stoponclick&&(B=!0),clearInterval(l));A(e+1,"next")}),a.viewline&&b(".showcase-arrow-previous").hide());if(a.buttons&&1<n)for(b(document.createElement("div")).css("clear","both").addClass("showcase-button-wrapper").appendTo(k),i=0;i<n;)b(document.createElement("span")).attr("id","showcase-navigation-button-"+i).addClass(0===i?"active":"").html(a.btn_numbers?parseInt(i)+1:"&#9679;").click(function(b,f){return function(){l&&(a.stoponclick&&(B=!0),clearInterval(l));A(b,f)}}(i,"")).appendTo(b(k).find(".showcase-button-wrapper")),
i++;a.keybord_keys&&b(document).keydown(function(b){a.stoponclick&&(B=!0);l&&clearInterval(l);37===b.keyCode&&A(0===e?n-1:parseInt(e)-1,"previous");39===b.keyCode&&A(e===n-1?0:parseInt(e)+1,"next")});var q=0,p=null;if(a.mousetrace){var U=b(document.createElement("div")).css("position","absolute").css("top","0").css("background-color","#fff").css("color","#000").css("padding","3px 5px").css("x-index","30").html("X: 0 Y: 0");k.append(U);var V=k.offset();r.mousemove(function(a){U.html("X: "+(a.pageX-
V.left)+" Y: "+(a.pageY-V.top))})}b("#awOnePageButton").click(function(){if(b(".view-page").is(":visible")){var e=b(document.createElement("div"));e.addClass("showcase-onepage");k.before(e);l&&(B=!0,clearInterval(l));b(this).find(".view-page").hide();b(this).find(".view-slide").show();k.hide();$.each(P,function(b,c){obj=L(b);obj.css("position","relative");e.append(obj);t(obj);u(obj);a.dynamic_height?obj.css("height",obj.find(".showcase-content").children().height()):obj.css("height",a.content_height)});
var f=b(document.createElement("div"));f.addClass("clear");e.append(f)}else b(".showcase-onepage").remove(),b(this).find(".view-page").show(),b(this).find(".view-slide").hide(),k.show();return!1});var N=[];k.removeClass("showcase-load")}})(jQuery);