$(function() {

$("ul").each(function(i) {

	var ul = $(this);
	ul.find("li:first").addClass("first").end().find("li:last").addClass("last");

})

});

// Easing Plugin 

/*
 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend(jQuery.easing, {
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeOutCool: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);

		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});
var section;

var navIndices = {
	'home': 0,
	'media': 1,
	'blog': 2,
	'about': 3,
	'contact': 4,
	'login': 5
};


$(function() {
	section = $('body')[0].className.substring(5);
	$('body').removeClass('nojs').addClass('js');
	if ($.browser.msie)	$('body').addClass('ie');
	
});

function d(title, str) {
	if (title) title = unescape(title);
	if (str) str = unescape(str);
	
	if (str) $('#debug').prepend('<p><b>' + title + ':</b> ' + str + '</p>');
	else if (title == '-') $('#debug').prepend('<p>------</p>');
	else if (title) $('#debug').prepend('<p>' + title + '</p>');
	else $('#debug').prepend('<br />');

}$(function() {
	initNav();
});

var navHoversDisabled = false;

function initNav() {
	// White or blue
	var fadingTo = 'white';
	var shadowDefault = .55;
	var shadowHover = .20;
	
	//
	// Create needed elements and set intial properties
	//
	$('#navigation li')
		.each(function() {
			var self = this;
			var itemName = this.id.substring(2);
			var active = section == itemName;

			$('.label', this).remove().appendTo(this).css('opacity', 0);
			
			$('a', this).html('<span class="imgs"><img class="grey" src="http://noisefreak.com/lib/i/sandwich/black/navigation/orbs/' + (active ? 'blue' : 'grey') + '/' + itemName + '.png" />\n<img class="' + fadingTo + '" src="http://noisefreak.com/lib/i/sandwich/black/navigation/orbs/' + (active ? 'blue' : fadingTo) + '/' + itemName + '.png" /></span>');
			
			$(this).append('<span class="shadow"></span>');

			$('.grey', this).css('opacity', 1)
			$('.shadow', this).css('opacity', shadowDefault)
			$('.' + fadingTo, this).css('opacity', 0);
			
			
	});	

	//
	// Functions for hover on and off
	//
	var easingImage = 'easeOutBack';
	var easingFade = 'easeOutBack';
	var easingShadow = 'easeOutExpo';
	var easingLabel = 'easeOutSine';
	
	var hovers = [function() {
		if (navHoversDisabled) return;
		
	//	d('Hovering on: ' + this.id);
		// Image
		$('a', this).stop().animate({
			'height': '108px'
		}, 900, easingImage);
		
		// Fade
		$('.' + fadingTo, this).stop().animate({
			'opacity': 1
		}, 800);

		// Shadow
		$('.shadow', this).stop().animate({
			'bottom': '-25px',
			'opacity': shadowHover
		}, 900, easingShadow);
		
		// Label
		$('.label', this).stop().animate({
			'bottom': '30px',
			'opacity': 1
		}, 600, easingLabel);

		
	}, function() {

		// Image
		$('a', this).stop().animate({
			'height': '64px'
		}, 900, 'easeOutBack');

		// Fade
		$('.' + fadingTo, this).stop().animate({
			'opacity': 0
		}, 900);
		
		// Shadow
		$('.shadow', this).stop().animate({
			'bottom': '-17px',
			'opacity': shadowDefault
		}, 900, easingShadow);

		// Label
		$('.label', this).stop().animate({
			'bottom': '10px',
			'opacity': 0
		}, 700, 'easeOutExpo');
		
		
	}];
			
	//
	// Initialize the hovers either all together or one by one
	//
	var initHovers = function(n) {
		/*
			If it's a number:
				Positive: Enable just that one
				Negative: Enable the rest except for that one
			If no argument:
				Enable all of them.		
		*/
	//	d('Init hover: ' + n);
		if (typeof n == 'number')
			if (n > -1)
				$('#navigation li:eq(' + n + ')')
					.one('mouseover', function() { $('#navigation li:eq(' + n + ') a').queue([]).stop(); })
					.hover.apply($('#navigation li:eq(' + n + ')'), hovers);
			else
				$('#navigation li').not(':eq(' + -n + ')')
					.one('mouseover', function() { $('#navigation li').not(':eq(' + -n + ') a').queue([]).stop(); })
					.hover.apply($('#navigation li').not(':eq(' + -n + ')'), hovers);
		else
			$('#navigation ul')
//				.one('mouseover', function() { $('#navigation li a').queue([]).stop();})
				.hover.apply($('#navigation li'), hovers);
		
	};
	
	//
	// Call it in the context of the li with n == index of the element
	// This bounces an icon down
	//
	var bounceDown = function(options) {
	//	d('In bouncedown: ' + this.id);
		var self = this;
		var itemName = this.id.substring(2);
		
	//	if (section == itemName)
	//		$('.grey', this)[0].src = 'lib/i/sandwich/black/navigation/orbs/grey/' + itemName + '.png'
		
		var e = {
			fadeinLength: 600,
			pulseLength: 600,
			dropLength: 1200,
			easing: 'easeOutBack'
		}
		
		if (options) e = jQuery.extend(e, options);
		
		$('.shadow', self).animate({
			'bottom': '-30px',
			'opacity': shadowHover
		}, fadeinLength, e.easing);

		$('a', self)
			.animate({ 'opacity': 1 }, e.fadeinLength, e.easing)
			
			.find('.white')
				.animate({ 'opacity': 1 }, e.pulseLength, function() {
					if (section == itemName)
						$('.grey', self)[0].src = 'http://noisefreak.com/lib/i/sandwich/black/navigation/orbs/blue/' + itemName + '.png'
				})
				.animate({ 'opacity': 0 }, e.pulseLength)
			.end()
			.animate({ 'height': '64px' }, e.dropLength, e.easing);
		
		// Initialize the hovers at a good point in the animation
		setTimeout(function() {
			initHovers.apply(self, [navIndices[itemName]]);
		}, e.dropLength - 150);
		
			// And animate the shadow too
		setTimeout(function() {
			$('.shadow', self).animate({
				'bottom': '-17px',
				'opacity': shadowDefault
			}, e.dropLength, e.easing);
		}, e.fadeinLength)
		
	};

	// If it is not the home page, only drop the active one
	if (section != 'home') {
		var fadeinLength = 250;
	
		var current = $('#navigation li:eq(' + navIndices[section] + ')')[0];
		
		// Set the defaults
		$('a', current).css({
			'height': '108px'
		});
		
		$('.shadow', current).css({
			'bottom': '-30px',
			'opacity': shadowHover
		});
		
		// Label Show the label
		$('.label', current).animate({
			'bottom': '30px',
			'opacity': 1
		}, 900, 'easeOutSine');

		bounceDown.apply(current, [{ 'fadeinLength': fadeinLength, pulseLength: 0 }])

		setTimeout(function() {
			// Also fade out the label
			$('.label', current).stop().animate({
				'bottom': '10px',
				'opacity': 0
			}, 700, 'easeOutExpo');
		}, fadeinLength);	// Same time as it takes for the icon to fade in
		
		initHovers(-navIndices[section]);
		
		/*setTimeout(function() {
			initHovers(navIndices[section])
		}, 600);*/
		
		return;
	}		

	// Bounce them down in a wave on the home page
	var timeout = 0;
	
	$('#navigation li').each(function(n)  {
		var self = this;

		// Set the defaults
		$('a', this).css({
			'height': '128px',
			'opacity': 0
		});
		
		$('.shadow', this).css({
			'bottom': '-30px',
			'opacity': 0
		});

		setTimeout(function() {
		//	d('self: ' + self);
			
			bounceDown.apply(self);
		}, timeout += 100);
	});
	
}
		
		
		
	// Version 1:
	// Fade in + Animate downwards at once.
	
	/*
			
			setTimeout(function() {
				$('a', self)
					.animate({ 'opacity': 1 }, { duration: 600, easing: 'easeOutBack', queue: false })
					.animate({ 'height': '64px' }, 800, 'easeOutBounce', function() {
						// If this is the last element 
						if (n == 5) initHovers();

					});
				
				//setTimeout(function() {
					$('.shadow', self).animate({
						'bottom': '-17px',
						'opacity': shadowDefault
					}, 600, 'easeOutBounce');
				//}, 500)
				
			}, timeout += 100);
	
	*/

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

// Apple's browser detector

if(typeof (AC)==="undefined"){AC={}}AC.Detector={getAgent:function(){return navigator.userAgent.toLowerCase()},isMac:function(B){var A=B||this.getAgent();return !!A.match(/mac/i)},isWin:function(B){var A=B||this.getAgent();return !!A.match(/win/i)},isWin2k:function(B){var A=B||this.getAgent();return this.isWin(A)&&(A.match(/nt\s*5/i))},isWinVista:function(B){var A=B||this.getAgent();return this.isWin(A)&&(A.match(/nt\s*6/i))},isWebKit:function(B){if(this._isWebKit===undefined){var A=B||this.getAgent();
this._isWebKit=!!A.match(/AppleWebKit/i);this.isWebKit=function(){return this._isWebKit}}return this._isWebKit},isSafari2:function(C){if(this._isSafari2===undefined){if(!this.isWebKit()){this._isSafari2=false}else{var B=navigator.userAgent.toLowerCase();var A=parseInt(parseFloat(B.substring(B.lastIndexOf("safari/")+7)));this._isSafari2=(A>=419)}this.isSafari2=function(){return this._isSafari2}}return this._isSafari2},isOpera:function(B){var A=B||this.getAgent();return !!A.match(/opera/i)},isIE:function(B){var A=B||this.getAgent();
return !!A.match(/msie/i)},isIEStrict:function(B){var A=B||this.getAgent();return A.match(/msie/i)&&!this.isOpera(A)},isFirefox:function(B){var A=B||this.getAgent();return !!A.match(/firefox/i)},isiPhone:function(B){var A=B||this.getAgent();return this.isMobile(A)},isMobile:function(B){var A=B||this.getAgent();return this.isWebKit(A)&&A.match(/Mobile/i)},isiTunesOK:function(B){var A=B||this.getAgent();return this.isMac(A)||this.isWin2k(A)},isQTInstalled:function(){var A=false;if(navigator.plugins&&navigator.plugins.length){for(var B=0;
B<navigator.plugins.length;B++){var C=navigator.plugins[B];if(C.name.indexOf("QuickTime")>-1){A=true}}}else{if(typeof (execScript)!="undefined"){qtObj=false;execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))',"VBScript");A=qtObj}}return A},getQTVersion:function(){var A="0";if(navigator.plugins&&navigator.plugins.length){for(var C=0;C<navigator.plugins.length;C++){var D=navigator.plugins[C];var B=D.name.match(/quicktime\D*([\.\d]*)/i);if(B&&B[1]){A=B[1]
}}}else{if(typeof (execScript)!="undefined"){ieQTVersion=null;execScript('on error resume next: ieQTVersion = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1").QuickTimeVersion',"VBScript");if(ieQTVersion){A=(ieQTVersion>>24).toString(16)}}}return A},isQTCompatible:function(C,E){function B(G,I){var F=parseInt(G[0],10);if(isNaN(F)){F=0}var H=parseInt(I[0],10);if(isNaN(H)){H=0}if(F===H){if(G.length>1){return B(G.slice(1),I.slice(1))}else{return true}}else{if(F<H){return true}else{return false}}}var D=C.split(/\./);
var A=E?E.split(/\./):this.getQTVersion().split(/\./);return B(D,A)},isValidQTAvailable:function(A){return this.isQTInstalled()&&this.isQTCompatible(A)}};



if (typeof(AC) == "undefined") { AC = { }; }

AC.Quicktime = {
	
	/**
	* Collection of all controllers that have a movie attached
	**/
	controllers: [],
	
	/**
	 * Adds an object param tag to the specified parent
	 * Note that the attributes are added in this seemingly odd order
	 * so they show up in the logical order in the dom
	 */
	_addParameter: function(parent, name, value) {

		if (!parent) {
			return;
		}

		var param = document.createElement('param');
		param.setAttribute('value', value);
		param.setAttribute('name', name);
		parent.appendChild(param);
		
		param = null;

	},
	
	/**
	 * Creates the IE friendly outer object
	 * NOTE Safari and Opera both seem to be able to use this one as well
	 * I'm assuming this is due to some hacking on their part for
	 * compatibility
	 */
	_createOuterObject: function(name, fileUrl, options) {

		var outerObject = document.createElement('object');
		
		if(AC.Detector.isMobile() && options.posterFrame) {
			AC.Quicktime._addParameter(outerObject, 'src', options.posterFrame);
			AC.Quicktime._addParameter(outerObject, 'href', fileUrl);
			AC.Quicktime._addParameter(outerObject, 'target', 'myself');
		} else {
			AC.Quicktime._addParameter(outerObject, 'src', fileUrl);
		}
		
		outerObject.setAttribute('id', name);


		var activexVersion = '7,3,0,0';

		if (null != options && '' != options.codebase && typeof(options.codebase) != 'undefined') {
			activexVersion = options.codeBase;
		}

		outerObject.setAttribute('codebase', 
		    'http://www.apple.com/qtactivex/qtplugin.cab#version=' + activexVersion);

		return outerObject;
	},
	
	/**
	 * Creates the more standards compliant object which Firefox and Netscape
	 * rely on to load the movie
	 */
	_createInnerObject: function(name, fileUrl, options) {

		var innerObject = document.createElement('object');
        
		innerObject.setAttribute('type', 'video/quicktime');
		innerObject.setAttribute('data', fileUrl);
		innerObject.setAttribute('id', name + "Inner");

		return innerObject;
	},
	
	/**
	* Creates a movie just to trigger the native activeX/missing plugin dialog in a browser
	*/
	_createNullMovie: function(width, height) {
		width = 0;
		height = 0;
		var nullContainer = $(document.createElement('div'));
		
		//needed in the object to trigger the missing activeX control in IE
		var classid = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
		var codebase = 'http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0';
		
		// triggers the missing plugin for other browsers like firefox
		var pluginspage = 'http://www.apple.com/quicktime/download/';

		nullContainer.innerHTML = '<object width="' + width + '" height="' + height + '" classid="' + classid +'" codebase="' + codebase + '"><embed width="' + width + '" height="' + height + '" type="video/quicktime" pluginspage="' + pluginspage + '"></embed></object>'
		
		return nullContainer;
	},
	
	/**
	 * Attaches supplied options as necessary to the movie objects
	 */
	_configureMovieOptions: function(innerObject, outerObject, options) {
		
		if(null == options || typeof(options) == 'undefined') {
			return false;
		}
			
		for (var property in options) {

			var attributeName = property.toLowerCase();

			switch(attributeName) {
				case('type'):
				case('src'):
				case('data'):
				case('classid'):
				case('name'):
				case('id'):
					//do nothing as these shouldn't be overriden
				break;
				case('class'):
					Element.addClassName(outerObject, options[property]);
				break;
				case('innerId'):
					if(innerObject) {
						innerObject.setAttribute('id', options[property]);
					}
				break;
				case('width'):
				case('height'):
					outerObject.setAttribute(attributeName, options[property]);
					if(innerObject) {
						innerObject.setAttribute(attributeName, options[property]);
					}
				break;
				default:
					AC.Quicktime._addParameter(outerObject, attributeName, options[property]);
					AC.Quicktime._addParameter(innerObject, attributeName, options[property]);
				break;
			}

		}
		
	},
	
	/**
	 * Will create an object element to append to the document with the
	 * specified parameters as well as any additional options
	 * 
	 * TODO plenty of work to do with the optional parameters I'm sure
	 * Though I don't know what custom parameters we may need to faciliate
	 * whatever it is we need to do with movies, though tehcnially you can
	 * pass whatever you wantt in here and it'll handle it pretty well
	 * 
	 * It's often just a matter of if we expose a custom parameter we'll
	 * accept as part of the options hash...where/how does that get applied?
	 */
	packageMovie: function(name, fileUrl, options) {
		
		if(name == null || fileUrl == null ) {
			throw new TypeError('Valid Name and File URL are required arguments.');
		}
		
		var minVersion = '7';
		if (options && options.minVersion) {
			minVersion = options.minVersion;
		}
		
		// If required QuickTime is not available provide a link to download instead of a movie object
		if (!AC.Detector.isMobile() && !AC.Detector.isValidQTAvailable(minVersion)) {
			var downloadNotice = $(document.createElement('a'));
			downloadNotice.addClassName('quicktime-download');
			
			downloadNotice.setAttribute('href', 'http://www.apple.com/quicktime/download/');
			downloadNotice.innerHTML = options.downloadText || 'Get the Latest QuickTime.';
			
			// downloadNotice.appendChild(this._createNullMovie(options.width, options.height));
			return downloadNotice;
		}
		
		var outerObject = AC.Quicktime._createOuterObject(name, fileUrl, options);
		
		if (!AC.Detector.isIEStrict()) {
			//really imperitive we don't create an inner object for IE
			//this is what causes the N items remaining as it never actually 
			//gets requested bbut IE still decides to report it as 
			//needing to be loaded
			
			var innerObject = AC.Quicktime._createInnerObject(name, fileUrl, options);
			outerObject.appendChild(innerObject);
			
		} else if(options.aggressiveCleanup !== false){
			
			//knowing it's IE at this point, make sure we clear the movie when the page closes
			//we also set our reference to null for good measure
			Event.observe(window, 'unload', function() {
				try {
					outerObject.Stop();
				} catch(e) {;}
				outerObject.style.display = 'none';
				outerObject = null;
				
				//this only masks memory leaks
				//movie could still be present even if hidden
				//if the movie remains in the viewport upon visiting other
				//pages, you have remaining references to the movie somewhere
				//they need to be removed as early as possible preferably
				//or at least before you leave if you have no other choice
				
				//closing the window that is leaking will throw an error message
				//but at least due to the hiding it won't completely interrupt
				//browsing
			});
			
		}

		AC.Quicktime._configureMovieOptions(innerObject, outerObject, options);
		
		//force preservation of existing params even if the movie's URL is changed
		//this is the ooopiste of how QT works by default
		
		AC.Quicktime._addParameter(outerObject, 'saveembedtags', true);
		AC.Quicktime._addParameter(innerObject, 'saveembedtags', true);
		
		//Needs to be last so IE sees all the parameters appended to
		//the object prior to loading the activex control
		outerObject.setAttribute('classid', 
			'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B');
		
		return outerObject;
	},

	/**
	 * Using this will clear the contents of oldMovie's parentNode and 
	 * insert newMovie into the container
	 */
	swapMovie: function(container, oldMovie, newMovie) {
		
		
		var isIE = AC.Detector.isIEStrict();

		//in IE ensure we hide the old movie, otherwise it kinda ghosts itself
		if(isIE && oldMovie) {
			oldMovie.style.display = 'none';
		}
		
		//Yes, we could preserve the nodes in this container in some browsers
		//but since IE is overwriting the innerHTML we're going to completely
		//empty the container everywhere for the sake of consistency
		Element.removeAllChildNodes(container);
		
		var movieReference = null; 

		if (!isIE) {
			container.appendChild(newMovie);
			movieReference = newMovie;
		} else {
			container.innerHTML = newMovie.toMarkup();
			movieReference = container.firstChild;
			movieReference.style.display = 'block';
		}
		
		//reference to the movie that's actually in the DOM
		return movieReference;
	},
	
	/**
	* Helper to handle a very simple insertion of a movie into a specified 
	* element
	*/
	render: function(movie, element, options) {

		var target = $(element);
		var placeholderContent = target.innerHTML;
		
		if (!AC.Detector.isQTInstalled()) {
			Element.addClassName(target, 'static');
			return
		}
		
		target.innerHTML = '';
		Element.addClassName(target, 'loading');
		target.appendChild(movie);
		
		var options = options ? options : {};
			
		var movieLoaded = function() {
			checkController.monitorMovie();
			Element.removeClassName(element, "loading");
			Element.addClassName(element, "loaded");
		}
		
		var movieFinished = function() {return;}
		
		if("finishedState" in options) {
			
			var showFinishedState = function(target, content) {
				return (function() {
					
					checkController.detachFromMovie();
					
					//ensure movie is hidden in IE
					movie.style.display = 'none';
					movie = null;
					
					target.innerHTML = '';
					
					if (typeof(content) == 'string') {
						target.innerHTML = content;
					} else {
						target.appendChild(content);
					}
				})
			}
			
			movieFinished = showFinishedState(target, options.finishedState)
		}
		
		var checkController = new AC.QuicktimeController(movie, {
			onMoviePlayable: movieLoaded, 
			onMovieFinished: movieFinished})
	}

};



$(function() {
	// TODO: Have this start when slot and item images are loaded.
	// And dropzone too, proably. 
	// Or just plug in the dimensions here
	
	setTimeout(initMedia, 100);

	//$(window).scroll(0);
	
});

var anchorPlay;

// Note: $(ui.draggable)[0] = future-proofing.


// This is kinda sloppy, but we need access to this function
// from outside after all.
var itemToZone;

	var showAudPlayer = function() { 
	//	if ($('#player').css('opacity') != 1)
			$('#player').stop().css('display', 'block').animate({ 'opacity': 1 }, 750, 'easeOutSine');
		$('#header').addClass('playing-audio');
	};
	
	var hideAudPlayer = function() {
		$('#player').stop().animate({ 'opacity': 0 }, 750, 'easeOutSine');
		$('#header').removeClass('playing-audio');
	};
	
	var showVidPlayer = function() {
		$('#qt-video-player').css('display', 'block');
		$('#header').addClass('playing-video');
	};
	
	var hideVidPlayer = function() {
		$('#qt-video-player').css('display', 'none');
		$('#header').removeClass('playing-video');
	};
	
	var showInstructions = function() {
		$('#description').stop().animate({'opacity' : 0 });
		$('#dz-instructions').stop().animate({ 'opacity': 1 }, 500, 'easeInSine');
	};
	
	var hideInstructions = function() {
		$('#description').stop().animate({'opacity' : 1 });
		$('#dz-instructions').stop().animate({ 'opacity': 0 }, 500, 'easeInSine');
	};
	
function initMedia() {
	d('~!!!');


	//
	// General stuff; Media functions
	//
	
	var getType = function(url) {
		var type = 'audio';
		var audioTypes = ['mp3', 'aac'];		// <-- this is being ignored by the function
		var videoTypes = ['mov', 'wmv', 'mp4'];
		var ext = url.match(/.*\.(.+$)/)[1];
	//alert(ext);
	
		if ($.inArray(ext, videoTypes) > -1)
			return 'video';
		return 'audio';
	};
	
	var firstPlayback = true;
	var startPlayback = function(item) {
		
		var url = $('.download', item)[0].href;
		type = getType(url);
//		else
//			type = 'audio';
/*
	if (firstPlayback)
			$('#dz-instructions').animate({ 'opacity': 0 }, 500, 'easeInSine');
*/			
	/*if (!current)
		$('#dz-instructions').animate({ 'opacity': 0 }, 500, 'easeInSine');
	else
		$('#dz-instructions').animate({ 'opacity': 1 }, 500, 'easeInSine');
	*/
	
	$('#description').html($('.desc', item).html());

	if (type == 'audio') {
		// Fade in the player and hide video player
		$('#header').addClass('playing-audio');
		hideVidPlayer();
		showAudPlayer();
		qt.switchTrack(url);


	} else {
		$('#header').addClass('playing-video');
	/*
		// Fade out the player
	//	if ($('#player').css('opacity') != 0)
		//	$('#player').stop().animate({ 'opacity': 0 }, 750, 'easeOutSine');
		d('Video type; hiding player');

			
		$('#qt-video-player').css('display', 'block');
	*/
		playVideo(url);
	}
			
//	alert(type);
		firstPlayback = false;
	};
	
	var stopPlayback = function() {
		setTimeout(function() {
			// if there is no replacement element; it's just been dragged out
			if (!current) {
				$('#header').removeClass('playing-video').removeClass('playing-audio');;
				hideVidPlayer();
				hideAudPlayer();
				showInstructions();
			} else {
				// if there is a replacement
				hideInstructions();
				
				var url = $('.download', current)[0].href;
				type = getType(url);
				if (type == 'video') {
					showVidPlayer();
					hideAudPlayer();	
				} else {
					hideVidPlayer();
					showAudPlayer();
				}
			}
			
			/*if (!current) {
				$('#qt-video-player').css('display', 'none');
				$('#player').stop().animate({ 'opacity': 0 }, 750, 'easeOutSine');
				$('#dz-instructions').stop().animate({ 'opacity': 1 }, 500, 'easeInSine');
			} else {
				var url = $('.download', current)[0].href;
				type = getType(url);
				if (type == 'video') {
					$('#qt-video-player').css('display', 'block');
					$('#player').stop().animate({ 'opacity': 0 }, 750, 'easeOutSine');
				} else {
					$('#qt-video-player').css('display', 'none');
					$('#player').stop().animate({ 'opacity': 1 }, 750, 'easeOutSine');
				}
					
				$('#dz-instructions').stop().animate({ 'opacity': 0 }, 500, 'easeInSine');
				
			}*/
			
		}, 200);

		if (qt.player.Stop) qt.player.Stop();
	};
	
	//
	// This screws up when you have to scroll up.
	// Bug in jQuery?
	//
	
	$('body').append('<div id="drag-div"></div>');

	$('#drag-div').css({
		'position': 'fixed',
		'height': $(document).height(),
		'width': '100%',
		'top': 0,
		'left': 0,
		'z-index': -1
	});

	var current = '';
	function setCurrent(item) {
		item = $(item)[0];
		current = item;
		item.current = true;
	};
	
	//
	// Set up the drop zone and related variables
	//

	$('#dropzone').append('<span class="icon"><span class="grey"></span><span class="white"></span><span class="pulse"></span><span class="blue"></span><span class="superblue"></span></span>');


	var dz = $('#dropzone');
	if (!dz.length) return;

	var dzOffset = dz.offset();
	var randomItem = $('#media-items li .item:first')[0];		// We just need one to get its dimensions.

	var dzItemYCenter = dzOffset.top + (dz.height() - $(randomItem).height())/2;
	var dzItemXCenter = dzOffset.left +  (dz.width() - $(randomItem).width())/2;
	dzItemYCenter -= 5;	// Visually this looks more like the center

	// Hover
	$('#dropzone').append('<div class="hover"></div>')
	$('#dropzone .hover').css('opacity', 0);

	var dropzoneOpacityEasing = 'easeInOutSine';

	// Fade out all of the icons
	$('#dropzone .icon *').not('.grey').css('opacity', 0);

	var whitePulsing = false;

	var startWhitePulse = function() {
	//	d('in StartWP');
		if (whitePulsing) return;
		whitePulsing = true;

	//	d('Starting white pulse');

		$('#dropzone .icon .pulse').stop()
				.animate({ 'opacity': 1 }, 700, 'easeInSine', function() {
					$('#dropzone .icon .white').css('opacity', 1);

					for (var i = 0; i < 20; i++)
						$('#dropzone .icon .pulse')
							.animate({ 'opacity': 0 }, 500, dropzoneOpacityEasing)
							.animate({ 'opacity': 1 }, 700, dropzoneOpacityEasing);
				});

	};

	var stopWhitePulse = function() {
	//	d('in StopWP');
		if (!whitePulsing) return;
		whitePulsing = false;

	//	d('Stopping white pulse');

		$('#dropzone .icon .pulse')
			.queue([]).stop()
			; //.animate({ 'opacity': 0 }, 700, dropzoneOpacityEasing);	};
	};
	

	var stopAll = function() {
	//	d('Stopping all');

		$('#dropzone .icon *')
			.queue([]).stop()
			.not('.grey').animate({ 'opacity': 0 }, 200, dropzoneOpacityEasing);

		whitePulsing = false;
	};

	
	var bluePulsing = false;

	// Also does the drag area borders
	var startBluePulse = function() {
	//	d('in StartBP');
		if (bluePulsing) return;
		bluePulsing = true;

	//	d('Starting blue pulse');

		$('#dropzone .hover').stop().animate({ 'opacity': 1 }, 250, 'easeInSine');

		$('#dropzone .icon .superblue')/*.css('opacity', 0)*/
				.queue([]).stop().animate({ 'opacity': 1 }, 400, 'easeInSine', function() {
					$('#dropzone .icon .blue').stop().css('opacity', 1);

					for (var i = 0; i < 20; i++)
						$('#dropzone .icon .superblue')
							.animate({ 'opacity': 0 }, 600, 'easeInSine')
							.animate({ 'opacity': 1 }, 600, 'easeInSine');
				});
	};

	// Also does the drag area borders
	var stopBluePulse = function() {
	//	d('in StopBP');
		if (!bluePulsing) return;
		bluePulsing = false;

	//	d('Stopping blue pulse');

		$('#dropzone .hover').stop().animate({ 'opacity': 0 }, 600, dropzoneOpacityEasing);
		
		$('#dropzone .icon .superblue').queue([]).stop();
		
		$('#dropzone .icon .blue, #dropzone .icon .superblue').animate({ 'opacity': 0 }, 600, dropzoneOpacityEasing);
		
	};

	// Droppable!
	$('#dropzone').droppable({
		accept: '#media-items li .item',
		tolerance: 'touch',

		// Fade in the outline and disable nav hovers
		activate: function(e, ui) {
			navHoversDisabled = true;
			// TODO: Check if you're dragging the one that's inside
			// If it is, draggable('disable')
			$(ui.draggable).stop();

			// Start pulsing the white icon
	//		startWhitePulse();

		},

		over: function(e, ui) {
			stopWhitePulse();
			startBluePulse();
		},

		out: function(e, ui) {
			startWhitePulse();
			stopBluePulse();
		},

		// Re-enable the nav hovers and fade out the blue outline
		deactivate: function(e, ui) {
			stopAll();

			navHoversDisabled = false;
				$('.hover', this).stop().animate({ 'opacity': 0 }, 500, dropzoneOpacityEasing);
		},

		drop: function(e, ui) {
			var item = $(ui.draggable)[0];
			stopWhitePulse();
			stopBluePulse();
			
			var sameOne = current && current.itemNum == item.itemNum;

			// If there's already a current one, send it back
			// if it isn't the one in the zone already
			if (current && !sameOne) {
				/* If you want it to go to its old slot: 
					if (current.slot.empty)
						itemToSlot(current, current.slot);
					else
						itemToSlot(current, findEmptySlot());
				*/

				if (item.slot.empty)
					itemToSlot(current, item.slot);
				else
					itemToSlot(current, findEmptySlot());
			} else {
				d('Setting slot ' + item.slot.id + ' to empty [dropzone drop].');
				item.slot.empty = true;
			}

			setCurrent(item);

			//if (!item.current) {
			//}

			// Now for a bit of a hack.
			// This value gets set to false on start of the drag, and gets
			// set to true here. What this
			// means is that when you finish the drag, true = dragged
			// into the drop zone and false means it wasn't.

			// This relies on the fact that this function here
			// is called before the draggable's function.
			//		alert('Dropped into drop zone.')

			// Used to be inTheZone
			d('Found a home.');
			item.foundAHome = true;
				

			// Move it to the middle and initialize playback.
			// Have the media controls as separate functions.

			$(item).animate({
				'top': dzItemYCenter + 'px',
				'left': dzItemXCenter + 'px'
			}, 500, 'easeOutExpo', function() {
				d('Starting playback [dropzone drop]');
				if (!sameOne) startPlayback(item);
			});
	if (!current)
		$('#dz-instructions').animate({ 'opacity': 0 }, 500, 'easeInSine');
	else
		$('#dz-instructions').animate({ 'opacity': 1 }, 500, 'easeInSine');
			
//			}, 500, 'easeOutExpo', function() {

//			}, 1500, 'easeOutElastic', function() {

		/*	setTimeout(function() {
				d('Starting playback [dropzone drop]');
				startPlayback(item);
			
			}, 500);*/
		}

	});





	//
	// Set up the slots
	//
	
	var itemToSlot = function(item, slot) {
		item = $(item)[0];
		
		d('Setting slot ' + slot.id + ' to full. [itemToSlot]');

		// !!
		// Might have to set current here too
		if (!item.current) {
			d('Not setting slot ' + item.slot.id + ' to empty anymore [itemToSlot].');
		//	$(item)[0].slot.empty = true;
		}

		if (item.current) {
			current = '';
			item.current = false;
		}

		slot.empty = false;
		item.slot = slot;
		item.foundAHome = true;

		var itemOffset = $(item).offset();
		var slotOffset = $(slot).offset();

		
		
		var x = Math.pow(itemOffset.left - slotOffset.left, 2);
		var y = Math.pow(itemOffset.top - slotOffset.top, 2);
		var distance = Math.sqrt(x + y);
		/*
		d('Distance' , distance);
		d('Anim', distance + ' ms');
		d('-');
		d('x', x);
		d('y', y);
		d('-');
		d('itemOffset.left', itemOffset.left);
		d('itemOffset.top', itemOffset.top);
		d('-');
		d('slotOffset.left', slotOffset.left);
		d('slotOffset.top', slotOffset.top);
		*/
		
		// 6 = padding on each side
		$(item).stop().animate({
			'top': (slotOffset.top + 6) + 'px',
			'left': (slotOffset.left + 6) + 'px'
		}, Math.log(distance) * 100, 'easeOutExpo');
		
		//
		// I think this works; might have to move it somewhere else
		//
		if (!current) stopPlayback();
	};

	var findEmptySlot = function() {
		d('Finding an empty slot...');

		var foundSlot = '';

		var find = function() { if (this.empty && !foundSlot) foundSlot = this; };

		$('#media-items li').each(find);
		d('Found empty slot', foundSlot.id);
		return foundSlot;
	};

	//
	// Set up the items
	//


	itemToZone = function(item) {
		var item = $(item)[0];
		if (item.current) return;
		// Eject the current one
		if (current)
		//	itemToSlot(current, item.slot);
			if (current.slot.empty)
				itemToSlot(current, current.slot);
			else
				itemToSlot(current, findEmptySlot());
		else {
			d('Setting slot ' + item.slot.id + ' to empty [itemToZone]');
			item.slot.empty = true;
		
		}

		d('Sending item to the drop zone.');
		var oldCurrent = current;
		setCurrent(item);
		
		item.slot.empty = true;
		
		// Blue flash
		$('#dropzone .hover').stop()
			.animate({	'opacity': 1 }, 100, 'easeInSine')
			.animate({ 'opacity': 0 }, 800, 'easeOutSine');	

		// The item's slot is empty because of the anim;
		// Now the old one gets sent to a different slot.
		
		item.foundAHome = true;

		var itemOffset = $(item).offset();
		

		var x = Math.pow(itemOffset.left - dzItemXCenter, 2);
		var y = Math.pow(itemOffset.top - dzItemYCenter, 2);
		var distance = Math.sqrt(x + y);

		d('Distance', distance);

		$(item).stop().animate({
			'top': (dzItemYCenter) + 'px',
			'left': dzItemXCenter + 'px'
		}, distance * 1.5, 'easeOutExpo');
		
		d('Starting playback [itemToZone]');
		// And finally, start playing the item.
		startPlayback(item);
	};

	
	var startSlotPulse = function(slot) {
		if (slot.pulsing) return;
		slot.pulsing = true;
		
		d('Starting slot pulse');

		$('.slot-hover', slot)
			.queue([]).stop()
			.animate({ 'opacity': 1 }, 300, 'easeInSine');
		
		/*for (var i = 0; i < 20; i++)
			$('.slot-hover', slot)
				.animate({ 'opacity': 0 }, 500, 'easeInSine')
				.animate({ 'opacity': 1 }, 500, 'easeInSine');		*/
	};
	
	var stopSlotPulse = function(slot) {

		if (!slot.pulsing) return;
		slot.pulsing = false;	
		
		d('Ending slot pulse');
		$('.slot-hover', slot).queue([]).stop();
		$('.slot-hover', slot).animate({ 'opacity': 0 }, 500, 'easeInSine');	
	};
	
	$(window).resize(function() {
		$('.item').each(function() {
			var item = this;
		//	if (item.current) alert();
			var slot = item.slot;
			
			// Position it absolutely
			var itemOffset = $(item).offset();


			//	d('Difference in width between slot and item', itemOffset.left - slotOffset.left);

			var slotOffset = $(slot).offset();
			
			dzOffset = dz.offset();
		
			dzItemYCenter = dzOffset.top + (dz.height() - $(randomItem).height())/2;
			dzItemXCenter = dzOffset.left +  (dz.width() - $(randomItem).width())/2;

			if (!item.current)
				$(item).css({
					'top': slotOffset.top + 6 + 'px',
					'left': slotOffset.left + 6 + 'px'
				});
			else
				$(item).css({
					'top': dzItemYCenter + 'px',
					'left': dzItemXCenter + 'px'
				});
		});
	});
	d('~!!!');
	// Loop through all of the li's and do stuff
	$('#media-items li').each(function(n) {
		var self = this;
		
		d('media items li!');
		//
		// Slot Hover
		//
		$(this).append('<div class="slot-hover"></div>');
		
		$('.item', this)
			.wrapInner('<div class="content"></div>')
			.append('<div class="item-hover"><div>')
			.hover(function() {
				$('.item-hover', this).stop().animate({	'opacity': 1 }, 150, 'easeInSine')
			}, function() {
				$('.item-hover', this).stop().animate({	'opacity': 0 }, 250, 'easeInSine')
			});
		
		$('.slot-hover, .item-hover', this).css('opacity', 0);
	
		var slotOffset = $(this).offset();

		$('.slot-hover', this).css({
			'position': 'absolute',
			'top': (slotOffset.top + 6) + 'px',
			'left': (slotOffset.left + 6) + 'px'
		});	
		
		
		if ($.browser.msie) return;

		//
		// Item
		//

		var item = $('.item', this)[0];

		// Ignore item stuff for totally empty slots
		if (item) {

			// Deactivate the download link
			$('.download', item).click(function() { return false; });
			
			$(item).mouseup(function() {
				if (this.current || this.dragging) return;
				itemToZone(this, true);
			});

			item.itemNum = n;

			// Position it absolutely
			var itemOffset = $(item).offset();


		//	d('Difference in width between slot and item', itemOffset.left - slotOffset.left);

			$(item).css({
				'position': 'absolute',
				'top': itemOffset.top + 'px',
				'left': itemOffset.left + 'px'
			});
			
			var fixFirefox = function() {
				d('This: ' + self.offsetLeft + '; Item: ' + item.offsetLeft);
				// 6 = needed value = padding of the slot
				var posDiff = 6 - (item.offsetLeft - self.offsetLeft);

				// d('posDiff', posDiff);

				if (posDiff > 0) {
					d('Fixing that damn Firefox bug by', posDiff);
					$('#white').css('padding-right', posDiff);

				}
			};

			if ($.browser.mozilla) setTimeout(fixFirefox, 10);

			d('Setting slot');
			item.slot = this;

			item.current = false;

			$(item).draggable({
				distance: 5,
		//		containment: '#drag-div',
				zIndex: 1100,
				scrollSensitivity: 50,
				scroll: true,

				start: function(e, ui) {
					var item = $(ui.helper)[0];
					item.dragging = true;

					// Fade in the dropzone icon
					startWhitePulse();
					
					// Start pulsing slot.
					if (!item.current) startSlotPulse(item.slot);

					item.foundAHome = false;

					// It's empty while you're dragging BUT ONLY IF it's not the current one

					d('Current? ', (item.current ? 'Yes' : 'No') + ' [item.start]');

					if (!item.current) {
						d('Setting slot ' + item.slot.id + ' to empty [item start].');
						item.slot.empty = true;
					}
				},

				stop: function(e, ui) {
					var item = $(ui.helper)[0];

					item.dragging = false;
					
					// Hopefully this is good.
					$('.item-hover', this).stop().animate({	'opacity': 0 }, 250, 'easeInSine')
					
					// See the long comment about foundAHome in the drop zone's drop function
					//		alert('Stopped dragging. Hopefully this is called last. >.<');

					// All's good if it's been dragged into a drop zone

					if (item.foundAHome) d('Found a home!');

					if (item.foundAHome) return;

				
					d('Found no home. This means I\'ve been dragged out.');
					
					stopPlayback();
	
					// Either go back to the old slot or to a new empty one
					d('Is slot ' + item.slot.id + ' empty: ' + (item.slot.empty ? 'Yes' : 'No') + '[item stop]');
					var destSlot = (item.slot.empty ? item.slot : findEmptySlot());

					if (current.itemNum != item.itemNum) {
						// Set the old slot to empty
						d('Setting slot ' + item.slot.id + ' to empty [item stop].');
						 item.slot.empty = true;
					}
					
					d('Calling itemToSlot [item.stop]')
					itemToSlot(ui.helper, destSlot);

				}
			});
		} // </if (item)>


		//
		// Slot
		//

		// Set the slot to filled or empty
		this.empty = (item ? false : true);

		// Allow dragging to other slots
		$(this).droppable({
			accept: function(draggable) {
				return self.empty;
			},
			
			over: function(e, ui) {
				startSlotPulse(this);
			},
			
			out: function(e, ui) {
				stopSlotPulse(this);
			},
			
			drop: function(e, ui) {
				item = $(ui.draggable)[0];
				stopSlotPulse(this);
				
				d('Foundahome true');
				item.foundAHome = true;
				itemToSlot(ui.draggable, this);

				// or will it? --> // itemToSlot will be called by the .stop()  function.
			}
		});
	});

}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

function getURLAnchor(){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("#") > -1 ){
   	strReturn = strHref.substr(strHref.indexOf("#") + 1).toLowerCase();
  }

  return strReturn;
}
//
// TODO: Handle when it just gets dragged out; disappear the media player and all that
//



if (!$.browser.msie)

	$(function() {
		setTimeout(qtInit, 10);
	
	});

$(function() {
	
		// !!
		// !!
		// Check for anchors
		var anchor = getURLAnchor();
	
		if (anchor && $('#' + anchor).length > 0)
		anchorPlay = setTimeout(function() {
			if (!$.browser.msie)
				itemToZone($('#' + anchor));
			else
				window.location = /*'http://noisefreak.com/' +*/ $('#' + anchor + ' .download')[0].href;
		}, 200);
});

function playVideo(url) {
	//if ($('#player').css('display') == 'block') {
//	}
//	alert('!');
	hideInstructions();
	
	var qtObject = AC.Quicktime.packageMovie('qt_video', url, {
		width: 320,
		height: 220,
		autoplay: true,
		controller: true,
		cache: true//,
		//'bgcolor': 'transparent'	// To hide it on the background. Otherwise in Firefox it's a white dot.
	});
	
//	$('#player').css({'display': 'block' });
	$('#qt-video-player').html(qtObject);
	//alert(qtObject);
	// Hope this works!exc
	

}


var sliderSetJS = false;
var sliderUserMove = false;
var sliderUserTime = -1;

	// Disable the automatic updating
	// of the time while user is dragging


var qt = { 
	player: '',
	percentLoaded: 0,
	
	switchTrack: function(url) {
		
		qt.percentLoaded = 0;
		//d('Switching track to', url);
		try {
		
		
		//	qt.player.SetHeight(100);
		//	qt.player.SetWidth(100);
			
			 qt.player.SetVolume($('#volume-slider').slider('value', 0));
			 qt.player.SetURL(url);
			
			 qt.player.Play();
			
			 qt.events.onSwitchTrack();
		} catch(e) {
				if ($.browser.msie) alert('Quicktime is required to view the media on this page.');
		}
	},

	
	setElapsedTime: function(ms) {
		////d('Time: ' + qt.player.GetTime());
		var cTime = (ms ? ms : qt.player.GetTime()); // In milliseconds
		var cSeconds = Math.round(cTime / 1000);
		var cMinutes = Math.floor(cSeconds / 60);
		cSeconds = cSeconds % 60;
	
		var dTime = qt.player.GetDuration(); // In milliseconds
		var dSeconds = Math.round(dTime / 1000);
		var dMinutes = Math.floor(dSeconds / 60);
		dSeconds = dSeconds % 60;
		d(dSeconds);
		$('#progress-text').html(cMinutes + ':' + (cSeconds < 10 ? '0' + cSeconds : cSeconds) + ' / ' + dMinutes + ':' + (dSeconds < 10 ? '0' + dSeconds : dSeconds));
	},
	
	isPlaying: function() {
		try {
			return qt.player.GetRate() !== 0
		} catch(e) {
			return false;
		}
	},
	
	isFinished: function() {
		
		try {
			var isStopped = qt.player.GetRate() === 0;
			var isAtEnd = qt.player.GetTime() == qt.player.GetDuration();
			return isStopped && isAtEnd;
		} catch (e) {
			
			/*	No firm connection with plugin
				Not exposing this exception the client as it's very common and
				somewhat unreasonable to think anybody will want to handle it
				at a higher level with anything other than assuming the movie
				is not finished
			
				very frequently in firefox this would arise if you bound a 
				onFinished callback:
			
				controller = new AC.QuicktimeController(movie, {
					onMovieFinished: function() { ... }.bind(this) });
			*/
			
			return false;
		}
	},

	events: {
		onPercentLoadedChanged: function(p) {
			$('#percent').html('Percent loaded:' + p);
		},
		
		onLoaded: function() {
			setInterval(function() {
				if (!sliderUserMove) qt.setElapsedTime();
			}, 1000);
			
			//d('Loaded');
			
			//qt.player.SetBGColor('#161616');
			
			$('#playpause').click(function() {
				// If it's not playing start it up
				// Otherwise pause it
				
				if (!qt.isPlaying()) {
					$(this).addClass('playing');
					qt.player.Play();
				} else {
					$(this).removeClass('playing');
					qt.player.Stop();
				}
			}).hover(function() {
				$('.hover', this).stop().animate({
					'opacity': 1
				}, 700, 'easeOutSine');
			}, function() {
				$('.hover', this).stop().animate({
					'opacity': 0
				}, 450, 'easeOutSine');
			});
			
			
			$('#progress-slider').slider({ 
				min: 0, 
				max: 100,
				slide: function(e, ui) {
					$('#progress-slider-filled').css('width', $('#progress-slider-handle').css('left'));
					if (sliderSetJS) return;
					
					var time = (ui.value / 100) * qt.player.GetDuration();
					sliderUserTime = time;
					
					qt.setElapsedTime(time);
				}
			});
			
			$('#volume-slider').slider({
				min: 0,
				max: 256,
				startValue: qt.player.GetVolume(),
				slide: function(e, ui) {
					qt.player.SetVolume(ui.value);
					$('#volume-slider-filled').css('width', $('#volume-slider-handle').css('left'));
					d(qt.player.GetVolume());
					switch (true) {
						case ui.value == 0:
							$('#volume-icon').removeClass('low').addClass('mute');
							break;
							
						case ui.value < 128:
							$('#volume-icon').removeClass('mute').addClass('low');
							break;
							
						case ui.value > 128:
							$('#volume-icon').removeClass('mute low');
							break;
					}							
				}
			});
			$('#volume-slider-filled').css('width', $('#volume-slider-handle').css('left'));
			d($('#volume-slider-handle').css('left').substring(0, 2) + 5)
			
			$('#progress-slider, #progress-slider-handle').mousedown(function() {
				sliderUserMove = true;
			})
						
			$(document).mouseup(function() {
				// Since this is called first, but we want it called after slider.stop()
				setTimeout(function() {
					sliderUserMove = false;
					if (sliderUserTime > -1) {
						qt.player.SetTime(sliderUserTime);
						sliderUserTime = -1;
					}
				}, 5);
			});


			
			
		},
		
		onPlayable: function() {
			//d('Playable: ' + qt.player);
		},
		
		onPlayStart: function() {
			//d('Started playing');
		},
		
		onPlayPositionChanged: function(p) {
			if (!sliderUserMove) {
				sliderSetJS = true;
				$('#progress-slider').slider('moveTo', p, 0);
				sliderSetJS = false;
			}
		},
		
		onPlayFinish: function() {
			//d('Finished playing');
		},
		
		onSwitchTrack: function(url) {
			// Reset the controller here
		}
		
		
		
		
	
	}
	
	
};



function qtInit() {
	$('#player').css( {
		'display': 'block',
		'opacity': 0
	});
	$('#playpause .hover').css('opacity', 0);
	
	if (!AC.Detector.isQTInstalled()) {
		// if we don't have QT, display the download stuff
	//	$('#noqt').animate(things);
		qt.player = 'nonexistent';
		return;
	}
	
	var qtObject = AC.Quicktime.packageMovie('qt', 'lib/m/audio/blank.mp3', {
		width: 1,	// +!6?
		height: 1,
		autoplay: true,
		controller: false,
		cache: true,
		'bgcolor': 'transparent'	// To hide it on the background. Otherwise in Firefox it's a white dot.
	})
	
//	$('#player').css({'display': 'block' });
	$('#qt-player').prepend(qtObject);
	

	
	
	// Attach to the player; apple's code
	var attach = function(movie, onPlayable) {
	//	//d('Attempting attach.');
		
		var status = null;

		try {
			qt.player = movie;
			status = qt.player.GetPluginStatus();
		} catch(e) {
			try {
				qt.player = $('object', movie)[0];
				status = qt.player.GetPluginStatus();
			} catch(e) {
				//d('In last catch.');
				qt.player = null;
			}
		}
		
		movie = null;
		
		if (status == 'Playable' || status == 'Complete') {
			//d('Playable');
			qt.player.Stop();
			clearInterval(intAttach);
			if (onPlayable) onPlayable();

			if (qt.events.onPlayable) qt.events.onPlayable();
		} else if (status && status.match(/error/i)) {
			clearInterval(intAttach);
		}
	};
	
	var intAttach = setInterval(function() {
		attach(qtObject, function() {
			
			//d('Movie loaded.');
			if (qt.events.onLoaded) qt.events.onLoaded();
			
			var monitorInterval = setInterval(monitorEvents, 400);
		});
	}, 10);
		
}

function qtPlay(url) {
	//d('in qtPlay');
//	qt.player.SetBgColor('#161616');

	// Default to audio; ignore audioTypes for now
	var type = 'audio';
	//player.setAutoPlay(true);
	
	var ext = url.match(/.*\.(.+$)/)[1];
	
	if ($.inArray(ext, videoTypes)) type = 'video';

	// qt.player.Play();
	// Since auto-play is on...
	
}

function qtStop() {
	qt.player.Stop();
}



function monitorEvents() {
//	//d(' I guess they removed events so I have this loop here instead.');
	var isPlaying = qt.isPlaying();

	/*
		var shouldBePauseable = isPlaying && (this.currentControl == this.playControl);
		var shouldBePlayable = !isPlaying && (this.currentControl == this.pauseControl);

		if (!this.isJogging && shouldBePauseable) {
			this.controllerPanel.replaceChild(this.pauseControl, this.currentControl);
			this.currentControl = this.pauseControl;
		} else if (!this.isJogging && shouldBePlayable) {
			this.controllerPanel.replaceChild(this.playControl, this.currentControl);
			this.currentControl = this.playControl;
		}
	*/
	
	//update the loaded indicator
	if (qt.percentLoaded < 100) {
		var loaded = qt.player.GetMaxBytesLoaded() / qt.player.GetMovieSize();
		if (!isNaN(loaded) && 0 !== loaded)
			if (qt.events.onPercentLoadedChanged)
				qt.events.onPercentLoadedChanged(loaded * 100);
	}

	
	
	//unless the user is jogging the controller, update to reflect movie's status
	if (isPlaying)
		if (qt.events.onPlayPositionChanged)
			qt.events.onPlayPositionChanged((qt.player.GetTime() / qt.player.GetDuration()) * 100);
			 //this.slider.setValue(this.GetTime()/this.GetDuration());
	
	
	
	//is the movie playing?
	if (isPlaying) {
		if (!qt.playing) {
			$('#playpause').addClass('playing');
			qt.playing = true;
			if (qt.events.onPlayStart) qt.events.onPlayStart();
		}
	} else {
		if (qt.playing) {
			$('#playpause').removeClass('playing');
			qt.playing = false;
			if (qt.events.onPlayStop) this.options.onPlayStop();
		}
	}
	
	//has the movie just finished?
	if (qt.isFinished()) {
		if (!qt.finished) {
			//make the callback if necessary
			if (qt.events.onPlayFinished) qt.events.onPlayFinished();
			qt.finished = true;
		}
	} else
		qt.finished = false;
	
	
	/*if (this.movie !== null) {
		this.movieWatcher = setTimeout(this._monitor.bind(this), this.monitorDelay);
	}*/
}

/* Codename Rainbows Ñ 0.2 */
/* April 04, 2008 */

function initGradients(s) {
	$(function() {
		$(s).each(function() {
			var el = this;
			// Parse the inputs
			var from = '#ffffff', to = '#000000';
			var
				fR = parseInt(from.substring(1, 3), 16),
				fG = parseInt(from.substring(3, 5), 16),
				fB = parseInt(from.substring(5, 7), 16),
				tR = parseInt(to.substring(1, 3), 16),
				tG = parseInt(to.substring(3, 5), 16),
				tB = parseInt(to.substring(5, 7), 16);

			
			var h = $(this).height() * 1.5;
			
			//h = h - Math.floor((h * .07));
			
			var html;
			
			if (this.initHTML)
				html = this.initHTML;
			else
				html = this.innerHTML;
			
			this.initHTML = html;
			this.innerHTML = '';

			for (var i = 0; i < h; i++) {
				var c = '#' +
					(Math.floor(fR * (h - i) / h + tR * (i / h))).toString(16) +
					(Math.floor(fG * (h - i) / h + tG * (i / h))).toString(16) +
					(Math.floor(fB * (h - i) / h + tB * (i / h))).toString(16);
					
					if (c.length == 4) continue;

				d('.rainbow-' + i + '{ color: ' + c + '; }');
				
			// $('<span class="rainbow rainbow-' + i + '"><span style="top: ' + (-i - 1) + 'px;">' + html + '</span></span>').appendTo(this);

			$('<span class="rainbow rainbow-' + i + '" style="color: ' + c + ';"><span style="top: ' + (-i - 1) + 'px;">' + html + '</span></span>').appendTo(this);

			}
			
			$('<span class="highlight">' + html + '</span>').appendTo(this);
			$('<span class="shadow">' + html + '</span>').appendTo(this);
			$('<span class="source">' + html + '</span>').appendTo(this);

		});
		
	});
}

initGradients('.rainbows');

function initShadows(s) {
	$(function() {
		$(s).each(function() {
		
		
		if (this.initHTML)
				html = this.initHTML;
			else
				html = this.innerHTML;
			
			this.initHTML = html;
			this.innerHTML = '';
				
		$('<span class="shadow">' + html + '</span><span class="source">' + html + '</span>').appendTo(this);

		});
		
	});
}
initShadows('.shadows');$(function() { inputFocus(); });function inputFocus() {	$(' .shy').focus(function() {		if (!this.shyValue) this.shyValue = $(this).val();				$(this).removeClass('shy');				if ($(this).val() == this.shyValue) $(this).val('');			})	.blur(function() {		if ($(this).val() == this.shyValue || $(this).val() == '')			$(this).addClass('shy').val(this.shyValue);	});}/* Â© 2008 Dragon Interactive LLC */
/* Build 2.1 - July 2, 2008 */

// 			$('a[@href$="' + self.options.selector + '"]')
// $ = endsWith.

SlideShow = function() { this.init.apply(this, arguments); }

SlideShow.prototype = {
	init: function(options) {	
		var dOptions = {
			autoStart: true,
			interval: 7000,
			selector: '#ss',
			stopOnHover: true,
			fade: 700
		};
		
		this.options = jQuery.extend(dOptions, options);
		this.go();
	},

	go: function() {
		$(this.options.selector).css('position', 'relative');
		


		this.divs = $(this.options.selector + '> div').not('.pagination').css({
			display: 'none',
			position: 'absolute'
		}).get();

		this.count = this.divs.length;
	//	console.log(this.options.selector + '!' + this.count);
		this.divs[0].style.display = 'block';
		
		this.curDiv = this.divs[0];
		
		this.initEvents();
		$('a[@href$="' + this.options.selector + '"]:first').addClass('active');
		if (this.options.autoStart)
			this.start();
	},

	initEvents: function() {
		var self = this;
		
		$(this.options.selector + '-controls .ss-next').click(function() {
			self.next.apply(self);
			return false;
		});

		$(this.options.selector + '-controls .ss-prev').click(function() {
			self.prev.apply(self);
			return false;
		});

		$(this.options.selector + '-controls .ss-start').click(function() {
			self.start.apply(self);
			return false;
		});

		$(this.options.selector + '-controls .ss-stop').click(function() {
			self.stop.apply(self);
			return false;
		});

		$('a[@href$="' + this.options.selector + '"]').click(function() {
			self.stop();
			var cClass = this.className;
	//		alert(this + ', ' + cClass);
			var selector = self.options.selector + ' .' + cClass;
			var switchTo = $(selector).get(0);
			
			if (switchTo == self.curDiv) return false;
			
			self.switchPanes.apply(self, [switchTo]);
			
			// Remove active classes from everything and add them back to the current one
			$('a[@href$="' + self.options.selector + '"]').removeClass('active');
			$(this).addClass('active');
			
			return false;
		});

		if (this.options.stopOnHover) {
			$(this.options.selector + ' div,' + this.options.selector + '-controls .dots').hover(function() { self.stop.apply(self); }, function() { self.start.apply(self); });
		}
	},

	getNext: function(div) {
		for (var i = 0; i < this.count; i++) {
			if (this.divs[i] == div) break;
		}
		
		if (i == this.count - 1) return this.divs[0];
		return this.divs[i + 1];
	},
	
	getPrev: function(div) {
		for (var i = 0; i < this.count; i++) {
			if (this.divs[i] == div) break;
		}
		
		if (i == 0) return this.divs[this.count - 1];
		return this.divs[i - 1];

	},
	
	start: function() {
		var self = this;
		if (!this.theInterval)
		this.theInterval = setInterval(function() { self.next.apply(self); }, this.options.interval);
	},

	stop: function() {
		clearInterval(this.theInterval);
		this.theInterval = 0;
	},

	next: function() {
		this.switchPanes(this.getNext(this.curDiv));
	},

	prev: function() {
		this.switchPanes(this.getPrev(this.curDiv));
	},

	switchPanes: function(newDiv) {
		var self = this;
		
		//console.log(this.options.selector + ': newDiv:' + newDiv);
		
				// Set appropriate zIndices so that the new one is above the old one.
		this.curDiv.style.zIndex = 50;
		newDiv.style.zIndex = 100;
		
		//console.log('CurDiv zIndex: ' + this.curDiv.style.zIndex + ', newDiv.zIndex: ' + newDiv.style.zIndex);
		
		// Cancel all animations
		//ignore anims for now$(this.curDiv).stop().css('opacity', 1).css('display', 'block');
		
		// Run the function
		if (this.curDiv.finalize) this.curDiv.finalize.apply(this.curDiv);
	//	if (this.prevDiv.makeNew) this.prevDiv.makeNew.apply(this.curDiv);
		
	//	console.log('switching panes from ' + this.curDiv.className + ' to ' + newDiv.className);
		
		
		
		newDiv.finalized = false;
		
		newDiv.finalize = function() {
		//	console.log(' Finalizing:' + newDiv.className + ', before finalized');
		
			if (this.finalized) return false;
	//		console.log(' Finalizing:' + newDiv.className);
			// Hide the old div
			$(self.prevDiv).css('display', 'none');
			// Show the current, new div
			$(this).css('display', 'block');//.css('opacity', 1);
			
			this.finalized = true;
			
			// Get rid of this function; we do not need it any more.
			//this.finalize = null;
		};
			
		// CORRECT AT YOUR OWN RISK, SEEMS TO WORK FINE WITH THE TYPO
		$(self.curDid).stop();
		
		self.prevDiv = self.curDiv;
		self.curDiv = newDiv;
		
		$(newDiv)
			.css({'display': 'block', 'opacity': 0})
			.animate({
				'opacity': 1
			}, self.options.fade, newDiv.finalize);


		// Remove active classes from all and add them back to just the current one
		$('a[@href$="' + self.options.selector + '"]')
			.removeClass('active')
			.each(function() {
				if ($(this).hasClass(newDiv.className)) $(this).addClass('active');
			});
			
		this.stop();
		this.start();

	},

	getAnchor: function(s){
	  var strReturn = '';
	  if ( s.indexOf('#') > -1 )
	   	strReturn = s.substr(s.indexOf('#') + 1).toLowerCase();

  		return strReturn;
	}
	

	
};
$(function() {
	focusInput();
	initContact();
	
});

var contacted = false, contacting = false;

function ajax(url, callback, pars, html) {
	var json = function(parse) {
		var json = eval('(' + parse + ')');
		return json;
	}

	$.post(url, pars, function(parse) {
//		alert(parse);
d(parse);
		if (parse)
			if (html)
				callback(parse);
			else
				callback(json(parse));
		else
			callback();
	});
}


function focusInput() {
	$('#contact-name').focus();
}

function initContact() {


	$('#contact-send').click(function() {
		$('#form-contact').submit();
		return false;
	});

	$('#form-contact').submit(function() {
		if (contacted || contacting) return false;
		
		contacting = true;
		
		var name = $('#contact-name').val();
		var email = $('#contact-email').val();
		var website = $('#contact-website').val();
		var message = $('#contact-message').val();

//		spin('#form-contact');
//		clearftips('#form-contact');
		
		ajax('lib/p/contact/send.php', function(json) {
	//		unspin('#form-contact');
			
			$('#form-contact input, #form-contact textarea')
				.removeClass('error')
				.attr('title', '');
				
			if (json.success){
				alert('Your message has been sent to Nick. He will get back to you presently.');
			//	showInfo($('#form-contact')[0], 'Your message has been sent to Yuri.');
				
			//	clearError('#form-contact');

				$('#contact-message').val('').blur();
				// focusInput();
				
				contacted = true;

				$('#contact-send').animate({
					'opacity': 0
				}, 500, function() { $(this).remove(); });
				
			} else {
				
				if (json.sendFailed)
					showInfo($('#form-contact')[0], 'Your server does not support PHP\'s mail() function. <a href="mailto:nick@noisefreak.com?subject=Hello!&body=' + escape($('#contact-message').val()) + '">Send me an email yourself</a>.');

 				// Normal Error
 				
				var first;
				var msg = '';
				for (input in json.error) {
					first = first ? first : input;
					//alert(json.error[input] );
					if (json.error[input] != undefined)
						$('#contact-' + input)
							.addClass('error')
							.attr('title', json.error[input]);
					//ftip('#contact-' + input, json.error[input]);
				}
				$('#contact-' + first).focus().select();

				//showError('#form-contact');
			}
			
			contacting = false;
		}, {
			'name': name,
			'email': email,
			'website': website,
			'message': message
		});
		
		return false;
	});
}$(function() {
	focusInput();
//	initForgotPassword();
	initLoginCheck();
	initForgot();
	
	initCollapse();
});

function initCollapse() {

//	console.log($('.indent .indent').css('display'));

	$('.indent .indent').css('height', '32px');
	$('#listing .foldertitle').toggle(function() {
		
		$(this).parent().css('height', 'auto').addClass('opened');
	}, function() {
		$(this).parent().css('height', '32px').removeClass('opened');
	})
}

function initLoginCheck() {
	$('#l-submit').click(function() {
		$('#login').submit();
		return false;
	});

	$('#login').submit(function() {
		
		var email = $('#login-email').val();
		var password = $('#login-password').val();

		spin('#login');
		clearftips('#login');

		ajax('client/checklogin.php', function(json) {
			unspin('#login');

			if (json.success){
				//clearError('#login');

				$('#login').unbind('submit').submit();
			} else {
				var first;

				for (input in json.error) {
					first = first ? first : input;
					ftip('#login-' + input, json.error[input]);
				}
				$('#login-' + first).focus().select();
				
				//
				//
				//showError('#login');
			}

		}, {
			'email': email,
			'password': password
		});

		return false;
	});
}


function initForgot() {
	$('#inform').css('opacity', 0);

	$('#forgot-link').click(function() {
		$('#login').animate({ 'opacity': 0 }, 400, 'easeOutExpo', function() {
			$(this).css('display', 'none');
		});

		$('#forgot-email').val($('#login-email').val()).focus().select();

		return false;
	});
	
	//return false;
	
	
	$('#f-cancel').click(function() {
		$('#login').css('display', 'block').animate({ 'opacity': 1 }, 400, 'easeOutExpo');			
		$('#login-email').focus();

	});
	
	$('#f-submit').click(function() {
	
		var email = $('#forgot-email').val();
	//	spin('#login');

		ajax('lib/p/login/forgot.php', function(json) {
		//	unspin('#login');
		
			if (json.success || json.sendFailed) {

				if (json.success)
					inform('Your password has been sent to ' + email + '.');

				if (json.sendFailed)
					inform('This server does not support PHP\'s mail() function. Delete settings.txt in the data folder to reset your password.');

				//clearError('#login');

				// Remove the link
				if (json.success) {
					$('#forgot-link').animate({
						'opacity': 0
					}, 500, function() { $(this).remove(); });
					$('#forgot-email').removeClass('error');
					
					$('#login').css('display', 'block').animate({ 'opacity': 1 }, 400, 'easeOutExpo');
					
					$('#login-email').val($('#forgot-email').val());
					$('#login-password').focus();
				}
			} else {

				var first;
				clearftips('#forgot');
				$('#forgot-email').addClass('error');
				ftip('#forgot-email', json.error);
				
				$('#login-' + first).focus().select();

			}

		}, {
			'email': email
		});
	
		return false;	
	});
	
	function inform(msg) {
		$('#inform').css('display', 'block').animate({ 'opacity': 1 }, 400, 'easeOutExpo').html(msg);
		
	}
	

}

function spin() {

}

function unspin() {

}

function focusInput() {
	// Focus on the email input, password input, or password input with the caret at the end
	if ($('#login-password').size() == 0) return;
	if ($('#login-email').size() == 0) return;

	setTimeout(function() {
		if ($('#login-email').val() == '')
			$('#login-email').focus();
		else if ($('#login-password').val() == '')
			$('#login-password').focus();
		else
			$('#login-password').focus()[0].selectionStart = 999;
	}, 100);
}


function ftip(input, message) {
	$(input).attr('title', message).addClass('error')
}


function clearftip(input) {
	$(input).attr('title', '').removeClass('error');
}


function clearftips(form) {
	$(form).find('input').attr('title', '').removeClass('error');
}



