/**
 * @package WordPress
 * @subpackage Sedermera
 */

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

	convertEmails();
	resizeFooter(145, $);

	$("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()

});

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');
}
