/**
 * @package WordPress
 * @subpackage Företagsnamn
 */

jQuery(document).ready(function($) {

	convertEmails();
	resizeFooter(60, $);

	$("A[rel='external']").attr("target", "_blank"); // Sätter target="_blank" för rel="external"
	$("A").focus(function(){ $(this).blur(); }); // Sätter blur() på alla länkar vid focus()
	
	$("#mainMenu LI").each(function(){
		if(location.href.indexOf(jQuery("A", this).attr("href")) != -1 && location.pathname != "/" && jQuery("A", this).attr("href") != "http://"+ location.hostname + "/") {
			if(! icl_lang || jQuery("A", this).attr("href") != icl_home) $(this).addClass("current-menu-item");
		}
	});
	
});

	 

function convertEmails(){
	var spans = document.getElementsByTagName("span");
	var numSpans = spans.length;
	for(var i = 0; i < numSpans; i++){
		if(spans[i] && spans[i].className == "epost"){
			var at = new RegExp("\\(snabel\-a\\)", "i");
			var punkt = new RegExp("\\(punkt\\)", "ig");
			var contact = spans[i].firstChild.data.split("|");

			if (contact.length == 2) {
				var address = contact[1].replace(at, "@").replace(punkt, ".");
               	var theLink = document.createElement("A");
               	theLink.setAttribute("href", "mailto:" + address);
               	theLink.className = "email";
               	theLink.appendChild(document.createTextNode(contact[0]));
               	spans[i].replaceChild(theLink, spans[i].firstChild);
			}
			else {
				var address = spans[i].firstChild.data.replace(at, "@").replace(punkt, ".");
				var theLink = document.createElement("A");
				theLink.setAttribute("href", "mailto:" + address);
				theLink.className = "email";
				theLink.appendChild(document.createTextNode(address));
				spans[i].replaceChild(theLink, spans[i].firstChild);
			}
		}
	}
}

function resizeFooter(minHeight, $){
	window.onresize = function() { resizeFooter(minHeight, $); }
	var newHeight = document.body.offsetHeight - $("#top").height() - $("#main").height();
	if(newHeight < minHeight) newHeight = minHeight;
	$("#bottom").css("height", newHeight + 'px');
}
