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