

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RanjSingh.com - Miscellaneous Scripts

Copyright (c) 2007-2011 Ranj Singh. All rights reserved.

Created: 2011-06-06

Revision History:
  0.01	- Initial version. TB, 2011-06-06, 22:46

To Do List:
	- figure out Highslide HTML
	- MailChimp integration
	- print mode
	- update the pictures and videos
	- image map links to the guys' bio pages to the home page alt 
		banner image

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Misc */

var WTF = 'What the $%#%?!?';
var resetLogoAngle = false;


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Path */

var pathOffset = '\/';
	// pathOffset = '';
	// pathOffset = 'http:\/\/localhost:8888\/';
	// pathOffset = '..\/';
	// pathOffset = 'http:\/\/ranjsingh.com\/';

var URL = location.href;
var URLProtocol = location.protocol;
var URLHostName = location.hostname;
var URLPortNumber = location.port;
var URLPort = URLPortNumber;
	if (URLPort != '') {
		URLPort = ':' + URLPort;
	};
var URLPath = location.pathname;
var URLHash = location.hash;
var URLSearch = location.search;
var URLMinusQueryString = URL;

if ((URL.indexOf('?') != -1) || (URL.indexOf('#') != -1)) {
	var URLMinusQueryStringTemp = '';

	if (URL.indexOf('?') != -1) {
		URLMinusQueryStringTemp = URL.split('?');
		URLMinusQueryString = URLMinusQueryStringTemp[0];
	} else if (URL.indexOf('#') != -1) {
		URLMinusQueryStringTemp = URL.split('#');
		URLMinusQueryString = URLMinusQueryStringTemp[0];
	};
};

var URLReconstructed = URLProtocol + '\/\/' + URLHostName + URLPort + URLPath;


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Browser detection */

var agent = '';
if (navigator.userAgent) { 
	agent = navigator.userAgent.toLowerCase();
} else { 
	agent = navigator.appVersion.toLowerCase();
};

var is_ie = (agent.indexOf('msie') != -1);
var is_ie6 = (is_ie && (agent.indexOf('msie 6.0') != -1));
var is_ie7 = (is_ie && (agent.indexOf('msie 7.0') != -1));
var is_ie8 = (is_ie && (agent.indexOf('msie 8.0') != -1));
var is_ie9 = (is_ie && ((agent.indexOf('msie 9.0') != -1) || ((agent.indexOf('msie 7.0') != -1) && (agent.indexOf('trident\/5.') != -1))));
var is_ie6up = (is_ie && (is_ie6 || is_ie7 || is_ie8 || is_ie9));
var is_ie7up = (is_ie && (is_ie7 || is_ie8 || is_ie9));
var is_ie8up = (is_ie && (is_ie8 || is_ie9));

var is_webkit = (agent.indexOf('webkit') != -1);
var is_ipad = (agent.indexOf('ipad') != -1);
var is_iphone = (agent.indexOf('iphone') != -1);
var is_ipod = (agent.indexOf('ipod') != -1);
	if (is_ipod || is_ipad) {
		is_iphone = 0;
	};
var is_safari_mobile = ((agent.indexOf('version\/5.0') != -1) && (agent.indexOf('safari mobile') != -1));


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Writing CSS into the page */

var iSSHTML = '';

iSSHTML += ' div#header div#menu { display: none; }';
// iSSHTML += ' div#content { display: none; }';

if (is_ie) {
	iSSHTML += ' hr { width: 100%; margin-top: 0px; } hr.withLeading { margin-top: 0px; }';

	iSSHTML += ' #content { overflow: hidden !important; }';

	iSSHTML += ' div#mc_embed_signup form#mc-embedded-subscribe-form div.mc-field-group p#mce-FNAME-Container input#mce-FNAME, div#mc_embed_signup form#mc-embedded-subscribe-form div.mc-field-group p#mce-LNAME-Container input#mce-LNAME, div#mc_embed_signup form#mc-embedded-subscribe-form div.mc-field-group p#mce-EMAIL-Container input#mce-EMAIL { padding: 2px 0px 0px 6px; }';

	iSSHTML += ' div#copyright { padding-bottom: 1px; }';

	if (!is_ie9) {
		iSSHTML += ' div#mc_embed_signup form#mc-embedded-subscribe-form div.mc-embedded-subscribe-wrapper input#mc-embedded-subscribe { height: 30px; margin-top: -9px; }';
	};

	if (!is_ie7up) {
		iSSHTML += ' body#index h1, body#bio h1, body#news h1, body#newsArchive h1, body#music h1, body#purchase h1, body#shows h1, body#pastShows h1, body#blog h1, body#lyrics h1, body#pictures h1, body#contacts h1, body#HevyDMusic h1, body#legalStuff h1, body#errorDocument404 h1, body#thankYou h1 { background-image: url(/media/images/_h1_bgs.gif); }';
	};
};

/*
body#index h1, body#bio h1, body#news h1, body#newsArchive h1, body#music h1, body#purchase h1, body#shows h1, body#pastShows h1, body#blog h1, body#lyrics h1, body#pictures h1, body#contacts h1, body#HevyDMusic h1, body#legalStuff h1, body#errorDocument404 h1 {
	width: 560px;
	height: 0px;
	overflow: hidden;
	margin: -5px 0px 12px -5px;
	padding: 40px 0px 0px 0px;
	background: no-repeat top left url(/media/images/_h1_bgs.png);
*/

iSSHTML = '<style type="text\/css"><!-' + '-\n' + iSSHTML + '\n-' + '-><\/style>'; // media="screen"
if (document.write) {
	document.write(iSSHTML);
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jQuery stuff */

// Exists
$.fn.exists = function() { return $(this).length !== 0; };

// Easy Slider
$.fn.easySlider = function() {};

// Livequery
$.fn.livequery = function() {};

// Load jQuery extensions
function RS2_pI_loadjQueryExtensions() {
	if (document.write) {
		document.write('<s' + 'cr' + 'ipt s' + 'rc="' + pathOffset + '_misc\/jquery_extensions' + '.j' + 's" ty' + 'pe="te' + 'xt\/ja' + 'vas' + 'cr' + 'ip' + 't"><\/s' + 'cr' + 'ip' + 't>');
	};
};
RS2_pI_loadjQueryExtensions();


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Highslide functionality */

// Load Highslide library
function RS2_pI_loadHighslide() {
	if (document.write) {
		document.write('<s' + 'cr' + 'ipt s' + 'rc="' + pathOffset + '_highslide\/highslide' + '.j' + 's" ty' + 'pe="te' + 'xt\/ja' + 'vas' + 'cr' + 'ip' + 't"><\/s' + 'cr' + 'ip' + 't>');
		document.write('<li' + 'nk type="te' + 'xt\/css" rel="style' + 'sheet" me' + 'dia="scr' + 'een" href="' + pathOffset + '_highslide\/highslide.css" \/>');
	};
};
RS2_pI_loadHighslide();

// Initialize Highslide
function RS2_pI_initializeHighslide() {
	hs.registerOverlay({
		className: 'highslideControlbar',
		fade: 2, // fading the semi-transparent overlay looks bad in IE
		html: '<div class="closebutton" onclick="closeHighslideContent(this);" title=" Close "><\/div>',
		// overlayId: 'highslideControlbar',
		position: 'top right',
		useOnHtml: true
	});

	hs.align = 'center';
	hs.dimmingOpacity = 0.85;
	hs.fadeInOut = true;
	hs.graphicsDir = pathOffset + '_highslide\/graphics\/';
	hs.minWidth = 300;
	// hs.numberOfImagesToPreload = 1;
	// hs.outlineType = null;
	hs.outlineType = 'drop-shadow-yellowish';
	hs.padToMinWidth = true;
	hs.showCredits = false;
	hs.transitions = ['expand', 'crossfade'];
	// hs.wrapperClassName = 'wide-border';
	// hs.wrapperClassName = 'controls-in-heading draggable-heading';

	// Disable dragging of highslide images
	hs.Expander.prototype.onDrag = function (sender, e) { return false; }; 
};

// Highslide close function
function closeHighslideContent(objectHandler) {
	return hs.close(objectHandler);
};

// Initialize Highslide image galleries
var highslideSlideshowInterval = 5000;
var highslideHideControlsOnMouseOut = true;
	if (is_iphone || is_ipod || is_ipad || is_safari_mobile) {
		highslideHideControlsOnMouseOut = false;
	};

function RS2_pI_initializeHighslideImageGalleries() {
	$('div.highslideImageGallery, span.highslideImageGallery').each( function() {
		hs.addSlideshow({
			slideshowGroup: $(this).attr('id'),
			interval: highslideSlideshowInterval,
			repeat: false,
			useControls: true,
			overlayOptions: {
				className: 'highslideImageGalleryOverlay',
				opacity: 0.75,
				position: 'bottom center',
				hideOnMouseOut: highslideHideControlsOnMouseOut
			}
		});
	});
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Flash Player detection variables */

var flashinstalled = 0;
var flashversion = 0;
var FlashPlayerVersionMinor = 0;
var FlashPlayerVersionRevision = 0;

var FlashPlayerVersionRequired = 8;
var FlashPlayerPluginObject = '';
// var FlashMSDetect = "false";


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QuickTime Player detection variables */

var QuickTimePlayerInstalled = 0;
var QuickTimePlayerVersion = 0;
// var QuickTimePlayerVersionMinor = 0;
// var QuickTimePlayerVersionRevision = 0;

var QuickTimePlayerVersionRequired = 6;
var QuickTimePlayerPluginObject = '';
// var QuickTimePlayerMSDetect = "false";


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Folder depth */

if ((fDPO == 'undefined') || (fDPO == null)) {
	var fDPO = ''; // folderDepthPathOffset
};
if ((mFPO == 'undefined') || (mFPO == null)) {
	var mFPO = ''; // mediaFolderPathOffset
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Player detection */

// Internet Explorer
if (window.ActiveXObject) {
	// Flash detection
	try {
		FlashPlayerObject = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');

		if (FlashPlayerObject) {
			flashinstalled = 2;

			FlashPlayerVersionTemp = FlashPlayerObject.GetVariable('$version');
			FlashPlayerVersionTempArray = FlashPlayerVersionTemp.split(' ')[1].split(','); // .toLowerCase().split('win ');

			flashversion = parseInt(FlashPlayerVersionTempArray[0], 10);
			FlashPlayerVersionMinor = parseInt(FlashPlayerVersionTempArray[1], 10);
			FlashPlayerVersionRevision = parseInt(FlashPlayerVersionTempArray[2], 10);
		};
	} catch(err) {
			flashinstalled = 1;
	};

	// QuickTime Detection
	try {
		QuickTimePlayerObject = new ActiveXObject('QuickTimeCheckObject.QuickTimeCheck.1');

		if (QuickTimePlayerObject) {
			if (QuickTimePlayerObject.IsQuickTimeAvailable(0)) {
				QuickTimePlayerInstalled = 1;
				QuickTimePlayerVersion = Math.round((QuickTimePlayerObject.QuickTimeVersion.toString(16, 10) / 1000000) * 10) / 10;
			};
		};
	} catch(err) {
			
	};

// Else if the plugins array exists
} else if (navigator.plugins && (navigator.plugins.length > 0)) {
	FlashPlayerPluginObject = navigator.plugins['Shockwave Flash'];

	// Flash detection
	if (FlashPlayerPluginObject) {
		flashinstalled = 2;

		if (FlashPlayerPluginObject.description) {
			var pluginDescription = FlashPlayerPluginObject.description;

			flashversion = pluginDescription.split('.')[0].split('Shockwave Flash ')[1];

			var FlashVersionSplitBy = ' r';
			if (pluginDescription.indexOf(' d') != -1) {
				FlashVersionSplitBy = ' d';
			};

			FlashPlayerVersionMinor = pluginDescription.split('.')[1].split(FlashVersionSplitBy)[0];
			FlashPlayerVersionRevision = pluginDescription.split('.')[1].split(FlashVersionSplitBy)[1];
		};

	} else {
		flashinstalled = 1;
		if (navigator.plugins['Shockwave Flash 2.0']) {
			flashinstalled = 2;
			flashversion = 2;
		};
	};

	// QuickTime Detection
	for (loop00 = 0; loop00 < navigator.plugins.length; loop00++) {
		if (navigator.plugins[loop00].name.indexOf('QuickTime') != -1) { 
			QuickTimePlayerInstalled = 1;
			QuickTimePlayerVersion = parseFloat(navigator.plugins[loop00].name.substring(18));
		};
	};

// Else
} else if ((navigator.mimeTypes) && (navigator.mimeTypes.length)) {
	FlashPlayerPluginObject = navigator.mimeTypes['application/FlashPlayerPluginObject-shockwave-flash'];

	if ((FlashPlayerPluginObject) && (FlashPlayerPluginObject.enabledPlugin)) {
		flashinstalled = 2;
	} else {
		flashinstalled = 1;
	};
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Flash and QuickTime object embedding */

var eFM_ObjectTagHTML = ''; // embeddedFlashMovie_ObjectTagHML
var eFM_EmbedTagHTML = ''; // embeddedFlashMovie_EmbedTagHTML

function embedFlashMovie(eFM_Filename, eFM_Container, eFM_PlayerVersion, eFM_Width, eFM_Height, eFM_OptionalParameters) {
	eFM_ObjectTagHTML = '';
	eFM_EmbedTagHTML = '';

	if (document.getElementById(eFM_Container)) {
		var e_FlashContainer = document.getElementById(eFM_Container); // FlashContainerElement

		var eFM_IdAttribute01HTML = '';
		var eFM_IdAttribute02HTML = '';

		if (eFM_OptionalParameters) {
			var eFM_Temp01 = eFM_OptionalParameters.split(',');

			for (loop00 = 0; loop00 < eFM_Temp01.length; loop00++) {
				eFM_Temp02 = eFM_Temp01[loop00].split('=');

				if (eFM_Temp02[0] == 'id') {
					eFM_IdAttribute01HTML += 'id="' + eFM_Temp02[1] + '" ';
					eFM_IdAttribute02HTML += 'name="' + eFM_Temp02[1] + '" ';
				};
			};
		};

		// if (eFM_Filename.indexOf('http:\/\/') == -1) {
		if (eFM_Filename.indexOf('\/') == -1) {
			eFM_Filename = fDPO + mFPO + 'media\/flash\/' + eFM_Filename;
		};

		eFM_ObjectTagHTML += '<object ' + eFM_IdAttribute01HTML + 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=' + eFM_PlayerVersion + ',0,0,0" width="' + eFM_Width + '" height="' + eFM_Height + '">';
		eFM_ObjectTagHTML += '<param name="movie" value="' + eFM_Filename + '" \/>';

		eFM_EmbedTagHTML += '<embed ' + eFM_IdAttribute02HTML + 'pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer" type="application\/x-shockwave-flash" src="' + eFM_Filename + '" width="' + eFM_Width + '" height="' + eFM_Height + '"';

		if (eFM_OptionalParameters) {
			for (loop00 = 0; loop00 < eFM_Temp01.length; loop00++) {
				eFM_Temp02 = eFM_Temp01[loop00].split('=');

				if (eFM_Temp02[0] != 'id') {
					eFM_ObjectTagHTML += '<param name="' + eFM_Temp02[0] + '" value="' + eFM_Temp02[1] + '" />';

					eFM_EmbedTagHTML += ' ' + eFM_Temp02[0] + '="' + eFM_Temp02[1] + '"';
				};
			};
		};

		eFM_EmbedTagHTML += '><\/embed>';
		eFM_ObjectTagHTML += eFM_EmbedTagHTML + '<\/object>';

		if ((flashinstalled == 2) && (flashversion >= eFM_PlayerVersion)) {
			e_FlashContainer.innerHTML = eFM_ObjectTagHTML;
		};
	} else {
		// alert('The necessary container element does NOT exist...');
	};
};

var eQTM_ObjectTagHTML = ''; // embeddedQuickTimeMovie_ObjectTagHML
var eQTM_EmbedTagHTML = ''; // embeddedQuickTimeMovie_EmbedTagHTML

function embedQuickTimeMovie(eQTM_Filename, eQTM_Container, eQTM_PlayerVersion, eQTM_Width, eQTM_Height, eQTM_OptionalParameters) {
	eQTM_ObjectTagHTML = '';
	eQTM_EmbedTagHTML = '';

	if (document.getElementById(eQTM_Container)) {
		var e_QuickTimeContainer = document.getElementById(eQTM_Container); // QuickTimeContainerElement

		var eQTM_IdAttribute01HTML = '';
		var eQTM_IdAttribute02HTML = '';

		if (eQTM_OptionalParameters) {
			var eQTM_Temp01 = eQTM_OptionalParameters.split(',');

			for (loop00 = 0; loop00 < eQTM_Temp01.length; loop00++) {
				eQTM_Temp02 = eQTM_Temp01[loop00].split('=');

				if (eQTM_Temp02[0] == 'id') {
					eQTM_IdAttribute01HTML += 'id="' + eQTM_Temp02[1] + '" ';
					eQTM_IdAttribute02HTML += 'name="' + eQTM_Temp02[1] + '" ';
				} else if ((eQTM_Temp02[0] == 'controller') && (eQTM_Temp02[1] == 'true')) {
					eQTM_Height += 16;
				};
			};
		};

		// if (eQTM_Filename.indexOf('http:\/\/') == -1) {
		if (eQTM_Filename.indexOf('\/') == -1) {
			eQTM_Filename = fDPO + mFPO + 'media\/quicktime\/' + eQTM_Filename;
		};

		eQTM_ObjectTagHTML += '<object ' + eQTM_IdAttribute01HTML + 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http:\/\/www.apple.com\/qtactivex\/qtplugin.cab" width="' + eQTM_Width + '" height="' + eQTM_Height + '">';
		eQTM_ObjectTagHTML += '<param name="type" value="video\/quicktime" \/>';
		eQTM_ObjectTagHTML += '<param name="src" value="' + eQTM_Filename + '" \/>';

		eQTM_EmbedTagHTML += '<embed ' + eQTM_IdAttribute02HTML + 'pluginspage="http:\/\/www.apple.com\/quicktime\/download\/" type="video\/quicktime" src="' + eQTM_Filename + '" width="' + eQTM_Width + '" height="' + eQTM_Height + '"';

		if (eQTM_OptionalParameters) {
			for (loop00 = 0; loop00 < eQTM_Temp01.length; loop00++) {
				eQTM_Temp02 = eQTM_Temp01[loop00].split('=');

				if (eQTM_Temp02[0] != 'id') {
					eQTM_ObjectTagHTML += '<param name="' + eQTM_Temp02[0] + '" value="' + eQTM_Temp02[1] + '" />';

					eQTM_EmbedTagHTML += ' ' + eQTM_Temp02[0] + '="' + eQTM_Temp02[1] + '"';
				};
			};
		};

		eQTM_EmbedTagHTML += '><\/embed>';
		eQTM_ObjectTagHTML += eQTM_EmbedTagHTML + '<\/object>';

		if (QuickTimePlayerInstalled && (QuickTimePlayerVersion >= eQTM_PlayerVersion)) {
			e_QuickTimeContainer.innerHTML = eQTM_ObjectTagHTML;
		};
	} else {
		// alert('The necessary container element does NOT exist...');
	};
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Misc functions */

var bodySelectorText = 'html, body';
	if (is_webkit) {
		bodySelectorText = 'body';
	};

// Scroll to top of the page
function RS2_sTTOTP() {
	$(bodySelectorText, top.document).animate({scrollTop: 0}, 600);
};

// Scroll menu with page
function RS2_pI_sMWP() {
	if ($('body').attr('id') == 'index') {
		// return;
	};

	$(window).bind('scroll', function() {
		if ($(bodySelectorText).scrollTop() > $('#leftColumn').offset().top) {
			$('#leftColumn')
				.stop()
				// .delay(300)
				.animate({
					'padding-top': ($(bodySelectorText, top.document).scrollTop() - $('#leftColumn').offset().top + 10)
				}, 800, function() {
					if (!($('ul#menu li#scrollToTopLinkContainer').exists())) {
						$('ul#menu').append('<li id="scrollToTopLinkContainer"><a href="topOfPage" onclick="RS2_sTTOTP(); return false;" title=" Scroll up to the top of the page... ">Scroll Up<\/a><\/li>');
						
					} else {
						
					};
						$('ul#menu li#scrollToTopLinkContainer').animate({
							'height': 'show'
						});
				});
		} else {
			$('#leftColumn')
				.stop()
				// .delay(300)
				.animate({
					'padding-top': 0
				}, 800, function() {
					$('ul#menu li#scrollToTopLinkContainer').animate({
						'height': 'hide'
					});
				});
		};
	});
};

// Show mailing list form
function RS2_sMLF(scrollPage) {
	$('form#mc-embedded-subscribe-form h2:first').trigger('click'); 

	if (scrollPage) {
		if ($(bodySelectorText, top.document).scrollTop() == 0) {
			if ($('body').attr('id') == 'index') {
				$(bodySelectorText, top.document).delay(100).animate({ scrollTop: ($('#content').offset().top - 30)}, 600);
			} else {
				$(bodySelectorText, top.document).delay(100).animate({ scrollTop: $('form#mc-embedded-subscribe-form').offset().top }, 600); 
			};
		} else {
			$(bodySelectorText, top.document).delay(200).animate({ scrollTop: 0 }, 600); 
		};
	};

	return false;
};

// Load external content stub...
function RS2_lECS(URLToLoad, IdToLoadInto) {
	if ($('#' + IdToLoadInto).exists()) {
		$('#' + IdToLoadInto)
			.addClass('contentLoading')
			.animate({
				'min-height': 100
			}, 400, function() {
				setTimeout( function() {
					$('#' + IdToLoadInto).load(URLToLoad, RS2_lECS_Response(IdToLoadInto));
				}, 1000);
			});

		return false;
	};
};
	function RS2_lECS_Response(IdToLoadInto) {
		if ($('#' + IdToLoadInto + 'LinkContainer').exists()) {
			$('#' + IdToLoadInto + 'LinkContainer')
				.delay(100)
				.animate({
					'opacity': 0,
					'height': 'hide'
				}, 300);
		};

		if ($('#' + IdToLoadInto).exists()) {
			$('#' + IdToLoadInto)
				.removeClass('contentLoading')
				.animate({
					// 'height': 'show'
				});
		};
	};

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Page initialization and finalization */

// Reflow the page
function RS2_pI_reflowPage() {
	// Head
	$_head = $('head');

	// Body
	$_body = $('body');

	// Header
	$_header = $('div#header');
	$_logo = $('img#logo');
	$_logoLink = $('a#logoLink');
		$_logoLink
			.bind('contextmenu', function() {
				clearTimeout(resetLogoAngle);

				$_logo.rotate({
					animateTo: 359
				});

				resetLogoAngle = setTimeout(
					function() {
						$_logo.rotate(0);
					}, 800);

				return false;
			});

	// Menu
	$_menu = $('ul#menu');

	// Social media links
	$_socialMediaLinks = $('div#socialMediaLinks');

	// Mail chimp signup form
	$_MailChimpForm = $('div#mc_embed_signup');

	// Left column
	$_leftColumn = $('<div id="leftColumn"><\/div>');
	$_leftColumnCapTop = $('<div id="leftColumnCapTop" class="narrowColumnCapTop"><\/div>');
	$_leftColumnCentre = $('<div id="leftColumnCentre" class="narrowColumnCentre"><\/div>');
		$_leftColumnCentre.append($_MailChimpForm);
		$_leftColumnCentre.append($_menu);
		$_leftColumnCentre.append($_socialMediaLinks);
	$_leftColumnCapBottom = $('<div id="leftColumnCapBottom" class="narrowColumnCapBottom"><\/div>');
	$_leftColumn.append($_leftColumnCapTop);
	$_leftColumn.append($_leftColumnCentre);
	$_leftColumn.append($_leftColumnCapBottom);
	$_leftColumn.insertAfter($('div#header'));

	// Content
	e_content = $('div#content');
	$_contentColumn = $('<div id="contentColumn"><\/div>');

	// Banner
	$_banner = $('div#banner');
	if ($_banner) {
		$_leftColumn.addClass('withBanner');
		$_contentColumn.addClass('withBanner');

		$_banner.detach()
		$_banner.insertAfter($('div#header'));
	};

	// Content containers
	$_contentColumnCapTop = $('<div id="contentColumnCapTop" class="wideColumnCapTop"><\/div>');
	$_contentColumnCentre = $('<div id="contentColumnCentre" class="wideColumnCentre"><\/div>');
		$_contentColumnCentre.append($('div#content'));
	$_contentColumnCapBottom = $('<div id="contentColumnCapBottom" class="wideColumnCapBottom"><\/div>');

	$_contentColumn.append($_contentColumnCapTop);
	$_contentColumn.append($_contentColumnCentre);

	$_contentColumn.append($_contentColumnCapBottom);

	$_contentColumn.insertAfter($('div#leftColumn'));
};

// Rework MailChimp signup form
var emailAddressRegExp = /^.+@.+\..{2,4}$/;

function RS2_pI_reworkMailChimpSignupForm() {
	if ($('form#mc-embedded-subscribe-form').exists()) {
		$('form##mc-embedded-subscribe-form div.mc-field-group').css({
			'display': 'none'
		});

		$('form#mc-embedded-subscribe-form h2:first')
			.css({
				// 'cursor': 'pointer'
			})
			.bind('click', function() {
				$('div.mc-field-group').animate({
					'height': 'toggle'
				}, 200, function() {
					$('form#mc-embedded-subscribe-form h2:first').css({
						// 'cursor': 'default'
					})
					.toggleClass('active');
				});
			});

		$('form#mc-embedded-subscribe-form input[type="email"], form#mc-embedded-subscribe-form input[type="text"]').each( function() {
			thisInitialValue = $(' > label:first', $(this).parent()).text();
			$(' > label:first', $(this).parent()).css({
				'display': 'none'
			});

			$(this)
				.css({
					// 'border-color': 'red'
				})
				.attr('title', ' ' + $(this).attr('title') + '... ')
				.attr('initialValue', thisInitialValue)
				.val(thisInitialValue)
				// .unbind('focus')
				.bind('focus', function() {
					$(this)
						.removeClass('warning')
						.css({
							'color': '#333333'
						});

					if ($(this).val() == $(this).attr('initialValue')) {
						$(this)
							.val('');

					} else if ($(this).val() != $(this).attr('initialValue')) {

					};
				})
				// .unbind('blur')
				.bind('blur', function() {
					if (($(this).val() == '') || ($(this).val() == ' ')) {
						$(this)
							.val($(this).attr('initialValue'));

					};

					if ($(this).val() == $(this).attr('initialValue')) {
						$(this)
							.css({
								'color': '#999999'
							});

					} else if ($(this).val() != $(this).attr('initialValue')) {
						$(this)
							.css({
								'color': '#333333'
							});
					};
				});
		});

		$_MailChimpSignupFormEmailField = $('form#mc-embedded-subscribe-form input#mce-EMAIL');
			MailChimpSignupFormEmailFieldInitialValue = $_MailChimpSignupFormEmailField.attr('initialValue');
		// $_MailChimpSignupFormEmailField
			// .unbind('click');

		$_MailChimpSignupFormSubmitButton = $('form#mc-embedded-subscribe-form input#mc-embedded-subscribe');

		$_MailChimpSignupFormSubmitButton
			.attr('title', ' ...and click here to ' + $_MailChimpSignupFormSubmitButton.attr('title').toLowerCase() + '! ')
			.unbind('click').bind('click', function() {
				if (!(emailAddressRegExp.test($_MailChimpSignupFormEmailField.val()))) {
					$_MailChimpSignupFormEmailField
						.addClass('warning')
						.val(MailChimpSignupFormEmailFieldInitialValue)
						.css({
							'color': '#ffffff',
							'background-color': '#dd2222'
						})
						.delay(1000).animate({
							'color': '#999999',
							'background-color': '#ffffff'
						}, 750, function() {
							$_MailChimpSignupFormEmailField.removeClass('warning');
						});

					return false;

				} else {
					$('form#mc-embedded-subscribe-form').submit();
				};
			});
	};
};

// Highlight navigation
function RS2_pI_highlightNav() {
	// All links
	$('a').each( function() {
		if (((URLProtocol + '\/\/' + URLHostName + URLPort + '\/' + $(this).attr('href')) == URLReconstructed) || ((URLProtocol + '\/\/' + URLHostName + URLPort + $(this).attr('href')) == URLReconstructed)) {
			$(this).addClass('highlighted').unbind('click').bind('click', function() {
				return false;
			}).bind('contextmenu', function() {
				return false;
			});
		};

		// Remove markup from the title attribute
		thisTitleText = $(this).attr('title');
		$(this).attr('highslideCaption', thisTitleText);
		$(this).attr('title', thisTitleText.replace(/<.*?>/gi, ''));
	});
};

// Initialize livequeries
function RS2_pI_initializeLiveQueries() {
	// Cloaked email links
	$('a.cloakedEmail').livequery( function() {
		if (($(this).attr('href').indexOf('%28-at-%29') != -1) && ($(this).attr('href').indexOf('mailto:') != -1)) {
			emailAddressHTMLTemp = $(this).attr('href').split('%28-at-%29');
			emailAddressHTML = emailAddressHTMLTemp[0] + '@' + emailAddressHTMLTemp[1];
			$(this).attr('href', emailAddressHTML);

			if ($(this).text().indexOf('%28-at-%29') != -1) {
				if (emailAddressHTML.split('mailto:')[1].split('?').length == 0) {
					$(this).text(emailAddressHTML.split('mailto:')[1]);
				} else {
					$(this).text(emailAddressHTML.split('mailto:')[1].split('?')[0]);
				};
			};
		};

		if (($(this).attr('href').indexOf('(-at-)') != -1) && ($(this).attr('href').indexOf('mailto:') != -1)) {
			emailAddressHTMLTemp = $(this).attr('href').split('(-at-)');
			emailAddressHTML = emailAddressHTMLTemp[0] + '@' + emailAddressHTMLTemp[1];
			$(this).attr('href', emailAddressHTML);

			if ($(this).text().indexOf('(-at-)') != -1) {
				if (emailAddressHTML.split('mailto:')[1].split('?').length == 0) {
					$(this).text(emailAddressHTML.split('mailto:')[1]);
				} else {
					$(this).text(emailAddressHTML.split('mailto:')[1].split('?')[0]);
				};
			};
		};
	});

	// External links
	$('a.external').livequery( function() {
		e_CL_WindowName = '_blank';
		if ($(this).attr('class').indexOf('external ') != -1) {
			e_CL_WindowName = $(this).attr('class').split(' ')[($(this).attr('class').split(' ').length - 1)]; // .replace(regExpStr03,'');
		};

		$(this).attr('target', e_CL_WindowName);

		if (!($(this).attr('title'))) {
			$(this).attr('title', ' Link opens in a new window\/tab... ');
		};
	});

	// Image links
	$('a > img').livequery( function() {
		$(this).parent().css({
			'border': '0px dashed lime'
		});

		if (!$(this).hasClass('highslideThumbnail')) {
			$(this).css({
				'border': '0px dashed lime'
			});
		};
	});

	// Highslide stuff
	$('a.highslideImage img, a.highslideImageGallery img').each( function() {
		// Remove markup from the alt attribute, while preserving it for the caption
		thisAltText = $(this).attr('alt');
		$(this).attr('highslideCaption', thisAltText);
		$(this).attr('alt', thisAltText.replace(/<.*?>/gi, ''));
		// $(this).attr('title', thisAltText.replace(/<.*?>/gi, ''));
	});
	$('a.highslideImage').bind('click', function() {
		// Set y-position
		// targetYCode = 'innerContainer 0px';

		// Scroll to top of the page
		// RS2_sTTOTP();

		// Is the first childNode a tag?
		if (this.childNodes[0].nodeType == 1) {
			if (this.childNodes[0].tagName.toLowerCase() == 'img') {
				// Grab caption contents
				captionCode = '';
				if (this.childNodes[0].getAttribute('highslideCaption') != '') {
					captionCode = this.childNodes[0].getAttribute('highslideCaption');
				};

				// Call highslide method
				// return hs.expand(null, { src: this.getAttribute('href'), captionText: captionCode }); // targetY: targetYCode
			};

		// Otherwise it's a text link
		} else if (this.childNodes[0].nodeType == 3) {
			// Grab caption contents
			captionCode = '';
			if (this.title != '') {
				captionCode = this.title;
			};

			// Call highslide method
			// return hs.expand(null, { src: this.getAttribute('href'), captionText: captionCode }); // targetY: targetYCode
		};

		// Call highslide method
		return hs.expand(null, { src: this.getAttribute('href'), captionText: captionCode }); // targetY: targetYCode
	});
	$('a.highslideImageGallery').each( function(loopCounter) {
		// Set y-position
		// targetYCode = 'innerContainer 0px';

		this.onclick = function() {
			// Scroll to top of the page
			// RS2_sTTOTP();

			// Grab caption contents
			captionCode = '';
			if (this.childNodes[0].getAttribute('highslideCaption') != '') {
				captionCode = this.childNodes[0].getAttribute('highslideCaption');
			};

			thumbnailCode = '';
			slideshowCode = '';

			if ($(this).parent().hasClass('highslideImageGallery')) {
				slideshowCode = $(this).parent().attr('id');
				if (!($(this).parent().hasClass('noThumbnail'))) {
					thumbnailCode = $(this).parent().attr('id') + '_Thumbnail';
				};

			} else if ($(this).parent().parent().hasClass('highslideImageGallery')) {
				slideshowCode = $(this).parent().parent().attr('id');
				if (!($(this).parent().parent().hasClass('noThumbnail'))) {
					thumbnailCode = $(this).parent().parent().attr('id') + '_Thumbnail';
				};
			};

			// Call highslide method
			return hs.expand(this, { slideshowGroup: slideshowCode, thumbnailId: thumbnailCode, captionText: captionCode });

			// if ($(this).hasClass('highslideImageGallery')) {
				/* if ($(this).parent().hasClass('highslideImageGallery')) {
					return hs.expand(this, { slideshowCode, thumbnailCode, captionCode });

				} else if ($(this).parent().parent().hasClass('highslideImageGallery')) {
					return hs.expand(this, { slideshowGroup: this.parentNode.parentNode.id, thumbnailId: ('galleryGroupLink' + this.parentNode.parentNode.id.split('Container')[1]), captionText: captionCode });
				}; */
			// };
		};
	});

	// Song lyrics
	$('div.songLyrics').livequery( function() {
		$('p', $(this)).css({
			'display': 'none'
		});

		$(this).addClass('restyled').bind('click', function() {
			$(this).toggleClass('restyled')
			$('p', $(this)).slideToggle();
		}).bind('contextmenu', function() {
			/* $('div.songLyrics p').css({
				'display': 'none'
			}).slideDown(); */

			$('div.songLyrics').trigger('click');

			return false;
		});
	});
};

// Page initialization
function RS2_pI() {
	// Reflow the page
	RS2_pI_reflowPage();

	// Rework MailChimp signup form
	RS2_pI_reworkMailChimpSignupForm();

	// Initialize highslide
	RS2_pI_initializeHighslide();

	// Initialize highslide images and galleries
	RS2_pI_initializeHighslideImageGalleries();

	// Highlight navigation
	RS2_pI_highlightNav();

	// Scroll menu with page
	RS2_pI_sMWP();

	// Initialize livequeries
	RS2_pI_initializeLiveQueries();
};

// Additional page initialization
function RS2_aPI() {
	// ?
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Window/document level events */

$(document).ready(function() {
	RS2_pI();	// pageInitialization
	RS2_aPI();	// additionalPageInitialization
});


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MailChimp stuff */

var fnames = new Array();
var ftypes = new Array();
fnames[0]='EMAIL';
ftypes[0]='email';
fnames[1]='FNAME';
ftypes[1]='text';
fnames[2]='LNAME';
ftypes[2]='text';

try {
	var jqueryLoaded = jQuery;
	jqueryLoaded = true;
} catch(err) {
	var jqueryLoaded=false;
};

var e_head = document.getElementsByTagName('head')[0];

if (!jqueryLoaded) {
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js';
	e_head.appendChild(script);
	if (script.readyState && script.onload !== null) {
		script.onreadystatechange = function () {
			if (this.readyState == 'complete') {
				mce_preload_check();
			};
		};	
	};
};

var MailChimpScript = document.createElement('script');
MailChimpScript.type = 'text\/javascript';
MailChimpScript.src = 'http:\/\/downloads.mailchimp.com\/js\/jquery.form-n-validate.js';
e_head.appendChild(MailChimpScript);

var err_style = '';
try{
	err_style = mc_custom_error_style;
} catch(e){
	err_style = '#mc_embed_signup input.mce_inline_error{border-color:#6B0505;} #mc_embed_signup div.mce_inline_error{margin: 0 0 1em 0; padding: 5px 10px; background-color:#6B0505; font-weight: bold; z-index: 1; color:#fff;}';
};

// var e_head = document.getElementsByTagName('head')[0];
var MailChimpStyle = document.createElement('style');
MailChimpStyle.type = 'text\/css';
if (MailChimpStyle.styleSheet) {
	MailChimpStyle.styleSheet.cssText = err_style;
} else {
	MailChimpStyle.appendChild(document.createTextNode(err_style));
};
e_head.appendChild(MailChimpStyle);
setTimeout('mce_preload_check();', 250);

var mce_preload_checks = 0;

function mce_preload_check(){
	if (mce_preload_checks > 40) return;
	mce_preload_checks++;
	try {
		var jqueryLoaded=jQuery;
	} catch(err) {
		setTimeout('mce_preload_check();', 250);
		return;
	};
	try {
		var validatorLoaded=jQuery("#fake-form").validate({});
	} catch(err) {
		setTimeout('mce_preload_check();', 250);
		return;
	};
	mce_init_form();
};

function mce_init_form(){
	jQuery(document).ready( function($) {
		var options = { errorClass: 'mce_inline_error', errorElement: 'div', onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
		var mce_validator = $("#mc-embedded-subscribe-form").validate(options);
		$("#mc-embedded-subscribe-form").unbind('submit');//remove the validator so we can get into beforeSubmit on the ajaxform, which then calls the validator
		options = { url: 'http://ranjsingh.us1.list-manage.com/subscribe/post-json?u=959c04e5a19916ce992ccf991&id=0113ae0354&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
      			beforeSubmit: function() {
      				$('#mce_tmp_error_msg').remove();
      				$('.datefield','#mc_embed_signup').each(
      					function() {
      						var txt = 'filled';
      						var fields = new Array();
      						var i = 0;
      						$(':text', this).each(
      							function() {
      								fields[i] = this;
      								i++;
      							});
      						$(':hidden', this).each(
      							function() {
      								var bday = false;
      								if (fields.length == 2){
      									bday = true;
      									fields[2] = {'value':1970};//trick birthdays into having years
      								};
      								if ( fields[0].value=='MM' && fields[1].value=='DD' && (fields[2].value=='YYYY' || (bday && fields[2].value==1970) ) ){
      									this.value = '';
      								} else if ( fields[0].value=='' && fields[1].value=='' && (fields[2].value=='' || (bday && fields[2].value==1970) ) ){
      									this.value = '';
      								} else {
      									this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
      								};
      							});
      					});
      				return mce_validator.form();
      			}, 
      			success: mce_success_cb
      		};

		$('#mc-embedded-subscribe-form').ajaxForm(options);
	});
};

function mce_success_cb(resp){
	$('#mce-success-response').hide();
	$('#mce-error-response').hide();

	if (resp.result=="success") {
		$('#mce-'+resp.result+'-response').show();
		$('#mce-'+resp.result+'-response').html(resp.msg);
		$('#mc-embedded-subscribe-form').each(function(){
			this.reset();
		});

	} else {
		var index = -1;
		var msg;
		try {
			var parts = resp.msg.split(' - ',2);
			if (parts[1] == undefined) {
				msg = resp.msg;
			} else {
				i = parseInt(parts[0]);
				if (i.toString() == parts[0]){
					index = parts[0];
					msg = parts[1];
				} else {
					index = -1;
					msg = resp.msg;
				};
			};
		} catch(e) {
			index = -1;
			msg = resp.msg;
		};
		try {
			if (index == -1) {
				$('#mce-'+resp.result+'-response').show();
				$('#mce-'+resp.result+'-response').html(msg);			
			} else {
				err_id = 'mce_tmp_error_msg';
				html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
				
				var input_id = '#mc_embed_signup';
				var f = $(input_id);
				if (ftypes[index]=='address'){
					input_id = '#mce-'+fnames[index]+'-addr1';
					f = $(input_id).parent().parent().get(0);
				} else if (ftypes[index]=='date'){
					input_id = '#mce-'+fnames[index]+'-month';
					f = $(input_id).parent().parent().get(0);
				} else {
					input_id = '#mce-'+fnames[index];
					f = $().parent(input_id).get(0);
				};
				if (f){
					$(f).append(html);
					$(input_id).focus();
				} else {
					$('#mce-'+resp.result+'-response').show();
					$('#mce-'+resp.result+'-response').html(msg);
				};
			};
		} catch(e) {
			$('#mce-'+resp.result+'-response').show();
			$('#mce-'+resp.result+'-response').html(msg);
		};
	};
};


