
// '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_1160_page9
// ---------------------------------------------------------------------

// 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_1160_page9 = {};

// 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_1160_page9 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	

//-- Fancy Image 360 Stack v2.0.2 by Joe Workman --//

//---------------------------
// Start jQuery 360 Plugin
//---------------------------
// Mathieu dumais-savard 2009
// http://www.mathieusavard.info/
// version 0.4.0 
jQuery.fn.threesixty = function(options){
		options = options || {};
		options.images = options.images || [];
		options.method = options.method || "click"
		options.cycle = options.cycle || 1;
		options.resetMargin = options.resetMargin || 0;
		options.direction = options.direction || "forward";

		if (options.direction == "backward")
			options.images.reverse();

    return this.each(function(){
			var imgArr = [];
			var pic = $(this);
		//ask browser to load all images.. I know this could be beter but is just a POC
				$.each(options.images, function(index, record) { var o =$("<img>").attr("src",record);		$("body").append(o); o.hide(); });

			for (var x=1; x<=options.cycle; x++)
				for (var y=0; y<options.images.length; y++)
					imgArr.push(options.images[y]);

			//add the first slice again to complete the loop
			imgArr.push(options.images[0]);

			if (options.method == "mousemove")
				pic.mousemove(function(e) {
					pic.attr("src",imgArr[Math.floor((e.pageX - pic.offset().left) / (pic.width()/imgArr.length))]);
				});

			if (options.method == "click")
			{			
					var follower
					if (!$.browser.msie)
					{	follower = $("<div>").css({"z-index":0, "width":"15px", "height":"15px", "position":"absolute", "top": pic.offset().top, "left":pic.offset().left});
  					$("body").append(follower);
						disableSelection(follower[0]);
					}
					disableSelection(pic[0]);
					var imgSrc, enabled;
					pic.mousemove(function(e) {
						if (e.pageX<=pic.offset().left+options.resetMargin || e.pageX > pic.offset().left + pic.width()-options.resetMargin || e.pageY<=pic.offset().top+options.resetMargin || e.pageY>=pic.offset().top+pic.height()-options.resetMargin)
						{	enabled=false;
							return false;
						}
						if (follower)
							follower.css({"top": e.pageY-7, "left": e.pageX-7});
						if (enabled==true)
							pic.attr("src",imgArr[Math.floor((e.pageX - pic.offset().left) / (pic.width()/imgArr.length))]);
					})
					pic.add((follower)?follower:null).mouseup(function() {
							enabled=false; 
					}).mousedown(function() { enabled=true; });
			}
	});			

//more than inspired of Bret Taylor's work : http://ajaxcookbook.org/disable-text-selection/
						function disableSelection(element) {
						    element.onselectstart = function() {
						        return false;
						    };
						    element.unselectable = "on";
						    element.style.MozUserSelect = "none";
						    element.style.cursor = "default";
						}


};
//---------------------------
// End jQuery 360 Plugin
//---------------------------
$(document).ready(function() {
	var arr = [];
	for (var x=1; x<= 64; x++) {
		arr.push("http://www.icecarvingsecrets.net/360/stork/" + x + ".jpg");
	}		
	$("#my360_stacks_in_1160_page9").threesixty({images:arr, method:'mousemove', cycle:2, direction:"forward"});	
});
//-- End Fancy Image 360 Stack --//

	return stack;
})(stacks.stacks_in_1160_page9);


// Javascript for stacks_in_99_page9
// ---------------------------------------------------------------------

// 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_99_page9 = {};

// 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_99_page9 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	

  

  jQuery(document).ready(function($){

function findPlainTextExceptInLinks(element, substring, callback) {
    for (var childi= element.childNodes.length; childi-->0;) {
        var child= element.childNodes[childi];
        if (child.nodeType===1) {
            if (child.tagName.toLowerCase()!=='a')
                findPlainTextExceptInLinks(child, substring, callback);
        } else if (child.nodeType===3) {
            var index= child.data.length;
            while (true) {
                index= child.data.lastIndexOf(substring, index);
                if (index===-1)
                    break;
                callback.call(window, child, index)
            }
        }
    }
}

var substring= 'TeleportMe';
findPlainTextExceptInLinks(document.body, substring, function(node, index) {
    node.splitText(index+substring.length);
    var span= document.createElement('span');
    span.className = "teleportHere";
    span.appendChild(node.splitText(index));
    node.parentNode.insertBefore(span, node.nextSibling);
});


var injectionStack = $("#stacks_in_99_page9").html();


$("#stacks_in_99_page9 .teleportMe").remove();
$(".teleportHere").replaceWith(injectionStack);


});
	return stack;
})(stacks.stacks_in_99_page9);



