
OpenLayers.GoogleMarker = OpenLayers.Class.create();
OpenLayers.GoogleMarker.prototype = {    
    point: null,      
    /** @type GoogleMap.Map */
     map: null,
     
     marker:null,
     name:null,
    
    oid:null,
    
    initialize: function(map,values) {
      this.map = map;
    	
  		var oid = values[0];
  		var imgurl="img/marker.png";
  		if(values[2]!="")
  	    imgurl = "img/"+values[2]+".png";  		
  		var lonlat = new GLatLng(values[4],values[3]);  	  	
    	this.point = lonlat;
    	this.name = values[1];
      this.marker = this.createMarker(lonlat,imgurl);
      this.oid=oid;  
                       
		
        
    },   
    
  	createMarker:function(lonlat,aurl)  
  	{
  		var baseIcon = new GIcon();
			baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			baseIcon.iconSize = new GSize(21, 25);
			baseIcon.shadowSize = new GSize(24, 28);
			baseIcon.iconAnchor = new GPoint(9, 28);
			baseIcon.infoWindowAnchor = new GPoint(9, 2);
			baseIcon.infoShadowAnchor = new GPoint(18, 25);
			//baseIcon.image = aurl;
			
		/*	var baseIcon = new GIcon();
        baseIcon.image = aurl;
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(12, 20);
        baseIcon.shadowSize = new GSize(22, 20);
        baseIcon.iconAnchor = new GPoint(6, 20);
        baseIcon.infoWindowAnchor = new GPoint(5, 1);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);*/
	
			var icn = new GIcon(baseIcon);	  	
			  icn.image = aurl;
	  	//this.marker = new GMarker(lonlat,{icon:icn,title:this.name},false);
	  	this.marker = new GMarker(lonlat,icn,false);
	  	//this.marker = createMarker(lonlat,aurl);
	  	GEvent.bind(this.marker, "click", this, this.onMarkerClick);
	  //	var marker = new GMarker(point, icn);
	  	
			return this.marker;

  	},
  	
  	onMarkerClick:function()
  	{
  		//alert(this.name);
  		var url= "minlang=ct&action=CustomPOI&id="+this.oid;
  		OpenLayers.loadURL("fetch_data.php",encodeURI(url),this,function(response){
  		//	GDownloadUrl(url, function(data, responseCode,this) {
  		if (response.readyState==4)
	{
		if (response.status==200)
		{
  			var responseTxt=response.responseText.toString();
				para=responseTxt.split("\t");
				var titlePara=new Array();
				var tempPara=new Array();
				arrLength=para.length;
				
				for(i=0,j=0,z=0;i<arrLength-4;i++)
				{
					if(i%2==0)
					{
						titlePara[j]=para[i];
						j++;
					}
					else
					{
						tempPara[z]=para[i];
						z++;
					}
				}
				var power=para[arrLength-1];
				//detailShow(this.ID,"CustomPOI",titlePara,tempPara,this.LonLat,power);
				var div = this.getContent(titlePara,tempPara);
				
				this.marker.openInfoWindowHtml(div);		
	  	}}
	  		});
  		
  		
  	},
  	
  	getContent:function(titlePara,para)
  	{
        
		var innerDiv=document.createElement("DIV");
		innerDiv.style.width="310px";
		innerDiv.style.whiteSpace="normal";
		var tempPara=para;		  
		var fontStyle="";
		fontStyle="MingLiu,Arial, Helvetica, sans-serif";
		tempStr="<br><b style='font-family:"+fontStyle+"'>"+tempPara[0]+"</b>";
		if(tempPara[1]!="")
		{
			tempStr=tempStr+"<br />"+tempPara[1]+"<br />";
		}
		if(tempPara[2]!="")
		{
			tempStr=tempStr+"<br />";
			dis=tempPara[2].split(",");
			if(dis[1]!=""&&dis[0]!="")
			{
				tempStr=tempStr+dis[0]+", "+dis[1];	
			}
			else
			{
				if(dis[0]!="")
				{
					tempStr=tempStr+dis[0];	
				}
				else
				{
					if(dis[1]!="")
					{
						tempStr=tempStr+dis[1];	
					}
				}
			}
		}
		if(tempPara[3]!="")
		{
			tempStr=tempStr+""+tempPara[3]+"<br />";
		}
		for(i=4,j=0;i<tempPara.length;i++)
		{
			//alert(poiParaName[i]+":"+paraArray[i]);
			if(tempPara[i]!="")
			{
				if(j==0)
				{
					//tempStr=tempStr+"<br>";
					j++;													   
				}
				if(titlePara[i]=="photo"){
					tempStr='<br/><img style="float:right;" width="200" height="150" src="img/ad/'+tempPara[i]+' "/>'+tempStr;
				}
				//else if (titlePara[i]=="Web Site")
				else if(i==7)
				{
					tempStr=tempStr+'<br />'+titlePara[i]+': <a  target="_blank" href="'+tempPara[i]+'">'+tempPara[i]+'</a>';	
				}
				//else if(titlePara[i]=="email")
				else if(i==8)
				{
					tempStr=tempStr+'<br />'+titlePara[i]+': <a  href="mailto:'+tempPara[i]+'">'+tempPara[i]+'</a>';	
				}
				else{
					tempStr=tempStr+"<br />"+titlePara[i]+": "+tempPara[i];	
				}
			}
		}
		
		innerDiv.innerHTML=tempStr;
		
		return innerDiv;
  	}
  	

};


    


