var t2;

var retinalogopath = '';
var retinalogobasename = '';

function fixMap() {
	clearInterval(t2);
	// Timer needed since Adapt.js fires with a timer set to 100ms
	t2 = setInterval(getProperMap, 200);
}


function hasRetina() {
	var retina = window.devicePixelRatio > 1 ? true : false;
	return retina;
}

function getProperMap() {
	clearInterval(t2);
	
	var geoloc = '62.39058,17.318482';
	
	var linkurl = 'http://maps.google.se/maps/place?q=design+by+jan&hl=sv&cid=11319175258029213524';

	// Retina display?
	var retina = hasRetina();
	
	var urlbase = 'http://maps.googleapis.com/maps/api/staticmap?center=';
	var urlrest = '&zoom=14&sensor=false&size=';
	var urltail = '&markers=color:red|label:A|';
	
	var width = document.getElementById('contact-info').offsetWidth;
	width = Math.round(width - (width / 100) * 10);
	var height = width - Math.round(width / 4);
	
	var showheight = height;
	var showwidth = width;
	// Handle higher device pixel ratios (iPhone 4 has 2, Nexus S has 1.5)
	if (retina) {
		var multiplier = window.devicePixelRatio;
		width = width * multiplier;
		height = height * multiplier;
	}
	var size = width + 'x' + height;
	document.getElementById('mapDiv').innerHTML = '<a href="'+linkurl+'" target="_blank" rel="me"><img width="'+showwidth+'" height="'+showheight+'" style="width: '+showwidth+'px; height: '+showheight+'px;" src="'+urlbase+geoloc+urlrest+size+urltail+geoloc+'" alt="Map" /></a>';
}

// function retinaLogoimage(filepath, basename, filetype) {
//	var divObject = document.getElementById('logoimage');

//	var showwidth = objWidth;
//	if (hasRetina()) {
//		var multiplier = window.devicePixelRatio;
//		objWidth = objWidth * multiplier;
//	}
//	var newHTML = '<img src="'.filepath.'/'.basename.'_'.objWidth.'.'.filetype.'" width="'.showwidth.'" alt="Site logo">';
//	
//}

// External functions

// addEvent, written by Scott Andrew
// Source: http://www.scottandrew.com/weblog/articles/cbs-events
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

// Calls to functions on script load

addEvent(window, 'load', fixMap);
addEvent(window, 'resize', fixMap);

addEvent(window, 'load', retinaLogoimage);
