if (navigator.userAgent.match(/iphone|ipod|android|iemobile/i) && document.cookie.indexOf("notouch=1") == -1
	&& window.location.hostname == 'www.parkwhiz.com') {
	window.location = 'http://touch.parkwhiz.com'+window.location.pathname+window.location.search;
}

if (window!= top && top.location.host != location.host) {
	top.location.href=location.href
}

var DAYS = Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var DAYS_ABBR = Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

$(function(){
	$('input.date').each(function(){
		var $this = $(this);
		var opts = {};

		if ($this.hasClass('future')) {
			opts.minDate = new Date();
		}

		if ($this.hasClass('start') || $this.hasClass('end')) {
			opts.onSelect = doDatepair;
		}

		$this.datepicker(opts);
	});

	$('input.time, select.time').each(function() {
		var $this = $(this);
		var opts = { 'showDuration': true, 'timeFormat': 'g:ia', 'scrollDefaultNow': true };

		if ($this.hasClass('start') || $this.hasClass('end')) {
			opts.onSelect = doDatepair;

		}

		$this.timepicker(opts);
	});

	$('.datepair').each(initDatepair);

	$('input.textCopy').each(function() {
		$(this).bind('focus', function(e) {
			this.select();
			e.preventDefault();
		});
	});

	$('a.newWin').each(function() {
		$(this).bind('click', newWin);
		if (document.createElement) {
			var img = document.createElement('img');
			img.src = "/images/new-win-icon.gif";
			this.appendChild(img);
		}
	});

	$('input.focusField:first').focus();
	$('input[placeholder]').placeHeld();

	$('.tiptip').tipTip({delay:0, fadeIn:0, fadeOut:0});

	$('.activeLabels input[type=checkbox]').bind('change', function() {
		if (this.checked) {
			$(this).closest('label').addClass('checked');
		} else {
			$(this).closest('label').removeClass('checked');
		}
	});

	$('.activeLabels input[type=checkbox]').each(function() {
		if (this.checked) {
			$(this).closest('label').addClass('checked');
		} else {
			$(this).closest('label').removeClass('checked');
		}
	});

	$('a.fbshare').bind('click', function() {

		_gaq.push(['_trackEvent', 'Sharing', 'Facebook', this.rel]);

		var url = 'http://www.facebook.com/sharer.php?u='+this.rel

		if (this.title != '') url += '&t='+this.title;

		window.open(url, 'shareWin', 'menubar=no,width=550,height=330,toolbar=no');
		return false;
	});

	$('a.twittershare').bind('click', function() {

		_gaq.push(['_trackEvent', 'Sharing', 'Twitter', this.rel]);

		var url = 'http://twitter.com/share?via=ParkWhiz&url='+this.rel;

		if (this.title != '') url += '&text='+this.title;

		window.open(url, 'shareWin', 'menubar=no,width=550,height=330,toolbar=no');
		return false;
	});

	$('.blocklink').live('click', function() {
		var url = $(this).find('a').attr('href');

		if (url) {
			window.location = url;
		}
	});

	(function() {
		var gm = document.createElement('link'); gm.type = 'text/css'; gm.rel = 'stylesheet'; gm.media='print';
		gm.href = pw.stat('/css/print.css');
		document.getElementsByTagName('head')[0].appendChild(gm);
	})();
});

function namespace(namespaceString) {
    var parts = namespaceString.split('.'),
        parent = window,
        currentPart = '';

    for(var i = 0, length = parts.length; i < length; i++) {
        currentPart = parts[i];
        parent[currentPart] = parent[currentPart] || {};
        parent = parent[currentPart];
    }

    return parent;
}


var pw = namespace('pw');

pw.stat = function(path)
{
	if (pw.staticHost) {
		return pw.staticHost+path+'.'+pw.gitHash;
	} else {
		return path;
	}
}

pw.mapSpriteCoords = function(icon, color) {

	if (icon == 'p') {
		if (color == 'white') {
			return new google.maps.Point(21, 340);
		} else {
			return new google.maps.Point(0, 340);
		}
	} else if (icon == 'number_shadow') {
		return new google.maps.Point(77, 340);
	} else if (icon == 'p_shadow') {
		return new google.maps.Point(42, 340);
	} else {
		// number icon is 29x26, rows of 10, 50 blue then 50 white

		var number = icon-1;

		var top = Math.floor(number/10)*34;
		if (color == 'white') {
			top += 170;
		}

		var left = (number % 10)*26;
		return new google.maps.Point(left, top);
	}
}

function initDatepair()
{
	var container = $(this);

	var startDateInput = container.find('input.start.date');
	var endDateInput = container.find('input.end.date');
	var dateDelta = 0;

	if (startDateInput.length && endDateInput.length) {
		var startDate = new Date(startDateInput.val());
		var endDate =  new Date(endDateInput.val());
		dateDelta = endDate.getTime() - startDate.getTime();

		container.data('dateDelta', dateDelta);
	}

	var startTimeInput = container.find('input.start.time');
	var endTimeInput = container.find('input.end.time');

	if (startTimeInput.length && endTimeInput.length) {
		var startInt = startTimeInput.timepicker('getSecondsFromMidnight');
		var endInt = endTimeInput.timepicker('getSecondsFromMidnight');

		container.data('timeDelta', endInt - startInt);

		if (dateDelta < 86400000) {
			endTimeInput.timepicker('option', 'minTime', startInt);
		}
	}
}

function doDatepair()
{
	var target = $(this);
	var container = target.closest('.datepair');

	if (target.hasClass('date')) {
		updateDatePair(target, container);

	} else if (target.hasClass('time')) {
		updateTimePair(target, container);
	}
}

function updateDatePair(target, container)
{
	var start = container.find('input.start.date');
	var end = container.find('input.end.date');

	if (!start.length || !end.length) {
		return;
	}

	var startDate = new Date(start.val());
	var endDate =  new Date(end.val());

	var oldDelta = container.data('dateDelta');

	if (oldDelta && target.hasClass('start')) {
		var newEnd = new Date(startDate.getTime()+oldDelta);
		end.datepicker('setDate', newEnd);
		return;

	} else {
		var newDelta = endDate.getTime() - startDate.getTime();

		if (newDelta < 0) {
			newDelta = 0;

			if (target.hasClass('start')) {
				end.datepicker('setDate', startDate);
			} else if (target.hasClass('end')) {
				start.datepicker('setDate', endDate);
			}
		}

		if (newDelta < 86400000) {
			var startTimeVal = container.find('input.start.time').val();

			if (startTimeVal) {
				container.find('input.end.time').timepicker('option', {'minTime': startTimeVal});
			}
		} else {
			container.find('input.end.time').timepicker('option', {'minTime': null});
		}

		container.data('dateDelta', newDelta);
	}
}

function updateTimePair(target, container)
{
	var start = container.find('input.start.time');
	var end = container.find('input.end.time');

	if (!start.length || !end.length) {
		return;
	}

	var startInt = start.timepicker('getSecondsFromMidnight');
	var endInt = end.timepicker('getSecondsFromMidnight');

	var oldDelta = container.data('timeDelta');
	var dateDelta = container.data('dateDelta');

	if (target.hasClass('start') && (!dateDelta || dateDelta < 86400000)) {
		end.timepicker('option', 'minTime', startInt);
	}

	var endDateAdvance = 0;
	var newDelta;

	if (oldDelta && target.hasClass('start')) {
		// lock the duration and advance the end time

		var newEnd = (startInt+oldDelta)%86400;

		if (newEnd < 0) {
			newEnd += 86400;
		}

		end.timepicker('setTime', newEnd);
		newDelta = newEnd - startInt;
	} else if (startInt !== null && endInt !== null) {
		newDelta = endInt - startInt;
	} else {
		return;
	}

	container.data('timeDelta', newDelta);

	if (newDelta < 0 && (!oldDelta || oldDelta > 0)) {
		// overnight time span. advance the end date 1 day
		var endDateAdvance = 86400000;

	} else if (newDelta > 0 && oldDelta < 0) {
		// switching from overnight to same-day time span. decrease the end date 1 day
		var endDateAdvance = -86400000;
	}

	var startInput = container.find('.start.date');
	var endInput = container.find('.end.date');

	if (startInput.val() && !endInput.val()) {
		endInput.datepicker('setDate', startInput.val());
		dateDelta = 0;
		container.data('dateDelta', 0);
	}

	if (endDateAdvance != 0) {
		if (dateDelta || dateDelta === 0) {
			var endDate =  new Date(endInput.val());
			var newEnd = new Date(endDate.getTime() + endDateAdvance);

			endInput.datepicker('setDate', newEnd);
			container.data('dateDelta', dateDelta + endDateAdvance);
		}
	}
}



function newWin(e)
{
	var event = new Event(e);
	var obj = event.target;
	var newwin = window.open(obj.href);
	if (newwin)
		event.stop();
};


function isChild(el, parent)
{
	if (el == parent)
		return true;
	else if (el.parentNode == null)
		return false;
	else
		return isChild(el.parentNode, parent);
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
};

function isNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
			IsNumber = false;
	}
	return IsNumber;
};

function showHowItWorks(e)
{
	e.preventDefault();

	if ($('#howitworks').length) {
		return false;
	}

	$.get('/how.html', function(resp) {
		$('body').prepend(resp);
		var offsets = getScrollXY();
		$('#howitworks').css('top', offsets[1]+50+'px');
		jQuery('#howitworks a.close').bind('click', closeHowItWorks);

		$(document).bind('click', closeHowItWorks);
	})

	return false;
}
function closeHowItWorks(e)
{
	if (e.target.id == 'howitworks') {
		return true;
	}

	var extTarget = $(e.target)
	if (extTarget.hasClass('close') || extTarget.parents('#howitworks').length == 0) {
		$('#howitworks').remove();
		$(document).unbind('click', closeHowItWorks);
		return false;
	} else {
		return true;
	}
}



function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function removeChildrenFromNode(node)
{
	if(!node) {
		return;
	}

	var len = node.childNodes.length;

	while (node.hasChildNodes()) {
		node.removeChild(node.firstChild);
	}
};

function confirmSubmit(msg)
{
	if (!msg) msg = "Are you sure you wish to do that? There is no undo.";
	var agree=confirm(msg);
	if (agree)
		return true;
	else
		return false;
};

function makePhoneString(phone)
{
	return '('+phone.substr(0,3)+') '+phone.substr(3,3)+'-'+phone.substr(6,4);
};

function cloneObject(what)
{
	for (i in what) {
		if (what[i] == null)
			this[i] = null;
		else if (typeof what[i] == 'object')
			this[i] = new cloneObject(what[i]);
		else
			this[i] = what[i];
	}
};

var trackAdwordsConversionCalled = false;
function trackAdwordsConversion(label, value)
{
	if (trackAdwordsConversionCalled) {
		return;
	}

	trackAdwordsConversionCalled = true;

	var google_conversion_id  = 1059819198;

	if (!value) value = 0;

	image = new Image(1,1);
	image.src = document.location.protocol+"//www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value="+value+"&label="+label+"&script=0";
};

function compareObjects(obj1, obj2)
{
	for (i in obj1) {
		if (obj1[i] != obj2[i])
			return false
	}

	return true;
};

function getQueryVar(varName, qstring)
{
	if (!qstring)
		qstring = window.location.search.substring(1);

	if (qstring.lastIndexOf('?') > 0)
		qstring = qstring.split('?')[1];

	var vars = qstring.split("&");

	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == varName) {
			return pair[1];
		}
	}
	return '';
}

(function($){
	$.PopupClose = function(containerId)
	{
		var container = jQuery('#'+containerId);
		container.hide();
	}

	$.fn.Popup = function(linkId, positionMe)
	{
		var openLink = jQuery('#'+linkId);
		var extendedThis = jQuery(this);

		function open(e)
		{
			if (jQuery('#'+extendedThis.attr('id')+':visible').length) {
				extendedThis.hide();
			} else {
				extendedThis.slideDown(300);
			}

			if (positionMe) {
				extendedThis.css({
				'position': 'absolute',
				'top': e.pageY+'px',
				'left': e.pageX+'px',
				'z-index': 1000 });
			}

			return false;
		}

		function close(e)
		{
			if ($(e.target).parents().index(extendedThis) == -1 && jQuery('#'+extendedThis.attr('id')+':visible').length) {
				extendedThis.hide();
				return false;
			}
		}

		openLink.bind('click', open);
		jQuery(document).bind('click', close);

		extendedThis.hide();
		return this;
	}
})(jQuery);

(function($){
	$.fn.Flasher = function()
	{
		return this.each(function(){
			var extThis = $(this);
			var currentColor = extThis.css('backgroundColor');
			$(this).animate({backgroundColor: '#fff'}, 300).animate({backgroundColor: currentColor}, 300)
				.animate({backgroundColor: '#fff'}, 300).animate({backgroundColor: currentColor}, 300)
				.animate({backgroundColor: '#fff'}, 300).animate({backgroundColor: currentColor}, 300);
		});
	}
})(jQuery);

/* placeheld for jquery - http://github.com/makenosound/jquery-placeheld */
(function($){
	$.placeHeld = function(el, options){
		var base = this;
		base.$el = $(el);
		base.el = el;
		base.$el.data("placeHeld", base);
		base.placeholderText = base.$el.attr("placeholder");

		base.init = function(){
			base.options = $.extend({},$.placeHeld.defaultOptions, options);
			base.$el.bind('blur', base.holdPlace).bind('focus', base.releasePlace).trigger('blur');
			base.$el.parents('form').bind('submit', base.releasePlace);
		};
		// Hold with the default value attribute
		base.holdPlace = function() {
			var value = base.$el.val();
			if (!value) base.$el.val(base.placeholderText).addClass(base.options.className);
		};
		// Refill with the default value attribute
		base.releasePlace = function() {
			var value = base.$el.val();
			if (value == base.placeholderText) base.$el.val('').removeClass(base.options.className);
		};
		base.init();
	};

	$.placeHeld.defaultOptions = { className: "placeheld" };

	$.fn.placeHeld = function(options) {

		// Check for placeholder attribute support
		if (!!("placeholder" in $('<input>')[0])) return;

		return this.each(function() {
			(new $.placeHeld(this, options));
		});
	};
})(jQuery);

/* jQuery cookie plugin http://plugins.jquery.com/project/cookie */
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};

/* jQuery timepicker plugin */
(function(d){var l=new Date().getTimezoneOffset();var c={className:null,minTime:null,step:30,showDuration:false,timeFormat:"g:ia",scrollDefaultNow:false,onSelect:function(){}};var b={init:function(m){return this.each(function(){var q=d(this);if(q[0].tagName=="SELECT"){var p=d("<input />");var r={type:"text",value:q.val()};var n=q[0].attributes;for(var s=0;s<n.length;s++){r[n[s].nodeName]=n[s].nodeValue}p.attr(r);q.replaceWith(p);q=p}var t=d.extend({},c);if(m){t=d.extend(t,m)}if(t.minTime){t.minTime=e(t.minTime)}q.data("settings",t);q.attr("autocomplete","off");q.click(b.show).focus(b.show).keydown(a);q.addClass("ui-timepicker-input");if(q.val()){var u=f(e(q.val()),t.timeFormat);q.val(u)}var o=d('<span class="ui-timepicker-container" />');q.wrap(o);d("body").attr("tabindex",-1).focusin(function(v){if(d(v.target).closest(".ui-timepicker-container").length==0){b.hide()}})})},show:function(s){var m=d(this);var r=m.siblings(".ui-timepicker-list");if(m.hasClass("ui-timepicker-hideme")){m.removeClass("ui-timepicker-hideme");r.hide();return}if(r.is(":visible")){return}b.hide();if(r.length==0){g(m);r=m.siblings(".ui-timepicker-list")}if((m.offset().top+m.outerHeight(true)+r.outerHeight())>d(window).height()+d(window).scrollTop()){r.css({top:m.position().top-r.outerHeight()})}else{r.css({top:m.position().top+m.outerHeight(true)})}r.show();var p=m.data("settings");var o=r.find(".ui-timepicker-selected");if(!o.length&&p.scrollDefaultNow){var q=e(new Date());o=i(m,r,q)}if(o&&o.length){var n=r.scrollTop()+o.position().top-o.outerHeight();r.scrollTop(n)}},hide:function(m){d(".ui-timepicker-list:visible").each(function(){var o=d(this);var n=o.siblings(".ui-timepicker-input");j(n);o.hide()})},option:function(n,q){var m=d(this);var o=m.data("settings");var p=m.siblings(".ui-timepicker-list");if(typeof n=="object"){o=d.extend(o,n)}else{if(typeof n=="string"&&typeof q!="undefined"){o[n]=q}else{if(typeof n=="string"){return o[n]}}}if(o.minTime){o.minTime=e(o.minTime)}m.data("settings",o);p.remove()},getSecondsFromMidnight:function(){return e(d(this).val())},setTime:function(n){var m=d(this);var o=f(e(n),m.data("settings").timeFormat);m.val(o)}};function g(t){var n=t.data("settings");var q=t.siblings(".ui-timepicker-list");if(q&&q.length){q.remove()}q=d("<ul />");q.attr("tabindex",-1);q.addClass("ui-timepicker-list");if(n.className){q.addClass(n.className)}var r=t.css("zIndex");r=(r+0==r)?r+1:2;q.css({display:"none",position:"absolute",left:(t.position().left),zIndex:r});if(n.minTime!==null&&n.showDuration){q.addClass("ui-timepicker-with-duration")}var m=(n.minTime!==null)?n.minTime:0;for(var p=m;p<m+86400;p+=n.step*60){var s=p%86400;var u=d("<li />");u.data("time",s);u.text(f(s,n.timeFormat));if(n.minTime!==null&&n.showDuration){var o=d("<span />");o.addClass("ui-timepicker-duration");o.text(" ("+h(p-n.minTime)+")");u.append(o)}q.append(u)}t.after(q);k(t,q);q.delegate("li","click",{timepicker:t},function(v){t.addClass("ui-timepicker-hideme");t[0].focus();q.find("li").removeClass("ui-timepicker-selected");d(this).addClass("ui-timepicker-selected");j(t)})}function i(m,q,p){if(!p&&p!==0){return false}var o=m.data("settings");var n=false;q.find("li").each(function(r,t){var s=d(t);if(Math.abs(s.data("time")-p)<=o.step*30){n=s;return false}});return n}function k(m,p){var o=e(m.val());var n=i(m,p,o);if(n){n.addClass("ui-timepicker-selected")}}function a(p){var m=d(this);var o=m.siblings(".ui-timepicker-list");switch(p.keyCode){case 13:j(m);b.hide.apply(this);p.preventDefault();return false;break;case 38:var n=o.find(".ui-timepicker-selected");if(n.length&&!n.is(":first-child")){n.removeClass("ui-timepicker-selected");n.prev().addClass("ui-timepicker-selected");if(n.prev().position().top<n.outerHeight()){o.scrollTop(o.scrollTop()-n.outerHeight())}}break;case 40:if(!o.is(":visible")){m.focus()}var n=o.find(".ui-timepicker-selected");if(n.length==0){o.children().first().addClass("ui-timepicker-selected")}else{if(!n.is(":last-child")){n.removeClass("ui-timepicker-selected");n.next().addClass("ui-timepicker-selected");if(n.next().position().top+2*n.outerHeight()>o.outerHeight()){o.scrollTop(o.scrollTop()+n.outerHeight())}else{}}}break;case 27:o.find("li").removeClass("ui-timepicker-selected");o.hide();break;case 9:case 16:case 17:case 18:case 19:case 20:case 33:case 34:case 35:case 36:case 37:case 39:case 45:return;default:o.find("li").removeClass("ui-timepicker-selected");return}}function j(m){var p=m.data("settings");var q=m.siblings(".ui-timepicker-list");var o=null;var r=q.find(".ui-timepicker-selected");if(r.length){var o=r.data("time")}else{if(m.val()){var o=e(m.val());k(m,q)}}if(o!==null){var n=f(o,p.timeFormat);m.attr("value",n)}p.onSelect.call(m);m.trigger("change")}function h(o){var n=Math.round(o/60);if(n<60){return n+" mins"}else{if(n==60){return"1 hr"}else{var m=n/60;return m.toFixed(1)+" hrs"}}}function f(t,s){var r=new Date((t+l*60)*1000);var n="";for(var p=0;p<s.length;p++){var q=s.charAt(p);switch(q){case"a":n+=(r.getHours()>11)?"pm":"am";break;case"A":n+=(r.getHours()>11)?"PM":"AM";break;case"g":var m=r.getHours()%12;n+=(m==0)?"12":m;break;case"G":n+=r.getHours();break;case"h":var m=r.getHours()%12;if(m!=0&&m<10){m="0"+m}n+=(m==0)?"12":m;break;case"H":var m=r.getHours();n+=(m>9)?m:"0"+m;break;case"i":var o=r.getMinutes();n+=(o>9)?o:"0"+o;break;case"s":var t=r.getSeconds();n+=(t>9)?t:"0"+t;break;default:n+=q}}return n}function e(p){if(p==""){return null}if(p+0==p){return p}if(typeof(p)=="object"){p=p.getHours()+":"+p.getMinutes()}var r=new Date(0);var q=p.toLowerCase().match(/(\d+)(?::(\d\d))?\s*([pa]?)/);if(!q){return null}var n=parseInt(q[1]*1);if(q[3]){if(n==12){var m=(q[3]=="p")?12:0}else{var m=(n+(q[3]=="p"?12:0))}}else{var m=n}var o=(q[2]*1||0);return m*3600+o*60}d.fn.timepicker=function(m){if(b[m]){return b[m].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof m==="object"||!m){return b.init.apply(this,arguments)}else{d.error("Method "+m+" does not exist on jQuery.timepicker")}}}})(jQuery);


/*
* TipTip
* Copyright 2010 Drew Wilson
* www.drewwilson.com
* code.drewwilson.com/entry/tiptip-jquery-plugin
*
* Version 1.3   -   Updated: Mar. 23, 2010
*
* This Plug-In will create a custom tooltip to replace the default
* browser tooltip. It is extremely lightweight and very smart in
* that it detects the edges of the browser window and will make sure
* the tooltip stays within the current window size. As a result the
* tooltip will adjust itself to be displayed above, below, to the left
* or to the right depending on what is necessary to stay within the
* browser window. It is completely customizable as well via CSS.
*
* This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*/
(function($){$.fn.tipTip=function(options){var defaults={activation:"hover",keepAlive:false,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:false,enter:function(){},exit:function(){}};var opts=$.extend(defaults,options);if($("#tiptip_holder").length<=0){var tiptip_holder=$('<div id="tiptip_holder" style="max-width:'+opts.maxWidth+';"></div>');var tiptip_content=$('<div id="tiptip_content"></div>');var tiptip_arrow=$('<div id="tiptip_arrow"></div>');$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')))}else{var tiptip_holder=$("#tiptip_holder");var tiptip_content=$("#tiptip_content");var tiptip_arrow=$("#tiptip_arrow")}return this.each(function(){var org_elem=$(this);if(opts.content){var org_title=opts.content}else{var org_title=org_elem.attr(opts.attribute)}if(org_title!=""){if(!opts.content){org_elem.removeAttr(opts.attribute)}var timeout=false;if(opts.activation=="hover"){org_elem.hover(function(){active_tiptip()},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}else if(opts.activation=="focus"){org_elem.focus(function(){active_tiptip()}).blur(function(){deactive_tiptip()})}else if(opts.activation=="click"){org_elem.click(function(){active_tiptip();return false}).hover(function(){},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}function active_tiptip(){opts.enter.call(this);tiptip_content.html(org_title);tiptip_holder.hide().removeAttr("class").css("margin","0");tiptip_arrow.removeAttr("style");var top=parseInt(org_elem.offset()['top']);var left=parseInt(org_elem.offset()['left']);var org_width=parseInt(org_elem.outerWidth());var org_height=parseInt(org_elem.outerHeight());var tip_w=tiptip_holder.outerWidth();var tip_h=tiptip_holder.outerHeight();var w_compare=Math.round((org_width-tip_w)/2);var h_compare=Math.round((org_height-tip_h)/2);var marg_left=Math.round(left+w_compare);var marg_top=Math.round(top+org_height+opts.edgeOffset);var t_class="";var arrow_top="";var arrow_left=Math.round(tip_w-12)/2;if(opts.defaultPosition=="bottom"){t_class="_bottom"}else if(opts.defaultPosition=="top"){t_class="_top"}else if(opts.defaultPosition=="left"){t_class="_left"}else if(opts.defaultPosition=="right"){t_class="_right"}var right_compare=(w_compare+left)<parseInt($(window).scrollLeft());var left_compare=(tip_w+left)>parseInt($(window).width());if((right_compare&&w_compare<0)||(t_class=="_right"&&!left_compare)||(t_class=="_left"&&left<(tip_w+opts.edgeOffset+5))){t_class="_right";arrow_top=Math.round(tip_h-13)/2;arrow_left=-12;marg_left=Math.round(left+org_width+opts.edgeOffset);marg_top=Math.round(top+h_compare)}else if((left_compare&&w_compare<0)||(t_class=="_left"&&!right_compare)){t_class="_left";arrow_top=Math.round(tip_h-13)/2;arrow_left=Math.round(tip_w);marg_left=Math.round(left-(tip_w+opts.edgeOffset+5));marg_top=Math.round(top+h_compare)}var top_compare=(top+org_height+opts.edgeOffset+tip_h+8)>parseInt($(window).height()+$(window).scrollTop());var bottom_compare=((top+org_height)-(opts.edgeOffset+tip_h+8))<0;if(top_compare||(t_class=="_bottom"&&top_compare)||(t_class=="_top"&&!bottom_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_top"}else{t_class=t_class+"_top"}arrow_top=tip_h;marg_top=Math.round(top-(tip_h+5+opts.edgeOffset))}else if(bottom_compare|(t_class=="_top"&&bottom_compare)||(t_class=="_bottom"&&!top_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_bottom"}else{t_class=t_class+"_bottom"}arrow_top=-12;marg_top=Math.round(top+org_height+opts.edgeOffset)}if(t_class=="_right_top"||t_class=="_left_top"){marg_top=marg_top+5}else if(t_class=="_right_bottom"||t_class=="_left_bottom"){marg_top=marg_top-5}if(t_class=="_left_top"||t_class=="_left_bottom"){marg_left=marg_left+5}tiptip_arrow.css({"margin-left":arrow_left+"px","margin-top":arrow_top+"px"});tiptip_holder.css({"margin-left":marg_left+"px","margin-top":marg_top+"px"}).attr("class","tip"+t_class);if(timeout){clearTimeout(timeout)}timeout=setTimeout(function(){tiptip_holder.stop(true,true).fadeIn(opts.fadeIn)},opts.delay)}function deactive_tiptip(){opts.exit.call(this);if(timeout){clearTimeout(timeout)}tiptip_holder.fadeOut(opts.fadeOut)}}})}})(jQuery);

// Simulates PHP's date function
Date.prototype.format=function(format){var returnStr='';var replace=Date.replaceChars;for(var i=0;i<format.length;i++){var curChar=format.charAt(i);if(replace[curChar]){returnStr+=replace[curChar].call(this);}else{returnStr+=curChar;}}return returnStr;};Date.replaceChars={shortMonths:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],longMonths:['January','February','March','April','May','June','July','August','September','October','November','December'],shortDays:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],longDays:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],d:function(){return(this.getDate()<10?'0':'')+this.getDate();},D:function(){return Date.replaceChars.shortDays[this.getDay()];},j:function(){return this.getDate();},l:function(){return Date.replaceChars.longDays[this.getDay()];},N:function(){return this.getDay()+1;},S:function(){return(this.getDate()%10==1&&this.getDate()!=11?'st':(this.getDate()%10==2&&this.getDate()!=12?'nd':(this.getDate()%10==3&&this.getDate()!=13?'rd':'th')));},w:function(){return this.getDay();},z:function(){return"Not Yet Supported";},W:function(){return"Not Yet Supported";},F:function(){return Date.replaceChars.longMonths[this.getMonth()];},m:function(){return(this.getMonth()<9?'0':'')+(this.getMonth()+1);},M:function(){return Date.replaceChars.shortMonths[this.getMonth()];},n:function(){return this.getMonth()+1;},t:function(){return"Not Yet Supported";},L:function(){return(((this.getFullYear()%4==0)&&(this.getFullYear()%100!=0))||(this.getFullYear()%400==0))?'1':'0';},o:function(){return"Not Supported";},Y:function(){return this.getFullYear();},y:function(){return(''+this.getFullYear()).substr(2);},a:function(){return this.getHours()<12?'am':'pm';},A:function(){return this.getHours()<12?'AM':'PM';},B:function(){return"Not Yet Supported";},g:function(){return this.getHours()%12||12;},G:function(){return this.getHours();},h:function(){return((this.getHours()%12||12)<10?'0':'')+(this.getHours()%12||12);},H:function(){return(this.getHours()<10?'0':'')+this.getHours();},i:function(){return(this.getMinutes()<10?'0':'')+this.getMinutes();},s:function(){return(this.getSeconds()<10?'0':'')+this.getSeconds();},e:function(){return"Not Yet Supported";},I:function(){return"Not Supported";},O:function(){return(-this.getTimezoneOffset()<0?'-':'+')+(Math.abs(this.getTimezoneOffset()/60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()/60))+'00';},P:function(){return(-this.getTimezoneOffset()<0?'-':'+')+(Math.abs(this.getTimezoneOffset()/60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()/60))+':'+(Math.abs(this.getTimezoneOffset()%60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()%60));},T:function(){var m=this.getMonth();this.setMonth(0);var result=this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,'$1');this.setMonth(m);return result;},Z:function(){return-this.getTimezoneOffset()*60;},c:function(){return this.format("Y-m-d")+"T"+this.format("H:i:sP");},r:function(){return this.toString();},U:function(){return this.getTime()/1000;}};

