var nsx;
var nsy;
if (!document.all) {
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=get_mouse;
}
function get_mouse(e) {
	nsx=e.pageX-10;
	nsy=e.pageY+5;
}
function layer(id){
	var res
	if(document.getElementById) res=document.getElementById(id)
	if(document.all) res=document.all[id]
	if (res) return res.style
	return null
}
function t_i(id) {
	var hlp=layer(id)
	if (hlp) {
	if (document.all) {
	 nsy=event.y+document.body.scrollTop
	 nsx=event.x+document.body.scrollLeft
	}
	hlp.top=nsy+20
	hlp.left=nsx-20
	hlp.visibility='visible'
}}
function t_o(id) {
	var hlp=layer(id)
	if(hlp) hlp.visibility='hidden'
}


function createMarker2(point, message) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(message);
  });

  return marker;
}


var gcontinent; var gcountry; var gregion; var gdistrict; var gcity;

function createMarker(point, zoom_in, continent,country,region,district,city,lat,lng,z_level, span_id,city_level,map) {

	var icon = new GIcon();

	if(city_level==2)
	{
		icon.image = "images/mm_20_yellow.png";
	}
	else if(zoom_in==1)
	{
		icon.image = "images/mm_20_green.png";
	}
	else
	{
		icon.image = "images/mm_20_red.png";
	}
	icon.shadow = "images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	var marker = new GMarker(point, icon);
	if(zoom_in==1)
	{		
		GEvent.addListener(marker, "click", function() {	
			if(gcontinent==continent && gcountry==country && gregion==region && gdistrict==district && gcity==city)
			{}else{showNews(continent,country,region,district,city,0);	}
			load(continent,country,region,district,lat,lng,z_level,0,map);
			
		});
	}
	else
	{
		GEvent.addListener(marker, "click", function() {
			if(gcontinent==continent && gcountry==country && gregion==region && gdistrict==district && gcity==city){}else {showNews(continent,country,region,district,city,0);}	
		});	
	}
	GEvent.addListener(marker, "mouseover", function() {
		closeAllPopUps();
		t_i("hs"+span_id);
		
	});
	GEvent.addListener(marker, "mouseout", function() {
		closeAllPopUps();
		t_o("hs"+span_id);
	});
	return marker;
}

function loadWindow(continent,country,region,district,lat,lng,z_level,show_all) {
	window.location.href = "?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&lat="+lat+"&lng="+lng+"&z_level="+z_level;
}

var totalSpan=0
function load(continent,country,region,district,lat,lng,z_level,show_all,map) {
	try { GUnload() } catch(e) {} 
	document.getElementById("hidden_span").innerHTML ="";
	if (GBrowserIsCompatible()) {
		

		map = new GMap2(document.getElementById("map"));

		map.setCenter(new GLatLng(lat,lng), parseInt(z_level)-1);
		
		map.panBy(new GSize(-75,0)); 
		map.addControl(new GSmallMapControl());


		GDownloadUrl("http://www.headlinemap.com/location_markers.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&sid="+Math.random(), function(data) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {

				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
								parseFloat(markers[i].getAttribute("lng")));
				
				map.addOverlay(createMarker(point, markers[i].getAttribute("zoom_in"),markers[i].getAttribute("z_continent"), markers[i].getAttribute("z_country"), markers[i].getAttribute("z_region"), markers[i].getAttribute("z_district"), markers[i].getAttribute("z_city"), markers[i].getAttribute("lat"), markers[i].getAttribute("lng"), markers[i].getAttribute("z_level"),i, markers[i].getAttribute("city_level"),map));


				loadPopUp(markers[i].getAttribute("marker_title"),markers[i].getAttribute("message"),i);
			}
			totalSpan = i;
	});
	}
	showheader(continent,country,region,district,show_all);
	
}

var newsXmlHttp

var headerXmlHttp

function showNews(continent,country,region,district,city,rid)
{

	gcontinent=continent;
	gcountry=country;
	gregion=region;
	gdistrict=district;
	gcity=city;
	document.getElementById("news_scroll").innerHTML="<BR/><BR/><center><img src='images/loading.gif'/><BR><BR><B>Loading....</B></center>"
	
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	newsXmlHttp=objXMLHttp
	
	if (newsXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="news.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&city="+city+"&rid="+rid+"&sid="+Math.random()
	newsXmlHttp.onreadystatechange=newsStateChanged
	newsXmlHttp.open("GET",url,true)
	newsXmlHttp.send("")
	setTimeout('fixCopyImg()',100)
}

function fixCopyImg(){
  for (var n=0; n<document.images.length; n++)
  {   
	if(document.images[n].width>240 && document.images[n].name=="img_copy")
	{
		 document.images[n].width=240
	} 
  }
}
function showheader(continent,country,region,district,show_all)
{
	document.getElementById("header").innerHTML="&nbsp;"

	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	headerXmlHttp=objXMLHttp
	
	if (headerXmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="http://www.headlinemap.com/google/get_headers.php?continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&show_all="+show_all+"&sid="+Math.random()
	headerXmlHttp.onreadystatechange=headerStateChanged
	headerXmlHttp.open("GET",url,true)
	headerXmlHttp.send("")
}

function loadPopUp(title,message, id)
{
	if(message.length==0)
	{
		message = "<small>"+message+"</small>";
	}
	var temp = document.getElementById("hidden_span").innerHTML;
	document.getElementById("hidden_span").innerHTML=temp+"<span id='hs"+id+"' class='hide'><B>"+title+"</B><br>"+message+"</span>";
}

function closeAllPopUps()
{
	for (var i = 0; i < totalSpan; i++) {
		t_o("hs"+i);
	}

}

function newsStateChanged()
{
	if (newsXmlHttp.readyState==4 || newsXmlHttp.readyState=="complete")
	{
		document.getElementById("news_block").innerHTML=newsXmlHttp.responseText
	}
}

function headerStateChanged()
{
	if (headerXmlHttp.readyState==4 || headerXmlHttp.readyState=="complete")
	{
		document.getElementById("header").innerHTML=headerXmlHttp.responseText
	}
}

function hide()
{
  var ns6=document.getElementById&&!document.all
    
  if(document.getElementById("news_scroll").style.visibility == 'hidden')
  {
	document.getElementById("news_scroll").style.visibility='visible';
	document.getElementById("news_scroll").style.position='static';


	document.getElementById("news_scroll").style.zIndex = 98;
	if(ns6)document.getElementById("news_scroll_img").innerHTML='<img src="images/open.gif" border=0>'
	{
		if(document.all){
			news_scroll_img.innerHTML='<img src="images/close.gif" border=0>'
		}
	}
  }
  else
  {
	document.getElementById("news_scroll").style.visibility='hidden';
	document.getElementById("news_scroll").style.position='absolute';
	if(ns6)document.getElementById("news_scroll_img").innerHTML='<img src="images/close.gif" border=0>'
	{
		if(document.all){
			news_scroll_img.innerHTML='<img src="images/open.gif" border=0>'
		}
	}
  }
}

function sources()
{
  var ns6=document.getElementById&&!document.all
  
 if(document.getElementById("sources").style.visibility=='')
 {
	document.getElementById("sources").style.visibility='hidden';	
 }
 
  
  document.getElementById("sources").style.zIndex = 99;
  if(document.getElementById("sources").style.visibility == 'hidden')
  {
	document.getElementById("sources").style.visibility='visible';
	document.getElementById("sources").style.position='static';
  }
  else
  {
	document.getElementById("sources").style.visibility='hidden';
	document.getElementById("sources").style.position='absolute';
  }
}

function hmap(width,height,continent,country,region,district,city,lat,lng,z_level)
{
document.getElementById("news_frame").innerHTML="<iframe marginheight='0' marginwidth='0' height='"+height+"' src='http://www.headlinemap.com/google/index.php?width="+width+"&height="+height+"&continent="+continent+"&country="+country+"&region="+region+"&district="+district+"&city="+city+"&lat="+lat+"&lng="+lng+"&z_level="+z_level+"' align='top' frameborder='0' width='100%' scrolling='no'></iframe>"
}
