
// '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_127_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_127_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_127_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;
	
/*
 *
 * RapidWeaver Newsticker Styled stack by Tsooj Media
 * Version 1.3.1
 *
 * Visit http://www.tsooj.net for more information on how to use this stacks product for RapidWeaver.
 *
 */
 
/*
News ticker plugin (BBC news style)
Bryan Gullan,2007-2011
version 2.3.6
updated 2011-03-16
Documentation at http://www.makemineatriple.com/news-ticker-documentation/
Demo at http://www.makemineatriple.com/jquery/?newsTicker
Use and distrubute freely with this header intact.
*/

(function($) {
	
	var name='newsTicker';
	var debugMode = false; // enabling this turns on console logging for interactions
	
	function runTicker(settings) {
		
		tickerData = $(settings.newsList).data('newsTicker');
		
		if(tickerData.currentItem > tickerData.newsItemCounter){
			// if we've looped to beyond the last item in the list, start over
			tickerData.currentItem = 0;
		}
		else if (tickerData.currentItem < 0) {
			// if we've looped back before the first item, move to the last one
			tickerData.currentItem = tickerData.newsItemCounter;
		}
		
		if(tickerData.currentPosition == 0) {
			if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
				$(tickerData.newsList).empty().append('<li><a '+ tickerData.newsAttributes[tickerData.currentItem] +'></a></li>');
			}
			else {
				$(tickerData.newsList).empty().append('<li></li>');
			}
		}
		
		//only start the ticker itself if it's defined as animating: otherwise it's paused or under manual advance
		if (tickerData.animating) {
			
			if( tickerData.currentPosition % 2 == 0) {
					var placeHolder = tickerData.placeHolder1;
			}
			else {
				var placeHolder = tickerData.placeHolder2;
			}
			
			if( tickerData.currentPosition < tickerData.newsItems[tickerData.currentItem].length) {
				// we haven't completed ticking out the current item
				
				var tickerText = tickerData.newsItems[tickerData.currentItem].substring(0,tickerData.currentPosition);
				if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
					$(tickerData.newsList + ' li a').text(tickerText + placeHolder);
				}
				else {
					$(tickerData.newsList + ' li').text(tickerText + placeHolder);
				}
				tickerData.currentPosition ++;
				setTimeout(function(){runTicker(settings); settings = null;},tickerData.tickerRate);
			}
			
			else {
				// we're on the last letter of the current item
				
				if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
					$(tickerData.newsList + ' li a').text(tickerData.newsItems[tickerData.currentItem]);
				}
				else {
					$(tickerData.newsList + ' li').text(tickerData.newsItems[tickerData.currentItem]);
				}
				
				setTimeout(function(){
					if (tickerData.animating) {
						tickerData.currentPosition = 0;
						tickerData.currentItem ++;
						runTicker(settings); settings = null;
					}
				},tickerData.loopDelay);
				
			}
		}
		
		else {// settings.animating == false 
			
			// display the full text of the current item
			var tickerText = tickerData.newsItems[tickerData.currentItem];
			
			if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
				$(tickerData.newsList + ' li a').text(tickerText);
			}
			else {
				$(tickerData.newsList + ' li').text(tickerText);
			}
					
		}
		
	}

	
	// Core plugin setup and config
	jQuery.fn[name] = function(options) {
 
	  // Add or overwrite options onto defaults
	  var settings = jQuery.extend({}, jQuery.fn.newsTicker.defaults, options);
	 
    var newsItems = new Array();
		var newsLinks = new Array();
		var newsAttributes = new Array();
		var newsItemCounter = 0;
		
		// Hide the static list items
		$(settings.newsList + ' li').hide();
		
		// Store the items and links in arrays for output
		$(settings.newsList + ' li').each(function(){
			if($(this).children('a').length) {
				newsItems[newsItemCounter] = $(this).children('a').text();
				newsLinks[newsItemCounter] = $(this).children('a').attr('href');
				
				var linkAttributes = new Object();
			  	var attrs = $(this).children('a')[0].attributes;
					for (var i=0;i<attrs.length;i++) {
					linkAttributes[attrs[i].nodeName] = attrs[i].nodeValue;
				}
				if (debugMode){ 
					console.log(linkAttributes);
				}
				
		    var linkAttributesProcessed = '';
 				for (var prop in linkAttributes) {
 					// print out the attributes as a string ready for output within the anchor tag
    			linkAttributesProcessed = linkAttributesProcessed + prop + '="' + linkAttributes[prop] + '" ';
 				}
 				if (debugMode){ 
					console.log(linkAttributesProcessed);
				}
 				
				newsAttributes[newsItemCounter] = linkAttributesProcessed;
				
			}
			else {
				newsItems[newsItemCounter] = $(this).text();
				newsLinks[newsItemCounter] = '';
				newsAttributes[newsItemCounter] = '';
			}
			newsItemCounter ++;
		});
        
        var tickerElement = $(settings.newsList); // for quick reference below
        
        tickerElement.data(name, {
        	newsList: settings.newsList,
					tickerRate: settings.tickerRate,
					startDelay: settings.startDelay,
					loopDelay: settings.loopDelay,
					placeHolder1: settings.placeHolder1,
					placeHolder2: settings.placeHolder2,
					controls: settings.controls,
					ownControls: settings.ownControls,
					stopOnHover: settings.stopOnHover,
					resumeOffHover: settings.resumeOffHover,
          newsItems: newsItems,
					newsLinks: newsLinks,
					newsAttributes: newsAttributes,
					newsItemCounter: newsItemCounter - 1, // -1 because we've incremented even after the last item (above)
					currentItem: 0,
					currentPosition: 0,
					firstRun:1
        })
        .bind({
			stop: function(event) {
				// show remainder of the current item immediately
		    	tickerData = tickerElement.data(name);
		    	if (tickerData.animating) { // only stop if not already stopped
            		tickerData.animating = false;
            		if (debugMode){ 
            			console.log('stop'+tickerData.currentItem + ' ' + tickerData.animating);
            		}
               	}
		  	},
		  	play: function(event) {
		  		// show 1st item with startdelay
		    	tickerData = tickerElement.data(name);
		    	if (!tickerData.animating) { // if already animating, don't start animating again
	            	tickerData.animating = true;
	            	if (debugMode){ 
            			console.log('play'+tickerData.currentItem + ' ' + tickerData.animating);
            		}
	            	setTimeout(function(){runTicker(tickerData); tickerData = null;},tickerData.startDelay);
	            }
		  	},
		  	resume: function(event) {
		  		// start from next item, with no delay
		    	tickerData = tickerElement.data(name);
		    	if (!tickerData.animating) { // if already animating, don't start animating again
	            	tickerData.animating = true;
	            	// set the character position as 0 to ensure on resume we start at the right point
					tickerData.currentPosition = 0;
	            	tickerData.currentItem ++;
	            	if (debugMode){ 
            			console.log('resume'+tickerData.currentItem + ' ' + tickerData.animating);
            		}
		            runTicker(tickerData); // no delay when resuming.
		        }
		  	},
		  	next: function(event) {
		  		// show whole of next item
		  		tickerData = tickerElement.data(name);
		  		// stop (which sets as non-animating), and call runticker
		  		$(tickerData.newsList).trigger("stop");
		  		// set the character position as 0 to ensure on resume we start at the right point
				tickerData.currentPosition = 0;
	            tickerData.currentItem ++;
	            if (debugMode){ 
            			console.log('next'+tickerData.currentItem + ' ' + tickerData.animating);
            		}
		  		runTicker(tickerData);
		  	},
		  	previous: function(event) {
				// show whole of previous item
				tickerData = tickerElement.data(name);
		  		// stop (which sets as non-animating), and call runticker
		  		$(tickerData.newsList).trigger("stop");
		  		// set the character position as 0 to ensure on resume we start at the right point
				tickerData.currentPosition = 0;
	            tickerData.currentItem --;
	            if (debugMode){ 
            			console.log('previous'+tickerData.currentItem + ' ' + tickerData.animating);
            		}
		  		runTicker(tickerData);
			}
		}); 	
		if (settings.stopOnHover) {
	    	tickerElement.bind({			    	
			  	mouseover: function(event) {
			  		tickerData = tickerElement.data(name);
			    	if (tickerData.animating) { // stop if not already stopped
				  		$(tickerData.newsList).trigger("stop");
				  		if (tickerData.controls) { // ensure that the ticker can be resumed if controls are enabled
				  			$('.stop').hide();
			        		$('.resume').show();
				  		}
			  		}
			  	}
			});
			if (settings.resumeOffHover) { // only allowed if stopOnHover enabled
		    	tickerElement.bind({			    	
				  	mouseout: function(event) {
				  		tickerData = tickerElement.data(name);
				    	if (!tickerData.animating) { // if already animating, don't start animating again
			            	$(tickerData.newsList).trigger("resume");
			            	if (debugMode){ 
		            			console.log('resumeoffhover'+tickerData.currentItem + ' ' + tickerData.animating);
		            		}
				        }
				  	}
				});
    		}
    	}
    	
    	tickerData = tickerElement.data(name);
    	
    	// set up control buttons if the option is on
		if (tickerData.controls || tickerData.ownControls) {
			if (!tickerData.ownControls) {
				$('<ul class="ticker-controls"><li class="play"><a href="#play">Play</a></li><li class="resume"><a href="#resume">Resume</a></li><li class="stop"><a href="#stop">Stop</a></li><li class="previous"><a href="#previous">Previous</a></li><li class="next"><a href="#next">Next</a></li></ul>').insertAfter($(tickerData.newsList));
			}
			$('.play').hide();
		    $('.resume').hide();
			
		    $('.play').click(function(event){
		        $(tickerData.newsList).trigger("play");
		        $('.play').hide();
		        $('.resume').hide();
		        $('.stop').show();
		        event.preventDefault();
		    });
		    $('.resume').click(function(event){
		        $(tickerData.newsList).trigger("resume");
		        $('.play').hide();
		        $('.resume').hide();
		        $('.stop').show();
		        event.preventDefault();
		    });
			$('.stop').click(function(event){
		        $(tickerData.newsList).trigger("stop");
		        $('.stop').hide();
		        $('.resume').show();
		        event.preventDefault();
		    });
		    $('.previous').click(function(event){
		        $(tickerData.newsList).trigger("previous");
		        $('.stop').hide();
			    $('.resume').show();
		        event.preventDefault();
		    });
		    $('.next').click(function(event){
		        $(tickerData.newsList).trigger("next");
		        $('.stop').hide();
			    $('.resume').show();
		        event.preventDefault();
		    });

	    };
    	
    	// tell it to play
    	$(tickerData.newsList).trigger("play");
	};

	// News ticker defaults 
	jQuery.fn[name].defaults = {
		newsList: ".atm-Newsticker ul",
		tickerRate: 20,
		startDelay: 100,
		loopDelay: 3000,
		placeHolder1: "",
		placeHolder2: "",
		controls: false,
		ownControls: false,
		stopOnHover: false,
		resumeOffHover: true
	}

})(jQuery);


$(document).ready(function() {
	$('.atm-Newsticker a[rel=external]').attr('target', '_blank');
	$().newsTicker();
});

	return stack;
})(stacks.stacks_in_127_page0);


// Javascript for stacks_in_133_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_133_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_133_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;
	
/* Copyright 2010-2011 NimbleHost. All rights reserved. */

var $hijax = jQuery.noConflict(); 

function activateHijax(fileExtension, fileLink) {
	/* Global default ajax settings for Hijax. */
	var hijaxErrorCode = "There was a problem loading the content. Please try again, or contact the webmaster.<br/><p><strong>Error details:</strong> <span class='hijaxErrorDetails'>";
	$hijax.ajaxSetup({
		url: fileLink,
		beforeSend: function() { $hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').empty(); },
		timeout: 30000,
		error: function(xhr, textStatus, errorThrown) {
			var generalError;
			if ( textStatus == '' ) { generalError = "Specific details are not available. This usually means: <ul><li>The file is missing, <strong>or</strong></li><li>The file is located on a different domain/sub-domain from the website you are viewing - for security reasons, such files cannot be displayed via ajax.</li></ul>"; } else { generalError = ''; }
			if ( textStatus == "timeout" ) { generalError = "The request to load the content has timed out. This could mean the server is not responding, or that the file size is too large to be loaded in the allotted time." }
			$hijax("#nimblehost_hijaxContentDetails_stacks_in_133_page0").html(hijaxErrorCode + textStatus + " " + generalError + "</span></p>");
			}
	});
	switch(fileExtension) {
		case 'jpg':
		case 'jpeg':
		case 'jif':
		case 'jfif':
		case 'png':
		case 'gif':
		case 'psd':
		case 'tif':
		case 'tiff':
		case 'bmp':
		case 'svg':
			var imageEmbed = '<div class="hijaxMedia"><img class="hijaxImage" src="' + fileLink + '"/></div>';
			$hijax.ajax({
				success: function() {
						$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').html(imageEmbed);
					}
			});
		break;
		case 'txt':
		case 'php':
		case 'rb':
		case 'py':
		case 'pl':
		case 'htm':
		case 'html':
		case 'shtml':
		case 'phtml':
		case 'xht':
		case 'xhtml':
		case 'stm':
		case 'xml':
		case 'jsp':
		case 'asp':
		case 'aspx':
		case 'cfm':
		case 'cgi':
			$hijax.ajax({
				success: function(data) {
						$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').html(data);
					}
				
			});
		break;
		case 'mp3':
		case 'aac':
		case 'aif':
		case 'aiff':
		case 'mid':
		case 'midi':
		case 'wav':
		case 'wma':
		case 'mpga':
		case 'au':
		case 'oga':
			var html5AudioEmbed = '<div class="hijaxMedia"><div id="hijaxMediaFlashFallback_stacks_in_133_page0"><audio src="' + fileLink + '" controls></audio></div></div>';
			$hijax.ajax({
				success: function() {
						var a = document.createElement("audio");
						if ( !a.play ) {
							$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').text("Your browser does not support HTML5 audio/video. Please go back and download the media file directly.");
						} else {
							$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').html(html5AudioEmbed);
						}
					}
			});
		break;
		case 'qt':
		case 'mpg':
		case 'mpeg':
		case 'mov':
		case 'mp4':
		case 'm4v':
		case 'avi':
		case 'wmv':
		case 'ogg':
		case 'webm':
		case 'ogv':
			var html5VideoEmbed = '<div class="hijaxMedia"><div id="hijaxMediaFlashFallback_stacks_in_133_page0"><video src="' + fileLink + '" controls></video></div></div>';
			$hijax.ajax({
				success: function() {
						var v = document.createElement("video");
						if ( !v.play ) {
							$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').text("Your browser does not support HTML5 audio/video. Please go back and download the media file directly.");
						} else {
							$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').html(html5VideoEmbed);
						}
					}
			});
		break;
		default:
			$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').load($hijax(this).attr('href'));
	}
}

$hijax(document).ready(function() {
	/* Create/remove loading animation and some written feedback for visitors to see during the ajax request, as they're waiting for content to load. */
	$hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').ajaxStart(function() {
		$hijax("<div id='hijaxInProgress'><div id='hijaxLoadingFeedback'><p class='loadingMessage1'>Please wait as the content is loaded.</p><p class='loadingMessage2'>Thanks for your patience.</p></div></div>").insertBefore('#stacks_in_133_page0');
		$hijax('#hijaxInProgress').animate({height: '120px'}, 400, function() {
			$hijax('#hijaxInProgress .loadingMessage1').delay(3500).fadeTo(1000, 1, function(){
				$hijax('#hijaxInProgress .loadingMessage2').delay(4500).slideDown().fadeIn(1000);	
			});
		});
	}).ajaxStop(function() {
		$hijax('#hijaxInProgress').fadeTo(300, 0, function(){
			$hijax(this).slideUp(300, function(){
				$hijax(this).remove();
				$hijax('.nimblehost_viewHijaxContent_stacks_in_133_page0').slideDown(500, function(){
					$hijax(this).fadeTo(300, 1);
					/* Resize images that are too large for the area they are being displayed in. */
					if ( $hijax('#nimblehost_hijaxContentDetails_stacks_in_133_page0').width() < $hijax('.hijaxMedia img.hijaxImage').width() ) {
						$hijax('.hijaxMedia img.hijaxImage').delay(400).animate({width: '100%', filter: 'progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF)'}, 500);
					} else {
						/* Check for png files in IE, to fix the jagged black edges that appear when such images with transparency are loaded via ajax. */
						if ($hijax('.hijaxMedia img.hijaxImage').is(':visible')) {
							var fileExtension = $hijax('.hijaxMedia img.hijaxImage').attr('src').split('.').pop().toLowerCase();
							if ( !($hijax.support.opacity) && (fileExtension == 'png') ) {
								$hijax('.hijaxMedia img.hijaxImage').css({filter: 'progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF)'});
							}
						}
					}
				});
			});
		});
	});

	$hijax('a.hijax').live('click', function(e) {
		var fileLink = $hijax(this).attr('href');
		var fileExtension = $hijax(this).attr('href').split('.').pop().toLowerCase();

		if ( fileExtension == 'pdf' || fileExtension == 'rtf' ) { 
			return;
		} else {
			/* Check if other Hijax content is already being displayed. */
			if ( $hijax('.nimblehost_viewHijaxContent_stacks_in_133_page0').is(':visible') ) {
				$hijax('.nimblehost_viewHijaxContent_stacks_in_133_page0').fadeTo(300, 0).slideUp(500, function(){
					activateHijax(fileExtension, fileLink);
				});
			} else {
				$hijax('.nimblehost_hijaxContent_stacks_in_133_page0').fadeTo(300, 0).slideUp(500);
				activateHijax(fileExtension, fileLink);
				$hijax("<p><a class='hideHijaxedContent' href='#'>Ausblenden<br/></a></p>").insertBefore('.nimblehost_viewHijaxContent_stacks_in_133_page0');
				$hijax('a.hideHijaxedContent').fadeIn(800);
			}
			e.preventDefault();
		}
		
		$hijax('a.hideHijaxedContent').live('click', function(e){
			if ( $hijax('#hijaxInProgress').is(':visible') ){
				$hijax('#hijaxInProgress').fadeTo(300, 0, function(){
					$hijax(this).slideUp(300, function(){
						$hijax(this).remove();
					});
				});
			}
			$hijax('.nimblehost_viewHijaxContent_stacks_in_133_page0').fadeTo(300, 0, function(){ $hijax('a.hideHijaxedContent').parent().fadeOut().remove(); }).slideUp(500);
			$hijax('.nimblehost_hijaxContent_stacks_in_133_page0').slideDown(800).fadeTo('normal', 1);
			e.preventDefault();
		});
	});
	
	
});
	return stack;
})(stacks.stacks_in_133_page0);



