function relay( url ) {
	window.location = url;
}

ilog = function( variable ) {
	if( console == undefined || empty(console) )  alert(variable);
	else console.log(variable);
}

posti = function( name, dom, ext, sub ) {
	if ( !sub ) sub = '';
	window.location = 'mailto:'+name+'@'+dom+'.'+ext+'?subject='+sub;
}

webSafe = function( inputString ) {	
  	return inputString.toLowerCase().replace(/ /g, "-").replace(/å|ä/g, "a").replace(/ö/g, "o").replace(/^a-zA-Z0-9\-_/g, "");
}

function empty (mixed_var) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philippe Baumann
    // +      input by: Onno Marsman
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: LH
    // +   improved by: Onno Marsman
    // +   improved by: Francesco
    // +   improved by: Marc Jansen
    // +   input by: Stoyan Kyosev (http://www.svest.org/)
    // *     example 1: empty(null);
    // *     returns 1: true
    // *     example 2: empty(undefined);
    // *     returns 2: true  
    // *     example 3: empty([]);
    // *     returns 3: true
    // *     example 4: empty({});
    // *     returns 4: true
    // *     example 5: empty({'aFunc' : function () { alert('humpty'); } });
    // *     returns 5: false

    var key;

    if (mixed_var === "" ||
        mixed_var === 0 ||
        mixed_var === "0" ||
        mixed_var === null ||
        mixed_var === false ||
        typeof mixed_var === 'undefined'
    ){
        return true;
    }

    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }

    return false;
}

function urlParam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


(function($) {
$.fn.KivaLoader = function(o) {	
  	
  	this.$el = $(this);
  	
  	var defaults = {
  		id: 'loader_'+this.$el.attr('id'),
  		text: '',
  		indicator: 'spinner.gif',
  		method: 'after'
  	}
  	
	var conf = $.extend(defaults, o);

  	var loaderHtml = 
  		'<span id="'+conf.id+'" class="iCmsLoader">'+
  		'	<img src="/static/img/loaders/'+conf.indicator+'"/>'+
  		'	'+conf.text+
  		'</span>';
  	
  	this.$el.each(function() {
		
		switch(conf.method) {
			case 'append': 
				$(this).append(loaderHtml);	
			break;
			case 'after': 
				$(this).after(loaderHtml);	
			break;
			case 'before': 
				$(this).before(loaderHtml);	
			break;
			case 'html': 
			default:
				$(this).empty();
				$(this).html(loaderHtml);	
			break;	
		}
		
  	});  	
  
  	return $('#'+conf.id);
  	
  }
})(jQuery);

$.extend({
  getUrlVars: function(){
    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];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
