﻿Namespace.register("How2go.MapView");
How2go.MapView=
{
		  
		 Tests:function()
		 {
			//alert('a');	 
		}
		,
        CallFunction:''
		,
	CallBack: function(callBack) {    
        if(typeof callBack!="object"){callBack={};}
            this.callBack = {
            oncomplate:callBack.oncomplate||function(){}
            }
        }
		,
        Load:function(map,callBack)
        {	
			if (typeof(window.frames[map])!='undefined' && typeof(window.frames[map].How2go) !='undefined'
																				
			&& typeof(window.frames[map].How2go.MapPoi) !='undefined'
			&& typeof(window.frames[map].How2go.MapPoi.style) !='undefined'
			&& parseInt(window.frames[map].How2go.Width)!=0
			)
			{
				How2go.MapView.CallFunction=callBack; 
            	How2go.MapView.CallBack(callBack); 
				if(typeof How2go.MapView.CallFunction!="undefined")
                {
                    How2go.MapView.CallFunction.oncomplate();  
				}
			}
			else
			{
				setTimeout(function(){How2go.MapView.Load(map,callBack);},50);	
			}
		}
		,
		Keydown:function()
		{
			alert('ddd');
			}
	,
	JS:''
	,
    Create:function(id,iframeName,city,time,slider,tlight,contextmenu,item)
    {
		//How2go.MapView.Load('map',{oncomplate:function(){How2go.MapView.Tests();}});	
		
        var layer=How2go.$(id);
            if (null!=layer)
            {
                parentNode=layer.parentNode;
                if (null!=parentNode)
                {
                     var h=parseInt(parentNode.offsetHeight);
                    var w=parseInt(parentNode.offsetWidth);
                     h=h-2;
                        w=w-2;
                    
                  //  document.body.innerHTML +="<noscript><iframe scr=\"*.htm\"></iframe></noscript>";
                    
                  //  var noscript=document.createElement("iframe");
						//noscript.innerHTML="<iframe scr=\"*.htm\"></iframe>";
						//noscript.src="*.htm";
					//	document.appendChild(noscript); 
						
						
                   //var  js=document.createElement("script");
					//	js.src=How2go.Path+"/JScript/How2go.Tabs.js";
					//	document.body.appendChild(js); 
						
                    
                    
                    layer.innerHTML = "<noscript><iframe scr=\"*.htm\"></iframe></noscript><iframe unselectable=\"on\" style=\"border-style:none;z-index:88888888;margin:0px; padding:0px;width:"+(w)+"px;height:"+(h)+"px;\" id=\""+iframeName+"\" name=\""+iframeName+"\" src=\"about:blank\"  frameborder=\"0\" scroll=\"no\"></iframe>";                            
                    var map=window.frames[iframeName];
                    map.document.open();                    
                    map.document.writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                    if (How2go.IE)
                    {
                        //<html xmlns:v="urn:schemas-microsoft-com:vml">
                    map.document.writeln("<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><style>v\\:*{behavior:url(#default#VML);}</style>");
					
						map.document.onkeydown=function()
						{
							if(map.event.ctrlKey   &&   map.event.keyCode   ==   78)   {   
          						map.event.returnValue   =   false;   
  							}   
						}
                    }
                    else
                    {
                        map.document.writeln("<html>");
						
						map.document.onkeydown=function(event)
						{
							//alert('ddddddd');
							if(event.ctrlKey   &&   event.keyCode   ==   78)   { 
								event.preventDefault();
								//alert('ddd');
          						//event.returnValue   =   false;   
  							}   
						}
                   // map.document.addEventListener("keydown",How2go.MapView.Keydown,false); 
						
						
                    }
                    map.document.writeln("<head><link href=\""+How2go.Path+"/Style/MStyle.css\" type=\"text/css\" rel=\"stylesheet\" />");
                    map.document.writeln("<title>实时路况 看路况 就上How2go</title></head><body style=\"overflow:hidden\" unselectable=\"on\" scroll=\"no\" ></body></html>");                    
    		        map.document.close();
                    map.document.charset="utf-8";
                    //var language=new Dongwin.Language.Editor();
                    var js=map.document.createElement("script");
                    js.src=this.JS;
                   // js.src=How2go.Path+"/JScript/How2go.Map.js";
                    map.document.body.appendChild(js); 
                    
                   // js=map.document.createElement("script");
//                    js.src=How2go.Path+"/JScript/How2go.Mouse.js";
//                    map.document.body.appendChild(js); 
					
					//if (slider)
					{
						js=map.document.createElement("script");
						js.src=How2go.Path+"/JScript/How2go.Slider.js";
						map.document.body.appendChild(js); 
					}
					//if (item)
					{
						js=map.document.createElement("script");
						js.src=How2go.Path+"/JScript/How2go.Items.js";
						map.document.body.appendChild(js); 
						
					}
					//if (contextmenu)
					{
						js=map.document.createElement("script");
						js.src=How2go.Path+"/JScript/How2go.Contextmenu.js";
						map.document.body.appendChild(js); 
					}
                    js=map.document.createElement("script");
						js.src=How2go.Path+"/JScript/How2go.Tabs.js";
						map.document.body.appendChild(js); 
                 
				 	//if (How2go.IE)
//					{
//						 map.document.body.onkeydown=function()
//						 {
//							 alert(event);
//							 alert('cc');
//							 return;
//							 parent.How2go.MapView.KeyDown(event);
//						 }
//					}
//					else
//					{
//						map.document.body.onkeydown=function(event)
//						 {
//							 parent.How2go.MapView.KeyDown(event);
//						 }
//					}
                }
            }
            
            }
			
		
		,
        OnInit:function(map,lat,lon,zoom,callBack)
        {	
			if (typeof(window.frames[map])!='undefined' && typeof(window.frames[map].How2go) !='undefined'			
			 && typeof(window.frames[map].How2go.ParentNode) !='undefined'
			 && typeof(window.frames[map].Items) !='undefined'	
			 && typeof(window.frames[map].Tabs) !='undefined'	
			 && typeof(window.frames[map].Contextmenu) !='undefined'	
			 && typeof(window.frames[map].Slider) !='undefined'	
			 
			 )
			{
				window.frames[map].DefaultLat=lat;
				window.frames[map].DefaultLon=lon;
				window.frames[map].DefaultZoom=zoom;
				How2go.MapView.CallFunction=callBack; 
            	How2go.MapView.CallBack(callBack); 
				if(typeof How2go.MapView.CallFunction!="undefined")
                {
                    How2go.MapView.CallFunction.oncomplate();  
				}
			}
			else
			{
				setTimeout(function(){How2go.MapView.OnInit(map,lat,lon,zoom,callBack);},10);	
			}
		}
            ,
            Init:function(id,iframeName,city,time,slider,tlight,contextmenu,item)
            {
				//if ((typeof(map.How2go)=='undefined'))
//				{
//					
//					setTimeout(function(){map,parentNode,iframeName,city,time,slider,tlight,contextmenu},1000);
//					return;
//				}
				//alert(typeof(map.How2go));
				//alert(map);
				
				 var layer=How2go.$(id);
                var parentNode=layer.parentNode;
				
				map=window.frames[iframeName];
                 map.How2go.ParentNode=parentNode;
                            map.How2go.IE=How2go.IE;
                            map.How2go.Iframe=How2go.$(iframeName);
                            map.How2go.Path=How2go.Path;
							map.How2go.TCity=city;
							map.How2go.TTime=time;
							map.How2go.IE=How2go.IE;
							map.How2go.Path=How2go.Path;
							map.How2go.PointArray=new Array();
							map.How2go.LineArray=new Array();
							map.How2go.AreaArray=new Array();
							
							
                                var bg;
                                var cursor=new How2go.Mouse.Cursor();
                                map.How2go.Map=map.document.body;                            
                                var loading=map.document.createElement("div");
                                loading.style.position='absolute';
                                loading.setAttribute("unselectable","on");      
                                loading.style.zIndex=99999999; 
                                bg=How2go.Path +'/Images/loading.gif';
                                loading.innerHTML="<img unselectable=\"on\" src=\""+bg+"\" border=\"0\" style=\"width:16px;height:16px;position:absolute\" />";
                                bg=How2go.Path +'/Images/blank.gif';
                                loading.style.backgroundImage='url('+bg+')';
								
								 
                                loading.style.display='none';
                                loading.style.cursor=cursor.wait;
                                map.How2go.Map.appendChild(loading); 
                                map.How2go.Loading=loading;
                                map.How2go.TLight=tlight;
                                
                                var background=map.document.createElement("div");
                                background.style.position='absolute';
                                background.setAttribute("unselectable","on");      
                                background.style.zIndex=1; 
                                bg=How2go.Path +'/Images/bg.gif';
                                background.style.backgroundImage='url('+bg+')';
                                map.How2go.Map.appendChild(background); 
                                map.How2go.Background=background;
                                
								
                                 var mapLayer=map.document.createElement("div");
                                mapLayer.style.position='absolute';
                                mapLayer.setAttribute("unselectable","on");      
                                mapLayer.style.zIndex=55555555; 
                                bg=How2go.Path +'/Images/blank.gif';
                                mapLayer.style.backgroundImage='url('+bg+')';
									mapLayer.style.left='0px'; 
									mapLayer.style.top='0px';
								//mapLayer.style.backgroundColor='#FF0000'; 
                                
								 var mapSvg=map.document.createElement("div");
                                mapSvg.style.position='absolute';
                                mapSvg.setAttribute("unselectable","on");      
                                mapSvg.style.zIndex=55555556; 
								if (How2go.IE)
								{									
									mapSvg.style.display='none';
								}
								else
								{
                                bg=How2go.Path +'/Images/blank.gif';
                                mapSvg.style.backgroundImage='url('+bg+')';
								}
								
                                mapSvg.oncontextmenu=
                                mapLayer.oncontextmenu=function(){return false;}
								
                                mapSvg.style.cursor=
                                mapLayer.style.cursor=cursor.index;
								
                                mapSvg.title=
                                mapLayer.title='点击移动地图,双击放大地图';
									
									
                                if (How2go.IE)
                                {
                                    mapLayer.onmousedown=function()
                                        {
                                            map.How2go.Click(event);
                                        }
										
                                }
                                else
                                {
                                    mapSvg.onmousedown=
                                    mapLayer.onmousedown=function(event)
                                        {
                                            map.How2go.Click(event);
                                        }
                                }
                                map.How2go.Map.appendChild(mapSvg); 
                                map.How2go.MapSvg=mapSvg;
                                
                                map.How2go.Map.appendChild(mapLayer); 
                                map.How2go.MapLayer=mapLayer;
                                
                                             
                                
                                 var mapView=map.document.createElement("div");
                                mapView.style.position='absolute';
                                mapView.setAttribute("unselectable","on");      
                                mapView.style.zIndex=2; 
                                mapView.style.width='0px'; 
                                mapView.style.height='0px';
                                mapView.style.left='0px'; 
                                mapView.style.top='0px';
                                map.How2go.Map.appendChild(mapView); 
                                map.How2go.MapView=mapView;
                             
							  
							 
                                 var mapPoi=map.document.createElement("div");
                                mapPoi.style.position='absolute';
                                mapPoi.setAttribute("unselectable","on");      
                                mapPoi.style.zIndex=77777777; 
                                mapPoi.style.width='0px'; 
                                mapPoi.style.height='0px'; 
                                mapPoi.style.left="-2000px"; 
                                mapPoi.style.top="-2000px"; 
                                map.How2go.Map.appendChild(mapPoi); 
                                map.How2go.MapPoi=mapPoi; 
                              
			
								var mapLine=map.document.createElement("div");
                                mapLine.style.position='absolute';
                                mapLine.setAttribute("unselectable","on");      
                                mapLine.style.zIndex=66666666; 
                                mapLine.style.width='0px'; 
                                mapLine.style.height='0px'; 
                                mapLine.style.left="-2000px"; 
                                mapLine.style.top="-2000px"; 
                                map.How2go.Map.appendChild(mapLine); 
                                map.How2go.MapLine=mapLine; 
								
								
							
								
                                 var measure=map.document.createElement("div");
                                measure.style.position='absolute';
                                measure.setAttribute("unselectable","on");      
                                measure.style.zIndex=88888888; 
                                measure.style.width='80px'; 
                                measure.style.height='22px'; 
                                measure.style.display='none';
                                bg=How2go.Path +'/Images/ScaleLon.gif';
                                measure.innerHTML="<div unselectable=\"on\" title=\"\" style=\"text-align:center; height:16px; width:80px; font-size:12px; color:#000000\" id=\"How2go.Measure.Value\">0公里</div>";
                                measure.innerHTML +="<div unselectable=\"on\" style=\"text-align:center; height:6px; width:80px; line-height:0px\"><img unselectable=\"on\" src=\""+bg+"\" border=\"0\" style=\"width:80px;height:6px;\" /></div>";
                                
                                map.How2go.Map.appendChild(measure); 
                                map.How2go.Measure=measure;
                            
                                 var version=map.document.createElement("div");
                                version.style.position='absolute';
                                version.setAttribute("unselectable","on");      
                                version.style.zIndex=88888888; 
                                version.style.width='80px'; 
                                version.style.height='20px'; 
                                version.style.display='none';
                                version.innerHTML="&copy; <a unselectable=\"on\" href=\"http://www.how2go.cn\" target=\"_blank\" style=\"color:#0033FF;TEXT-DECORATION:none ;cursor:"+cursor.hand+"\" title=\"\">How2go.cn</a>";
                                map.How2go.Map.appendChild(version); 
                                map.How2go.Version=version;
								
								
								
								setTimeout(function(){
                                if (item)
								{
									var items=map.document.createElement("div");
                                items.style.position='absolute';
                                items.setAttribute("unselectable","on");      
                                items.style.zIndex=88888888; 
                                items.style.width='0px'; 
                                items.id='How2go.Items.Parent'; 
                                items.style.height='0px'; 
                                items.style.left="0px"; 
                                items.style.top="0px"; 
                                items.style.display='none';
								//items.style.backgroundColor='#FF0000'; 
                                items.innerHTML=window.frames[iframeName].Items.Content;
                                map.How2go.Map.appendChild(items); 
								}
								var tab=map.document.createElement("div");
                                tab.style.position='absolute';
                                tab.setAttribute("unselectable","on");      
                                tab.style.zIndex=77777779; 
                                tab.id='How2go.Tab.Parent'; 
                                //tab.className='tab'; 
                                tab.style.left="200px"; 
                                tab.style.top="50px"; 
                                tab.style.display='none';
								//items.style.backgroundColor='#FF0000'; 
                                tab.innerHTML=window.frames[iframeName].Tabs.Content;
                                map.How2go.Map.appendChild(tab); 
                                map.How2go.Tab=tab;
								//window.frames[iframeName].Tabs.Set('基本信息,路况信息,行驶路线,周边查找','我就是路况名称啦',1);
								if (slider)
								{
									  
									 slider=window.frames[iframeName].document.createElement("div");
									 	slider.style.position='absolute';
										slider.setAttribute("unselectable","on");      
										slider.style.zIndex=88888888; 
										slider.style.width='54px'; 
										slider.style.height='210px';  
										slider.style.left='4px';  
										//slider.style.backgroundColor='#FF0000'; 
										slider.style.top='4px';
										slider.innerHTML=window.frames[iframeName].Slider.Content;
                                		window.frames[iframeName].How2go.Map.appendChild(slider); 
								}
								if (contextmenu)
									{
										
										contextmenu=window.frames[iframeName].document.createElement("div");
									 	contextmenu.style.position='absolute';
										contextmenu.setAttribute("unselectable","on");      
										contextmenu.style.zIndex=88888889; 
										contextmenu.style.width='100px'; 
										contextmenu.style.left='0px';    
										contextmenu.style.top='0px';    
										contextmenu.style.display='none';    
										contextmenu.style.padding='2px';    
										contextmenu.style.fontSize='11px';    
										contextmenu.style.border='#000000 1px solid'; 
										contextmenu.style.backgroundColor='#ffffff';  
										contextmenu.innerHTML=window.frames[iframeName].Contextmenu.Content;
										contextmenu.id='How2go.cn.Contentmentu';
										contextmenu.style.cursor=cursor.index;
										contextmenu.oncontextmenu=function(){return false;}
										contextmenu.onmouseout=function()
										{
											contextmenu.style.display='none';	
										}
                                		window.frames[iframeName].How2go.Map.appendChild(contextmenu); 
										//map.How2go.Map.innerHTML +=Contextmenu.Content;
									}
                                map.How2go.Resize();
													}
													
													,10
													)
            }
}
