
// '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_354_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_354_page0 = {};

// A closure is defined and assigned to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for referring
// to this object from elsewhere.
stacks.stacks_in_354_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;
	

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// FADER STACK BY http://www.doobox.co.uk XXXXXXXX
// V-1.0.3 LAST UPDATED 24/3/2011 XXXXXXXXXXXXXXXX
// COPYRIGHT@2010 MR JG SIMPSON, TRADING AS DOOBOX
// ALL RIGHTS RESERVED XXXXXXXXXXXXXXXXXXXXXXXXXXX
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


$(document).ready(function() {
$("#stacks_in_354_page0 img").removeClass("imageStyle").addClass('dooFaderImage');
	
	// get the main background image if one exists
	var bgimage = $('.stacks_in_354_page0background img').attr("src");


	// create the image array from the images the user has dropped in to the slides
    var FArray = $.makeArray($('.stacks_in_354_page0faderImageContainer img'));
    	$(FArray).hide();
	
	// set initial global variables
	var doowidth = 0;
	var dooheight = 0;
    var dooi = 0;
    var doox = 0;
    var dooy = 0;
    var stacks_in_354_page0total = FArray.length - 1;
    var stacks_in_354_page0delay = 1;
    var doofaderborder = 0 + "px solid #CCCCCC"
    var dootopmargin = 0;
    var dooleftmargin = 0;
    
    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // get the size of the highest image in px
    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    var dooheight = 0;
    $.each(FArray, function(index, height) {
    if($(height).height() > dooheight){
    dooheight = $(height).height();
    }
	});
	dooheight = dooheight +"px"; // add the px for ie
	
	
	
	// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	// get the size of the widest image in px
	// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    var doowidth = 0;
    $.each(FArray, function(index, width) {
    if($(width).width() > doowidth){
    doowidth = $(width).width();
    }
	});
	doowidth = doowidth + "px"; // add the px for ie
	
	
	 // remove the initial image container and images from the page(not needed)
    $('.stacks_in_354_page0faderImageContainer img').remove();
	

    // place the first slide right away, before the effect starts
    $(FArray[0]).appendTo(".stacks_in_354_page0faderbox").show();
    
 
    
    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // setup the initial css for the faderbox
    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    if("yes" == "yes"){
		$(".stacks_in_354_page0faderbox").css("backgroundColor", "#F4F4F4");
	  }

   $(".stacks_in_354_page0faderbox").css({
    "background-image": "url("+bgimage+")",
    "padding":          "0px",
    "height":           dooheight + '',
    "width":            doowidth + '',
    "border":           doofaderborder + ''
});

   	 
   	 

    
    
	// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // The Main Fader Infinite Function XXXXX
    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    function rotateFader(){
    $("#stacks_in_354_page0 img").removeClass("imageStyle").addClass('dooFaderImage');
    
    // set up vars for negative centering margins (only applies if centering set in the hud to true)
    if("yes" == "yes"){
    dootopmargin = $(FArray[dooi]).height() / 2;
    dooleftmargin = $(FArray[dooi]).width() / 2;
    dootopmargin = "-" + Math.round(dootopmargin) + "px";
	dooleftmargin = "-" + Math.round(dooleftmargin) + "px";

    
    // take care of the css for each image as the images rotate (only applies if centering set in the hud to true)
    $(FArray[dooi]).css({
    	"position": "absolute",
    	"top": "50%" ,
    	"left": "50%",
    	"marginTop": dootopmargin,
    	"marginLeft": dooleftmargin
    });
    }
    
    
    
    
			$(FArray[dooi]).appendTo(".stacks_in_354_page0faderbox").delay(stacks_in_354_page0delay).fadeIn(3000, function() {
			

			
       	 		$(FArray[dooi]).delay(3000).fadeOut(3000, function() {
       	 		
       	 		// do something in a future upgrade, when fade out has ended.
     		 	});
     		 	
     			 if(dooi < stacks_in_354_page0total){dooi = dooi + 1;}
        		 else{dooi = 0;}
        		 stacks_in_354_page0delay = 3000;
        		 
        		
        		 rotateFader();
        		 
        		 
      		});
    // set up vars for negative centering margins (only applies if centering set in the hud to true)
    if("yes" == "yes"){
    dootopmargin = $(FArray[dooi]).height() / 2;
    dooleftmargin = $(FArray[dooi]).width() / 2;
    dootopmargin = "-" + Math.round(dootopmargin) + "px";
	dooleftmargin = "-" + Math.round(dooleftmargin) + "px";

    
    // take care of the css for each image as the images rotate (only applies if centering set in the hud to true)
    $(FArray[dooi]).css({
    	"position": "absolute",
    	"top": "50%" ,
    	"left": "50%",
    	"marginTop": dootopmargin,
    	"marginLeft": dooleftmargin
    });
    }
    
	}
	
	// initialize the fader function and rotate the images
    rotateFader();
    
});


// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// END DOOBOX FADER STACK XXXXXXXXXXXXXXXXXXXXX
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	return stack;
})(stacks.stacks_in_354_page0);



