function urlencode( str ) {
	// http://kevin.vanzonneveld.net
	// +   original by: Philip Peterson
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: AJ
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Brett Zamir
	// %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
	// *     example 1: urlencode('Kevin van Zonneveld!');
	// *     returns 1: 'Kevin+van+Zonneveld%21'
	// *     example 2: urlencode('http://kevin.vanzonneveld.net/');
	// *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
	// *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
	// *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

	var histogram = {}, tmp_arr = [];
	var ret = str.toString();

	var replacer = function(search, replace, str) {
		var tmp_arr = [];
		tmp_arr = str.split(search);
		return tmp_arr.join(replace);
	};

	// The histogram is identical to the one in urldecode.
	histogram["'"]   = '%27';
	histogram['(']   = '%28';
	histogram[')']   = '%29';
	histogram['*']   = '%2A';
	histogram['~']   = '%7E';
	histogram['!']   = '%21';
	histogram['%20'] = '+';

	// Begin with encodeURIComponent, which most resembles PHP's encoding functions
	ret = encodeURIComponent(ret);

	for (var search in histogram) {
		replace = histogram[search];
		ret = replacer(search, replace, ret) // Custom replace. No regexing
	}

	// Uppercase for full PHP compatibility
	return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
		return "%"+m2.toUpperCase();
	});

	return ret;
}

// change font size
alterFontSize = function(direction){
	var getCurrentSize = parseFloat($('body').css('font-size'));
	(( direction == 'larger' ) ? getCurrentSize++ : getCurrentSize--)+"px";
	$('body').css('font-size',getCurrentSize);
	return false;
}

// Define indexOf for IE
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

function showFlashMessage(message)
{
	$("#notifications").slideDown(250, function()
	{
		var sTmOut = setTimeout(hideFlashMessage, 5000);
		$("#message").html(message).fadeIn('slow');
	});
}
function hideFlashMessage()
{
	clearTimeout();
	$("#message").fadeOut(250, function(){
		$("#notifications").slideUp(250, function(){
			$("#message").html("");
		});
	});
}


$(document).ready(function(){
	//$(".thickbox").lightBox({fixedNavigation:true});
	//tb_init(".tb");
	//$('#mycarousel').jcarousel();
	$(".delete").click(function(){
		conf = confirm("Are you sure?");
		if(!conf) {
			return false;
		}
	});
	$(".sub_but").click(function(){
      $.get(APP_DIR+"ajax/join/?name="+$("#sub_name").val()+"&email="+$("#sub_mail").val(), function(data){
		showFlashMessage(data);
		$("#sub_name").val("")
		$("#sub_mail").val("")
      });
	  return false;
	});
	$("a.submit").click(function(){
		$(this).parents("form").submit();
		return false;
	});
	$(".subcomm").click(function(){
		if(!$("#comment-area").val()) {
			showFlashMessage("Comment field is required!");
			return false;
		}
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: true, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){} /* Called when prettyPhoto is closed */
	});

	$(".search_but").click(function(){
		window.location = $(this).attr("href")+"/"+$("#keyword").val();
		return false;
	});
});
