//Размеры картинки var pw=640; var ph=480; //Размеры виртуального окна для малого вида var ww=296; var wh=206; var layers="1,2,3,4,5"; var domain=document.domain.split("."); var cc_map_url="/c_map/get_map_merc_image.php?city_code="+city_code+"&w="+pw+"&h="+ph+"&lon="+layers; var f_start=true; var cc_loaded=false; var MapTopS=0; var MapLeftS=0; var disable_mz=false; function cc_image_loaded() { cc_map_img=document.getElementById("cc_map_src"); if (!cc_map_img) return; // Инициализация события mousewheel if (cc_map_img.addEventListener) // mozilla, safari, chrome cc_map_img.addEventListener('DOMMouseScroll', mouse_wheel, false); // IE, Opera. cc_map_img.onmousewheel = mouse_wheel; OpenFullMap("small"); //Инициализация малого вида cc_map_img.width=pw; cc_map_img.height=ph; MapTopS=parseInt(cc_map_img.style.top); MapLeftS=parseInt(cc_map_img.style.left); cc_loaded=true; if (!Get_Cookie("geo_data")) { disable_mz=true; OnOffElements("zoom_out,zoom_in","off","default"); cc_map_img.style.cursor="default"; } else cc_map_img.style.cursor="move"; cc_map_img.onload=cc2_image_ready; } var cc2_loading=false; var _isIE = -1; //Если 1, то IE, если 0 - то не IE function cc_isIE() { if (_isIE != -1) {return _isIE;} else { if (cc_map_img.style.opacity=="") _isIE = 0; else _isIE = 1; } return _isIE; } function image_loading() { cc2_loading=true; OnOffElements("cc_map_src,full_map,zoom_out,zoom_in","off","wait"); } function cc2_image_ready() { cc2_loading=false; cc_map_img.style.top=MapTopS+"px"; cc_map_img.style.left=MapLeftS+"px"; cc_map_img.width=pw; cc_map_img.height=ph; OnOffElements("cc_map_src","on","move"); if (!disable_mz) { OnOffElements("full_map","on","pointer"); if (zoom >= max_zoom) OnOffElements("zoom_in","off","default") else OnOffElements("zoom_in","on","pointer"); if (zoom <= min_zoom) OnOffElements("zoom_out","off","default") else OnOffElements("zoom_out","on","pointer"); } else OnOffElements("full_map,zoom_out,zoom_in","off","default"); } var zoom=1; var max_zoom=16; var min_zoom=-6; var zoom_quant=2; function map_zoom(zoom_dir,zomm_level) { if (zomm_level == undefined) zomm_level=0; if (disable_mz) return; if (cc2_loading) return; if (whell_moving) return; var zoom_to=1; if (zoom_dir==0) { image_loading(); zoom_to=zoom+zomm_level; if (zoom_to>max_zoom) { zoom_to=max_zoom-zoom; zoom=max_zoom; } else if (zoom_to < min_zoom) { zoom_to=min_zoom-zoom; if (zoom_to==0) zoom_to=1; zoom=min_zoom; } else { zoom_to=zomm_level; zoom=zoom+zomm_level; } if (zoom_to==0 || zoom_to==1) { cc2_image_ready(); return true; } cc_map_img.src=cc_map_url+"&zoom="+zoom_to+"&nx=1&ext="+Get_Cookie("geo_data"); } else { if (zoom_dir==2 && zoom < max_zoom) { image_loading(); if (zoom+zoom_quant>=3) zoom_quant=4; else zoom_quant=2; zoom=zoom+zoom_quant; if (zoom==0) zoom++; if (zoom==1) zoom++; zoom_to=zoom_quant; cc_map_img.src=cc_map_url+"&zoom="+zoom_to+"&nx=1&ext="+Get_Cookie("geo_data"); } if (zoom_dir==1 && zoom>min_zoom) { image_loading(); if (zoom-zoom_quant < 3) zoom_quant=2; else zoom_quant=4; zoom=zoom-zoom_quant; if (zoom==0) zoom--; if (zoom==-1) zoom--; zoom_to=-zoom_quant; cc_map_img.src=cc_map_url+"&zoom="+zoom_to+"&nx=1&ext="+Get_Cookie("geo_data"); } } return; } //Определяет, какой тип айвента использовать - IE или Mozilla function cm_GetEventType(evt) { _evt = evt ? evt : window.event; if (_evt.preventDefault) _evt.preventDefault(); else _evt.returnValue = false; // для IE _evt.mysource = _evt.target ? _evt.target : _evt.srcElement; _evt.myx = _evt.pageX ? _evt.pageX : _evt.clientX + document.documentElement.scrollLeft; _evt.myy = _evt.pageY ? _evt.pageY : _evt.clientY + document.documentElement.scrollTop; return _evt; } mapXshift=0; mapYshift=0; MouseXOffset=0; MouseYOffset=0; IsDraggable=false; function BeginMapMove(evt) { if (disable_mz) return; if (whell_moving) return; _evt = cm_GetEventType(evt); if (_evt.button && (_evt.button == 2)) return; MouseXOffset = _evt.myx; MouseYOffset = _evt.myy; IsDraggable = true; } function EndMapMove(evt) { if (!IsDraggable) return; IsDraggable=false; var fXshift=(MapLeftS-parseInt(cc_map_img.style.left)); var fYshift=(MapTopS-parseInt(cc_map_img.style.top))*-1; image_loading(); cc_map_img.src=cc_map_url+"&nx=1&oX="+fXshift+"&oY="+fYshift+"&ext="+Get_Cookie("geo_data"); } function MapMove(evt) { if (!can_whell_zoom) { if (whell_timeout) clearTimeout(whell_timeout); whell_timeout = setTimeout("reset_whell()", 300); } if (!IsDraggable) return; _evt = cm_GetEventType(evt); cc_map_img.style.top=(MapTopS+(_evt.myy-MouseYOffset))+"px"; cc_map_img.style.left=(MapLeftS+(_evt.myx-MouseXOffset))+"px"; } function MapOut(evt) { if (whell_timeout) { clearTimeout(whell_timeout); can_whell_zoom=false; } if (!IsDraggable) return; IsDraggable=false; cc_map_img.style.top=MapTopS+"px"; cc_map_img.style.left=MapLeftS+"px"; } var clicks_count=0; var wh_timeout_state = null; function Wc_counter() { wh_timeout_state=null; whell_moving=false; map_zoom(0,clicks_count*2); clicks_count=0; } var whell_moving=false; function mouse_wheel(event) { if (disable_mz) return; if (!can_whell_zoom) return; whell_moving=true; var delta = 0; event=cm_GetEventType(event); if (wh_timeout_state) clearTimeout(wh_timeout_state); wh_timeout_state = setTimeout("Wc_counter()", 1000); if (event.wheelDelta) { delta = event.wheelDelta/120; // IE, Opera, safari, chrome - кратность дельта равна 120 } else if (event.detail) { delta = -event.detail/3; // Mozilla, кратность дельта равна 3 } if (delta < 0) { clicks_count--; cc_map_img.style.top=parseInt(cc_map_img.style.top)+Math.round(cc_map_img.height/4)+"px"; cc_map_img.style.left=parseInt(cc_map_img.style.left)+Math.round(cc_map_img.width/4)+"px"; cc_map_img.width=Math.round(cc_map_img.width/2); cc_map_img.height=Math.round(cc_map_img.height/2); } else { clicks_count++; cc_map_img.style.top=parseInt(cc_map_img.style.top)-Math.round(cc_map_img.height/2)+"px"; cc_map_img.style.left=parseInt(cc_map_img.style.left)-Math.round(cc_map_img.width/2)+"px"; cc_map_img.width=cc_map_img.width*2; cc_map_img.height=cc_map_img.height*2; } //alert(cc_map_img.style.top+" "+cc_map_img.style.left+" "+cc_map_img.width+" "+cc_map_img.height); } var can_whell_zoom=false; var whell_timeout=null; function reset_whell() { clearTimeout(whell_timeout); can_whell_zoom=true; } map_visible=false; function OpenFullMap(view) { var open_type; if (view == undefined) open_type=0; else if (view=="full") open_type=1; else open_type=2; if ((!map_visible && open_type!=2) || (open_type==1)) { document.getElementById("map_table").style.width=(pw+4)+"px"; document.getElementById("map_table").style.height=(ph+34)+"px"; document.getElementById("cc_map").style.width=(pw+4)+"px"; document.getElementById("cc_map").style.height=(ph+34)+"px"; document.getElementById("cc_map_src_container").style.clip="rect(0,"+pw+","+ph+",0)"; cc_map_img.style.top="0px"; cc_map_img.style.left="0px"; MapTopS=0; MapLeftS=0; map_visible=true; } else { document.getElementById("map_table").style.width=(ww+4)+"px"; document.getElementById("map_table").style.height=(wh+34)+"px"; document.getElementById("cc_map").style.width=(ww+4)+"px"; document.getElementById("cc_map").style.height=(wh+34)+"px"; document.getElementById("cc_map_src_container").style.clip="rect(0,"+ww+","+wh+",0)"; MapTopS=-Math.round(ph/2-wh/2); MapLeftS=-Math.round(pw/2-ww/2); cc_map_img.style.top=MapTopS+"px"; cc_map_img.style.left=MapLeftS+"px"; map_visible=false; } } function OnOffElements(elemList,action,cursor_type) { var elements=elemList.split(","); var cursor="default"; if ((cursor_type != undefined) && (cursor_type != "")) cursor=cursor_type; for (var i=0; i < elements.length; i++) { var obj=document.getElementById(elements[i]); if (!obj) continue; if (action=="on") { if (cc_isIE()) obj.style.filter = ""; else obj.style.opacity = 1; obj.style.cursor=cursor; } else { if (cc_isIE()) obj.style.filter = "alpha(opacity=30)"; else obj.style.opacity = 0.3; obj.style.cursor=cursor; } } } function Get_Cookie( check_name ) { // first we will split this cookie up into name/value pairs // note: document.cookie only returns name=value, not the other components var a_all_cookies = document.cookie.split( ";" ); var a_temp_cookie = ""; var cookie_name = ""; var cookie_value = ""; var b_cookie_found = false; // set boolean t/f default f for ( i = 0; i < a_all_cookies.length; i++ ) { // now we will split apart each name=value pair a_temp_cookie = a_all_cookies[i].split( "=" ); // and trim left/right whitespace while we are at it cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, ""); // if the extracted name matches passed check_name if ( cookie_name == check_name ) { b_cookie_found = true; // we need to handle case where cookie has no value but exists (no = sign, that is): if ( a_temp_cookie.length > 1 ) { cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, "") ); } // note that in cases where cookie is initialized but no value, null is returned return cookie_value; break; } a_temp_cookie = null; cookie_name = ""; } if ( !b_cookie_found ) { return null; } }