
// 'stacks' is the Stacks global object.
// All of the other Stacks related Javascript will 
// be attatched to it.
var stacks = {};


// this call to jQuery gives us access to the globaal
// jQuery object. 
// 'noConflict' removes the '$' variable.
// 'true' removes the 'jQuery' variable.
// removing these globals reduces conflicts with other 
// jQuery versions that might be running on this page.
stacks.jQuery = jQuery.noConflict(true);

// Javascript for stacks_in_655_page0
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_655_page0 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_655_page0 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
//-- Gyro Stack v1.2 by Joe Workman --//

$(document).ready(function() {

	// Create the ribbon HTML
	createPager = function(){	
        $("#stacks_in_655_page0 .gyro_image_reel img").each(function(index) {
            $('<a href="#" rel="' + (index+1) + '">' + (index+1) + '</a>').appendTo('#stacks_in_655_page0 div.gyro_ribbon_middle');
        });
		// Need to swap the bragrounds when the ribbon is on the left
		if ('right' == 'left') {
			$('#stacks_in_655_page0 .gyro_ribbon_start').css("background", "url('rw_common/plugins/stacks/images/ribbon12/gyro_ribbon_right_end_12.png') no-repeat");
			$('#stacks_in_655_page0 .gyro_ribbon_end').css("background", "url('rw_common/plugins/stacks/images/ribbon12/gyro_ribbon_right_start_12.png') no-repeat");			
		}
		// This is to set some CSS styles for ribbons that don't  fit into the defaults set in the CSS file
		/* if ('12' == 2 || '12' == 3 || '12' == 4) {
			$('#stacks_in_655_page0 .gyro_ribbon').css("right", "-13px");
		}
		if ('12' == 5 || '12' == 6) {
			$('#stacks_in_655_page0 .gyro_ribbon_end').css("width", "32px");
		} */
	}; 
	createPager(); //Run function on launch

	//Set Default State of each portfolio piece
	// $("#stacks_in_655_page0 .gyro_ribbon").show();
	$("#stacks_in_655_page0 .gyro_ribbon a:first").addClass("active");

	//Get size of images, how many there are, then determin the size of the image reel.
	var imageHeight = $("#stacks_in_655_page0 .gyro_image_reel img:first").height();
	var imageWidth = $("#stacks_in_655_page0 .gyro_image_reel img:first").width();
	var imageSum = $("#stacks_in_655_page0 .gyro_image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$("#stacks_in_655_page0 .gyro_container").css({'width' : imageWidth});
	$("#stacks_in_655_page0 .gyro_window").css({'width' : imageWidth});
	$("#stacks_in_655_page0 .gyro_window").css({'height' : imageHeight});
	$("#stacks_in_655_page0 .gyro_image_reel").css({'width' : imageReelWidth});
			
	//ribbon + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$("#stacks_in_655_page0 .gyro_ribbon a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$("#stacks_in_655_page0 .gyro_image_reel").animate({ 
			left: -image_reelPosition
		}, 1201 );		
	}; 
	
	var play;
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('#stacks_in_655_page0 .gyro_ribbon a.active').next();
			if ( $active.length === 0) { //If ribbon reaches the end...
				$active = $('#stacks_in_655_page0 .gyro_ribbon a:first'); //go back to first
			}
			rotate(); //Trigger the ribbon and slider function
		}, 5000); //Timer speed in milliseconds
	};
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$("#stacks_in_655_page0 .gyro_image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	

	//On Click
	$("#stacks_in_655_page0 .gyro_ribbon a").click(function() {	
		$active = $(this); //Activate the clicked ribbon
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		if (false) {
			clearInterval(play); //Stop the rotation
		}
		else {
			rotateSwitch(); // Resume rotation
		}
		return false; //Prevent browser jump to link anchor
	});	
});

//-- End Gyro Stack --//
	return stack;
})(stacks.stacks_in_655_page0);


// Javascript for stacks_in_666_page0
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_666_page0 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_666_page0 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
/**
 *
 * Image Mapper Plus stack by Tsooj Media.
 * Version 1.0.1.
 *
 * Visit http://www.tsooj.net for more information on how to use this stacks product for RapidWeaver.
 *
 */

/**
 *
 * jquery.maphilight by http://davidlynch.org/
 *
 */
(function(F){var B,C,I,L,K,H,E,G,A,J;B=document.namespaces;has_canvas=!!document.createElement("canvas").getContext;if(!(has_canvas||B)){F.fn.maphilight=function(){return this};return }if(has_canvas){E=function(M){return Math.max(0,Math.min(parseInt(M,16),255))};G=function(M,N){return"rgba("+E(M.substr(0,2))+","+E(M.substr(2,2))+","+E(M.substr(4,2))+","+N+")"};C=function(M){var N=F('<canvas style="width:'+M.width+"px;height:"+M.height+'px;"></canvas>').get(0);N.getContext("2d").clearRect(0,0,N.width,N.height);return N};I=function(P,M,S,O,N){var R,Q=P.getContext("2d");Q.beginPath();if(M=="rect"){Q.rect(S[0],S[1],S[2]-S[0],S[3]-S[1])}else{if(M=="poly"){Q.moveTo(S[0],S[1]);for(R=2;R<S.length;R+=2){Q.lineTo(S[R],S[R+1])}}else{if(M=="circ"){Q.arc(S[0],S[1],S[2],0,Math.PI*2,false)}}}Q.closePath();if(O.fill){Q.fillStyle=G(O.fillColor,O.fillOpacity);Q.fill()}if(O.stroke){Q.strokeStyle=G(O.strokeColor,O.strokeOpacity);Q.lineWidth=O.strokeWidth;Q.stroke()}if(O.fade){F(P).css("opacity",0).animate({opacity:1},407)}};L=function(M){M.getContext("2d").clearRect(0,0,M.width,M.height)}}else{C=function(M){return F('<var style="zoom:1;overflow:hidden;display:block;width:'+M.width+"px;height:"+M.height+'px;"></var>').get(0)};I=function(N,Q,R,U,M){var S,T,O,P;S='<v:fill color="#'+U.fillColor+'" opacity="'+(U.fill?U.fillOpacity:0)+'" />';T=(U.stroke?'strokeweight="'+U.strokeWidth+'" stroked="t" strokecolor="#'+U.strokeColor+'"':'stroked="f"');O='<v:stroke opacity="'+U.strokeOpacity+'"/>';if(Q=="rect"){P=F('<v:rect name="'+M+'" filled="t" '+T+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+R[0]+"px;top:"+R[1]+"px;width:"+(R[2]-R[0])+"px;height:"+(R[3]-R[1])+'px;"></v:rect>')}else{if(Q=="poly"){P=F('<v:shape name="'+M+'" filled="t" '+T+' coordorigin="0,0" coordsize="'+N.width+","+N.height+'" path="m '+R[0]+","+R[1]+" l "+R.join(",")+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+N.width+"px;height:"+N.height+'px;"></v:shape>')}else{if(Q=="circ"){P=F('<v:oval name="'+M+'" filled="t" '+T+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(R[0]-R[2])+"px;top:"+(R[1]-R[2])+"px;width:"+(R[2]*2)+"px;height:"+(R[2]*2)+'px;"></v:oval>')}}}P.get(0).innerHTML=S+O;F(N).append(P)};L=function(M){F(M).find("[name=highlighted]").remove()}}K=function(N){var M,O=N.getAttribute("coords").split(",");for(M=0;M<O.length;M++){O[M]=parseFloat(O[M])}return[N.getAttribute("shape").toLowerCase().substr(0,4),O]};J=function(O,N){var M=F(O);return F.extend({},N,F.metadata?M.metadata():false,M.data("maphilight"))};A=function(M){if(!M.complete){return false}if(typeof M.naturalWidth!="undefined"&&M.naturalWidth==0){return false}return true};H={position:"absolute",left:0,top:0,padding:0,border:0};var D=false;F.fn.maphilight=function(O){O=F.extend({},F.fn.maphilight.defaults,O);if(!has_canvas&&F.browser.msie&&!D){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var N=document.createStyleSheet();var M=["shape","rect","oval","circ","fill","stroke","imagedata","group","textbox"];F.each(M,function(){N.addRule("v\\:"+this,"behavior: url(#default#VML); antialias:true")});D=true}return this.each(function(){var U,R,Y,Q,T,V,X,S,W;U=F(this);if(!A(this)){return window.setTimeout(function(){U.maphilight(O)},200)}Y=F.extend({},O,F.metadata?U.metadata():false,U.data("maphilight"));W=U.get(0).getAttribute("usemap");Q=F('map[name="'+W.substr(1)+'"]');if(!(U.is("img")&&W&&Q.size()>0)){return }if(U.hasClass("maphilighted")){var P=U.parent();U.insertBefore(P);P.remove();F(Q).unbind(".maphilight").find("area[coords]").unbind(".maphilight")}R=F("<div></div>").css({display:"block",background:'url("'+this.src+'")',position:"relative",padding:0,width:this.width,height:this.height});if(Y.wrapClass){if(Y.wrapClass===true){R.addClass(F(this).attr("class"))}else{R.addClass(Y.wrapClass)}}U.before(R).css("opacity",0).css(H).remove();if(F.browser.msie){U.css("filter","Alpha(opacity=0)")}R.append(U);T=C(this);F(T).css(H);T.height=this.height;T.width=this.width;X=function(c){var a,b;b=J(this,Y);if(!b.neverOn&&!b.alwaysOn){a=K(this);I(T,a[0],a[1],b,"highlighted");if(b.groupBy){var Z;if(/^[a-zA-Z][-a-zA-Z]+$/.test(b.groupBy)){Z=Q.find("area["+b.groupBy+'="'+F(this).attr(b.groupBy)+'"]')}else{Z=Q.find(b.groupBy)}var d=this;Z.each(function(){if(this!=d){var f=J(this,Y);if(!f.neverOn&&!f.alwaysOn){var e=K(this);I(T,e[0],e[1],f,"highlighted")}}})}if(!has_canvas){F(T).append("<v:rect></v:rect>")}}};F(Q).bind("alwaysOn.maphilight",function(){if(V){L(V)}if(!has_canvas){F(T).empty()}F(Q).find("area[coords]").each(function(){var Z,a;a=J(this,Y);if(a.alwaysOn){if(!V&&has_canvas){V=C(U.get());F(V).css(H);V.width=U.width();V.height=U.height();U.before(V)}a.fade=a.alwaysOnFade;Z=K(this);if(has_canvas){I(V,Z[0],Z[1],a,"")}else{I(T,Z[0],Z[1],a,"")}}})});F(Q).trigger("alwaysOn.maphilight").find("area[coords]").bind("mouseover.maphilight",X).bind("mouseout.maphilight",function(Z){L(T)});U.before(T);U.addClass("maphilighted")})};F.fn.maphilight.defaults={fill:true,fillColor:"000000",fillOpacity:0.2,stroke:true,strokeColor:"ff0000",strokeOpacity:1,strokeWidth:1,fade:true,alwaysOn:false,neverOn:false,groupBy:false,wrapClass:true}})(jQuery);

/** 
 *
 * Document Ready Actions.
 *
 */
 
$(document).ready(function() {
	if(false) {
		// Show the Coordinates Inspector Elements.
		$('<div id="atm_image_mapper_overlay_headerstacks_in_666_page0"><div class="atm_image_mapper_areastacks_in_666_page0"><a href="#">Finished measuring area &#39;1&#39;</a></div><div class="atm_image_mapper_showhidestacks_in_666_page0"><a href="#">Show / Hide Placeholder</a></div><input type="checkbox" name="autohidestacks_in_666_page0" value="autohide" /><span class="atm_image_mapper_autohidestacks_in_666_page0">Hide while measuring</span></div><div id="atm_image_mapper_overlaystacks_in_666_page0"></div><div id="atm_image_mapper_coordinatesstacks_in_666_page0"><div id="atm_image_mapper_coordinates_placeholder"><span class="atm_image_mapper_comment_text">Hover your mouse over the image above and the X,Y coordinates automatically appears. Simply click on the current location to add the coordinates into the &#39;measured coordinates section&#39;. You can use this &#39;placeholder&#39; to create all your required area&#39;s and then copy and paste it into the custom input fields of the image mapper stack. Note that the measured area numbers below are in no way directly related to the already added area&#39;s in edit mode. So you can start measuring new area&#39;s any time.</span><br /><br /><span class="atm_image_mapper_area_textstacks_in_666_page0">Measured coordinates area &#39;1&#39;: </span></div></div>').prependTo('body');
		$('#stacks_in_666_page0').appendTo('#atm_image_mapper_overlaystacks_in_666_page0').css('cursor', 'crosshair');				
		$('.atm_image_mapper_areastacks_in_666_page0 a').data('area', parseInt(1));
		
		// Inspector Hover code.
		$('#stacks_in_666_page0 img').hover(function(e) {
			$('<div id="atm_image_mapper_inspectorstacks_in_666_page0"></div>').appendTo('body').css('left', (e.pageY + 20) + 'px').css('top', (e.pageY - 10) + 'px').show();
		}, function() {
			// Inspector Hover out code.
			$('#atm_image_mapper_inspectorstacks_in_666_page0').remove();
		}).mousemove(function(e) {

			// Inspector Mouse move code.
			var atm_intX = e.pageX - Math.round($('#stacks_in_666_page0 img').offset().left);
			var atm_intY = e.pageY - Math.round($('#stacks_in_666_page0 img').offset().top);
			$('#atm_image_mapper_inspectorstacks_in_666_page0').css('left', (e.pageX + 30) + 'px').css('top', (e.pageY - 20) + 'px').text('X,Y = ' + atm_intX + ',' + atm_intY).data('coordinates', atm_intX + ',' + atm_intY);
		});
		
		// Add to the Coordinates placeholder.
		$('#stacks_in_666_page0 img').click(function(e) {
			if($('#atm_image_mapper_coordinatesstacks_in_666_page0').length > 0) {
				if($('input[name=autohidestacks_in_666_page0]').attr('checked')) { $('#atm_image_mapper_coordinatesstacks_in_666_page0').hide(); }
				$('#atm_image_mapper_coordinatesstacks_in_666_page0 #atm_image_mapper_coordinates_placeholder').append($('#atm_image_mapper_inspectorstacks_in_666_page0').data('coordinates') + ', ');
			}
			$('<div class="atm_image_mapper_coordinatestacks_in_666_page0"></div>').appendTo('#stacks_in_666_page0').css('left', (e.pageX -2) + 'px').css('top', (e.pageY -2) + 'px');
		});
		
		// Add new Measuring Area.
		$('.atm_image_mapper_areastacks_in_666_page0 a').click(function() {
			var atm_strCoordinates = new String($('#atm_image_mapper_coordinatesstacks_in_666_page0 #atm_image_mapper_coordinates_placeholder').html());
			if(atm_strCoordinates.charAt(atm_strCoordinates.length - 2) == ",") {		
				var atm_intArea = parseInt($(this).data('area') + 1);
				$(this).data('area', parseInt(atm_intArea));
				atm_strCoordinates = atm_strCoordinates.slice(0, atm_strCoordinates.length -2);
				$('#atm_image_mapper_coordinatesstacks_in_666_page0 #atm_image_mapper_coordinates_placeholder').html(atm_strCoordinates + '<span class="atm_image_mapper_area_spacestacks_in_666_page0">&nbsp;</span><span class="atm_image_mapper_area_textstacks_in_666_page0">Measured coordinates area &#39;' + atm_intArea + '&#39;: </span>');
				$(this).text('Finished measuring area \'' + atm_intArea + '\'');
				$('.atm_image_mapper_coordinatestacks_in_666_page0').remove();
				if($('input[name=autohidestacks_in_666_page0]').attr('checked')) { $('#atm_image_mapper_coordinatesstacks_in_666_page0').show(); }
			}
			return false;
		});
		
		// Show/Hide the Coordinate placeholder.
		$('.atm_image_mapper_showhidestacks_in_666_page0 a').click(function() {
			$('#atm_image_mapper_coordinatesstacks_in_666_page0').toggle();
			return false;
		});	
		
		// Toggle Auto Hide.
		$('.atm_image_mapper_autohidestacks_in_666_page0').click(function() {
			$('input[name=autohidestacks_in_666_page0]').attr('checked', !$('input[name=autohidestacks_in_666_page0]').attr('checked'));
		});
		
	} else {
	
		// Add the map to the image.
		$('#stacks_in_666_page0 img').attr('usemap', '#imagemap_stacks_in_666_page0');
	
		// Let the user decide if they would like to use the Maphilight.
		if(true) {
			var atm_strFillColor = '#000000', 
				atm_strStrokeColor = '#3767A6';
			atm_strFillColor = atm_strFillColor.replace('#', '');
			atm_strStrokeColor = atm_strStrokeColor.replace('#', '');
			$('img[usemap=#imagemap_stacks_in_666_page0]').maphilight({fill:true,fillColor:atm_strFillColor,fillOpacity:parseFloat(parseInt(20)/100),stroke:true,strokeColor:atm_strStrokeColor,strokeOpacity:parseFloat(parseInt(100)/100),strokeWidth:1,fade:true});
		}
	}
});

	return stack;
})(stacks.stacks_in_666_page0);



