if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
	var len = this.length;
	if (typeof fun != "function")
	  throw new TypeError();

	var thisp = arguments[1];
	for (var i = 0; i < len; i++)
	{
	  if (i in this)
		fun.call(thisp, this[i], i, this);
	}
  };
}

	
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = document.referrer.slice(document.referrer.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];
  }
});

function highlightItem(element, index, array) {
  $('#wrap').highlight(element);
}

$(document).ready(function () {

	var index = document.referrer.indexOf('.google.');
	if (index > 0 && index < 15)
	{
		var byName = $.getUrlVar('q');
		$("input[name=q]").val(decodeURIComponent(byName.replace(/\+/g, " ")));
		decodeURIComponent(decodeURIComponent(byName.replace(/\+/g, " "))).split(" ").forEach(highlightItem);
		$('#wrap').append("<a id='aremoveHighlight' style='bottom: 10px; right: 10px; position: fixed;' title='usuń zaznaczenie'><img src='http://www.wlosy.praktyczne.info.pl/images/highlightIcon.gif' alt='usuń zaznaczenie'/></a>");
		$('#aremoveHighlight').click(function() {
			$('#wrap').removeHighlight(); $('#aremoveHighlight').remove();
		});
		$('#aremoveHighlight').css('cursor', 'pointer');
	}
});



//$('#wrap').removeHighlight();
