<?php
# $Id$
# http://www.mapbender.org/index.php/mod_pan.php
# Copyright (C) 2002 CCGIS 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
echo "var mod_pan_target = '".$e_target[0]."';";
?>
var mod_pan_elName = "pan1";
var mod_pan_frameName = "";


var mod_pan_img_on = new Image(); mod_pan_img_on.src = "<?php  echo preg_replace("/_off/","_on",$e_src);  ?>";
var mod_pan_img_off = new Image(); mod_pan_img_off.src = "<?php  echo $e_src;  ?>";
var mod_pan_img_over = new Image(); mod_pan_img_over.src = "<?php  echo preg_replace("/_off/","_over",$e_src);  ?>";

function init_mod_pan(ind){
	mb_button[ind] = document.getElementById(mod_pan_elName);
	mb_button[ind].img_over = mod_pan_img_over.src;
	mb_button[ind].img_on = mod_pan_img_on.src;
	mb_button[ind].img_off = mod_pan_img_off.src;
	mb_button[ind].status = 0;
	mb_button[ind].elName = mod_pan_elName;
	mb_button[ind].fName = mod_pan_frameName;
	mb_button[ind].go = new Function ("mod_pan_click()");
	mb_button[ind].stop = new Function ("mod_pan_disable()");
}
function mod_pan_click(){   
	var el = window.frames[mod_pan_target].document; 
	el.onmousedown = mod_pan_start;
	el.onmouseup = mod_pan_stop;
	el.onmousemove = mod_pan_run;
}
function mod_pan_disable(){
	var el = window.frames[mod_pan_target].document; 
	el.onmousedown = null;
	el.onmouseup = null;
	el.onmousemove = null;
}
function mod_pan_start(e){
	mb_panActive = true;
	mb_getMousePos(e,mod_pan_target);
	mb_start_x=clickX;
	mb_start_y=clickY;
	mb_end_x = clickX;
	mb_end_y = clickY; 
	return false;
}
function mod_pan_run(e){
	if(mb_panActive){
		mb_getMousePos(e,mod_pan_target);
		mb_end_x = clickX;
		mb_end_y = clickY;
		mod_pan_move_map();
		if(ie){
			return false;
		}
		else{
			return true;
		}
	}
}
function mod_pan_stop(e){
	if(mb_panActive){
		mb_panActive = false;
		var dif_x = mb_end_x - mb_start_x;
		var dif_y = mb_end_y - mb_start_y;
		for(var i=0; i<mb_mapObj.length; i++){
			if(mb_mapObj[i].frameName == mod_pan_target){
				var width = mb_mapObj[i].width;
				var height = mb_mapObj[i].height;      
			}
		} 
		var center_x = (width / 2)  - dif_x;
		var center_y = (height / 2) - dif_y;
		var real_center = makeClickPos2RealWorldPos(mod_pan_target,center_x, center_y);   
		mb_arrangeElement(mod_pan_target, "maps", 0, 0);
		for(var i=0; i<mb_PanSubElements.length; i++){
			mb_arrangeElement(mod_pan_target, mb_PanSubElements[i], 0, 0);
		}
	   zoom(mod_pan_target,false, 1.0, real_center[0], real_center[1]);   
	}
}
function mod_pan_move_map(){
	var dif_x = mb_end_x - mb_start_x;
	var dif_y = mb_end_y - mb_start_y;
	mb_arrangeElement(mod_pan_target, "maps", dif_x, dif_y);
	for(var i=0; i<mb_PanSubElements.length; i++){
		mb_arrangeElement(mod_pan_target, mb_PanSubElements[i], dif_x, dif_y);
	} 
	return false;  
}