
// '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_37_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_37_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_37_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_37_page0').empty();
			},
		timeout: 30000,
		error: function(xhr, error) {
			var generalError;
			if ( xhr.statusText == '' ) { 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 ( error == "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_37_page0").html(hijaxErrorCode + xhr.statusText + " " + 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({
				url: '/',
				success: function() {
						$hijax('#nimblehost_hijaxContentDetails_stacks_in_37_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_37_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_37_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_37_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_37_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_37_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_37_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_37_page0').html(html5VideoEmbed);
						}
					}
			});
		break;
		default:
			$hijax('#nimblehost_hijaxContentDetails_stacks_in_37_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_37_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_37_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_37_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_37_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_37_page0').is(':visible') ) {
				$hijax('.nimblehost_viewHijaxContent_stacks_in_37_page0').fadeTo(300, 0).slideUp(500, function(){
					activateHijax(fileExtension, fileLink);
				});
			} else {
				$hijax('.nimblehost_hijaxContent_stacks_in_37_page0').fadeTo(300, 0).slideUp(500);
				activateHijax(fileExtension, fileLink);
				$hijax("<p><a class='hideHijaxedContent' href='#'>Back</a></p>").insertBefore('.nimblehost_viewHijaxContent_stacks_in_37_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_37_page0').fadeTo(300, 0, function(){ $hijax('a.hideHijaxedContent').parent().fadeOut().remove(); }).slideUp(500);
		$hijax('.nimblehost_hijaxContent_stacks_in_37_page0').slideDown(800).fadeTo('normal', 1);
		e.preventDefault();
	});
});
	return stack;
})(stacks.stacks_in_37_page0);



