/*	jquery-wtplugins.js	*/
/*	Misc jQuery plug-in functions for Woodford Theater	*/
/*	Created: 2011-10-13	*/
/*	© 2011 Woodford County Theater & RLK Marketing; All rights reserved.	*/

//	Create name/value object from deisgnated inputs
$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
//    	if (parseFloat(this.value) != "NaN") this.value = parseFloat (this.value);
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

$.fn.exists = function() {
	return jQuery( this ).length > 0;
};


$.fn.htmlEscape = function () {
	return this.replace(/&/g, '&amp;')
		.replace(/</g, '&lt;')
		.replace(/>/g, '&gt;')
		.replace(/'/g, '&#039;')
		.replace(/"/g, '&quot;')
		.replace(/\n/g, '<br />');
};

$.extend({
	getPathArgs: function(){
  	if (window.location.href.indexOf('?') != -1) {
	    var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1].replace ('#', '');
		}
		return vars;
	} else {
		return false;
	}
  },
  getPathArg: function(name){
    return $.getPathArgs()[name];
  }
});
