window.log = function() {
	log.history = log.history || [];
	// store logs to an array for reference
	log.history.push(arguments);
	arguments.callee = arguments.callee.caller;
	if(this.console)
		console.log(Array.prototype.slice.call(arguments));
}; (function(b) {
	function c() {
	}

	for(var d = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), a; a = d.pop(); )
	b[a] = b[a] || c
})(window.console = window.console || {});

/**
 * CoolInput Plugin
 *
 * @version 1.5 (10/09/2009)
 * @requires jQuery v1.2.6+
 * @author Alex Weber <alexweber.com.br>
 * @author Evan Winslow <ewinslow@cs.stanford.edu> (v1.5)
 * @copyright Copyright (c) 2008-2009, Alex Weber
 * @see http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
 *
 * Distributed under the terms of the GNU General Public License
 * http://www.gnu.org/licenses/gpl-3.0.html
 */
;(function($) {
	$.fn.coolinput = function(b) {
		var c = {
			hint : null,
			source : "title",
			blurClass : "blur",
			iconClass : false,
			clearOnSubmit : true,
			clearOnFocus : true,
			persistent : true
		};
		if(b && typeof b == "object")
			$.extend(c, b);
		else
			c.hint = b;
		return this.each(function() {
			var d = $(this);
			var e = c.hint || d.attr(c.source);
			var f = c.blurClass;
			function g() {
				if(d.val() == "")
					d.val(e).addClass(f)
			}

			function h() {
				if(d.val() == e && d.hasClass(f))
					d.val("").removeClass(f)
			}

			if(e) {
				if(c.persistent)
					d.blur(g);
				if(c.clearOnFocus)
					d.focus(h);
				if(c.clearOnSubmit)
					d.parents("form:first").submit(h);
				if(c.iconClass)
					d.addClass(c.iconClass);
				g()
			}
		})
	}
})(jQuery);

jQuery.callback = function(o, m) {

	if(arguments.length > 2) {
		var args = Array.prototype.slice.call(arguments, 2);
		return function() {
			return m.apply(o, args);
		};
	}

	return function() {
		return m.apply(o, arguments);
	};
};

jQuery.parseQuery = function(qs, options) {
	var q = ( typeof qs === 'string' ? qs : window.location.search), o = {
		'f' : function(v) {
			return unescape(v).replace(/\+/g, ' ');
		}
	}, options = ( typeof qs === 'object' && typeof options === 'undefined') ? qs : options, o = jQuery.extend({}, o, options), params = {};
	jQuery.each(q.match(/^\??(.*)$/)[1].split('&'), function(i, p) {
		p = p.split('=');
		p[1] = o.f(p[1]);
		params[p[0]] = params[p[0]] ? ((params[p[0]] instanceof Array) ? (params[p[0]].push(p[1]), params[p[0]]) : [params[p[0]], p[1]]) : p[1];
	});
	return params;
}
//##############################
// jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms
// By Dharmavirsinh Jhala - dharmavir@gmail.com
// Date of Release: 13th March 10
// Version: 0.8
/*
 USAGE:
 $(document).ready(function(){
 $(":radio").behaveLikeCheckbox();
 }
 */

var elmHeight = "25";
// should be specified based on image size

// Extend JQuery Functionality For Custom Radio Button Functionality
jQuery.fn.extend({
	dgStyle : function() {
		// Initialize with initial load time control state
		$.each($(this), function() {
			var elm = $(this).children().get(0);
			elmType = $(elm).attr("type");
			$(this).data('type', elmType);
			$(this).data('checked', $(elm).attr("checked"));
			$(this).dgClear();
		});
		$(this).mousedown(function() {
			$(this).dgEffect();
		});
		//$(this).mouseup(function() { $(this).dgHandle(); });
	},
	dgClear : function() {
		if($(this).data("checked") == true) {
			$(this).css("backgroundPosition", "center -" + (elmHeight * 2) + "px");
		} else {
			$(this).css("backgroundPosition", "center 0");
		}
	},
	dgEffect : function() {
		if($(this).data("checked") == true)
			return;
		//$(this).css({backgroundPosition:"center -"+(elmHeight*3)+"px"});
		else {
			$(this).css({
				backgroundPosition : "center -" + (elmHeight) + "px"
			});
			$(this).dgHandle();
		}
	},
	dgHandle : function() {
		var elm = $(this).children().get(0);
		if($(this).data("checked") == true)
			return;
		//$(elm).dgUncheck(this);
		else
			$(elm).dgCheck(this);

		if($(this).data('type') == 'radio') {
			$.each($("input[name='" + $(elm).attr("name") + "']"), function() {
				if(elm != this)
					$(this).dgUncheck(-1);
			});
		}
	},
	dgCheck : function(div) {
		$(this).attr("checked", true);
		if(div != -1)
			$(div).data('checked', true).css({
				backgroundPosition : "center -" + (elmHeight * 2) + "px"
			});
		else
			$(this).parent().data('checked', true).css({
				backgroundPosition : "center -" + (elmHeight * 2) + "px"
			});

		//$(div).data('checked',true).css({backgroundPosition:"center -"+(elmHeight*2)+"px"});
	},
	dgUncheck : function(div) {
		$(this).attr("checked", false);
		if(div != -1)
			$(div).data('checked', false).css({
				backgroundPosition : "center 0"
			});
		else
			$(this).parent().data("checked", false).css({
				backgroundPosition : "center 0"
			});
	}
});

// -----------------------------------------------------------------------
// Eros Fratini - eros@recoding.it
// jqprint 0.3
//
// - 19/06/2009 - some new implementations, added Opera support
// - 11/05/2009 - first sketch
//
// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea
// requires jQuery 1.3.x
//
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
//------------------------------------------------------------------------

(function($) {
	var opt;

	$.fn.jqprint = function(options) {
		opt = $.extend({}, $.fn.jqprint.defaults, options);

		var $element = (this instanceof jQuery) ? this : $(this);

		if(opt.operaSupport && $.browser.opera) {
			var tab = window.open("", "jqPrint-preview");
			tab.document.open();

			var doc = tab.document;
		} else {
			var $iframe = $("<iframe  />");

			if(!opt.debug) {
				$iframe.css({
					position : "absolute",
					width : "0px",
					height : "0px",
					left : "-600px",
					top : "-600px"
				});
			}

			$iframe.appendTo("body");
			var doc = $iframe[0].contentWindow.document;
		}

		if(opt.importCSS) {
			if($("link[media=print]").length > 0) {
				$("link[media=print]").each(function() {
					doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
				});
			} else {
				$("link").each(function() {
					doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
				});
			}
		}

		if(opt.printContainer) {
			doc.write($element.outer());
		} else {
			$element.each(function() {
				doc.write($(this).html());
			});
		}

		doc.close();

		(opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
		setTimeout(function() {
			(opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print();
			if(tab) {
				tab.close();
			}
		}, 1000);
	}

	$.fn.jqprint.defaults = {
		debug : false,
		importCSS : true,
		printContainer : true,
		operaSupport : true
	};

	// Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
	jQuery.fn.outer = function() {
		return $($('<div></div>').html(this.clone())).html();
	}
})(jQuery);

var BrowserDetect = {
	init : function() {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString : function(data) {
		for(var i = 0; i < data.length; i++) {
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if(dataString) {
				if(dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			} else if(dataProp)
				return data[i].identity;
		}
	},
	searchVersion : function(dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if(index == -1)
			return;
		return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
	},
	dataBrowser : [{
		string : navigator.userAgent,
		subString : "Chrome",
		identity : "Chrome"
	}, {
		string : navigator.userAgent,
		subString : "OmniWeb",
		versionSearch : "OmniWeb/",
		identity : "OmniWeb"
	}, {
		string : navigator.vendor,
		subString : "Apple",
		identity : "Safari",
		versionSearch : "Version"
	}, {
		prop : window.opera,
		identity : "Opera",
		versionSearch : "Version"
	}, {
		string : navigator.vendor,
		subString : "iCab",
		identity : "iCab"
	}, {
		string : navigator.vendor,
		subString : "KDE",
		identity : "Konqueror"
	}, {
		string : navigator.userAgent,
		subString : "Firefox",
		identity : "Firefox"
	}, {
		string : navigator.vendor,
		subString : "Camino",
		identity : "Camino"
	}, {// for newer Netscapes (6+)
		string : navigator.userAgent,
		subString : "Netscape",
		identity : "Netscape"
	}, {
		string : navigator.userAgent,
		subString : "MSIE",
		identity : "Explorer",
		versionSearch : "MSIE"
	}, {
		string : navigator.userAgent,
		subString : "Gecko",
		identity : "Mozilla",
		versionSearch : "rv"
	}, {// for older Netscapes (4-)
		string : navigator.userAgent,
		subString : "Mozilla",
		identity : "Netscape",
		versionSearch : "Mozilla"
	}],
	dataOS : [{
		string : navigator.platform,
		subString : "Win",
		identity : "Windows"
	}, {
		string : navigator.platform,
		subString : "Mac",
		identity : "Mac"
	}, {
		string : navigator.userAgent,
		subString : "iPhone",
		identity : "iPhone/iPod"
	}, {
		string : navigator.platform,
		subString : "Linux",
		identity : "Linux"
	}]

};
BrowserDetect.init();

function reloadImages() {
	$("img").each(function(i) {

		var src = $(this).attr("src");
		$(this).attr("src", $(this).attr("src").replace("/templates", ""));

		log($(this).attr("src"), src);
	});
};
