
	//<![CDATA[

 	// these must be passed


	var MeccaLat = 21.43261686447735
	var MeccaLon = 39.814453125;
	var compassWidth = 160;
	var compassHeight = 160;
	var decimals = 8;
	var angleDecimals = 0;
	var angleStr = "";
	var arrowColor = "#F8641D";

	// read cookie
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
		}
		return null;
	}

	// Init Home
	function InitHome() {
		// read the cookies
		strLat = readCookie('ptlat');
		strLon = readCookie('ptlon');
		if (strLat && strLon) {
			HomeLat = parseFloat(strLat);
			HomeLon = parseFloat(strLon);
		}
	}

// On Compass
	function getDirectionForCompass(P1_lon, P1_lat, P2_lon, P2_lat) {
		P1_x = -1*P1_lon*Math.PI/180;
		P1_y = P1_lat*Math.PI/180; // to remove the zero
		P2_x = -1*P2_lon*Math.PI/180;
		P2_y = P2_lat*Math.PI/180; // to remove the zero
		
		var difflong = P1_x - P2_x;
		direction = ((180/Math.PI) * Math.atan2( Math.sin(difflong), Math.cos(P1_y) * Math.tan(P2_y) - Math.sin(P1_y) * Math.cos(difflong)));
		if (direction < 0)
			direction = 360 + direction;
		return direction.toFixed(decimals);
	}

	function drawOnCompass(jg, x, y, angle) {
		jg.clear();
		jg.paint();
		g = -angle*(Math.PI/180);
		d = Math.max(compassWidth/2.0, compassHeight/2.0);
		x2 = x-((d)*Math.sin(g));
		y2 = y-((d)*Math.cos(g));
		jg.setColor(arrowColor);
		jg.setStroke(1);
		jg.drawLine(x, y, x2, y2); // co-ordinates related to "GheblehCanvas"
//		jg.setColor("#005F00"); // dark green
//		jg.setStroke(3);
//		jg.drawLine(x, y, x2, y2); // co-ordinates related to "GheblehCanvas"

		// the head of the arrow
		x3 = x2+((0.05*d)*Math.sin(g));
		y3 = y2+((0.05*d)*Math.cos(g));
		x4 = x2+((0.1*d)*Math.sin(g));
		y4 = y2+((0.1*d)*Math.cos(g));
		x5 = x2+((0.15*d)*Math.sin(g));
		y5 = y2+((0.15*d)*Math.cos(g));
		x6 = x2+((0.2*d)*Math.sin(g));
		y6 = y2+((0.2*d)*Math.cos(g));
		jg.setColor(arrowColor);
		jg.setStroke(2);
		jg.drawLine(x2, y2, x3, y3); // co-ordinates related to "GheblehCanvas"
		jg.setStroke(3);
		jg.drawLine(x3, y3, x4, y4); // co-ordinates related to "GheblehCanvas"
		jg.setStroke(4);
		jg.drawLine(x4, y4, x5, y5); // co-ordinates related to "GheblehCanvas"
		jg.setStroke(5);
		jg.drawLine(x5, y5, x6, y6); // co-ordinates related to "GheblehCanvas"

		jg.paint();
	}



	function showGheblehOnCompass() {
		var jg = new jsGraphics("CompassCanvas");
		dir = getDirectionForCompass(HomeLon, HomeLat, MeccaLon, MeccaLat);
		off = 2;
		drawOnCompass(jg, compassHeight/2.0 + off, compassWidth/2.0 - off, dir);
		
	}

	document.write('<div id="CompassCanvas" style="position:relative;height:160px;width:160;">');
	document.write('<img src="CompassBG1.png"/>');
	document.write('</div>');
	InitHome();
	showGheblehOnCompass();
	
    //]]>
