

PanControl = function ( map, img_path_pan )
{	
	this._map = map;
	this.img_path = img_path_pan;
	GControl.call(this);
};
jQuery.extend ( PanControl, GControl ); 
 
PanControl.prototype = new GControl();	

PanControl.prototype._map = null;


function pngImage ( z_in, isIE, img_path, w_z, h_z )
{
	if ( isIE )
	{
		var loader_in = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img_path + "', sizingMethod='scale');";
		z_in.innerHTML = '<div style="height:' + h_z + 'px; width:' + w_z + 'px; ' +loader_in+ '" ></div>'; 
	}
	else
	{
		z_in.innerHTML = '<img src="' + img_path + '"  width="' + w_z + '" height="' + h_z + '" >';
	}
	z_in.style.cursor = "pointer";
}
PanControl.prototype.initialize = function(map)
{
    var container = document.createElement("div");
    
	var h_b = 25;
	var w_b = 45;
    
    var w = map.getSize().width;
    var mid_w = 0;
    if (w > 0) 
        mid_w = (w / 2) - h_b;
        
    var h = map.getSize().height;
    var mid_h = 0;
    if (h > 0) 
        mid_h = h / 2;
		
    var agent = navigator.userAgent.toLowerCase();
	if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){this.ie = true;} else {this.ie = false;}
        
    var div_right = document.createElement("div");
	div_right.id = "pan_right";
	
    this.setStyleButton(div_right, mid_h - 22, w - 25);
    container.appendChild(div_right);
	pngImage ( div_right, this.ie, this.img_path + "pan_right"+".png", h_b, w_b );

	

	div_right.setAttribute('title', 'Deplacer la carte vers la droite.');
    GEvent.addDomListener(div_right, "click", function(){
        map.panDirection(-1, 0);
    });
    
    
    var div_left = document.createElement("div");
	div_left.id = "pan_left";
	
    this.setStyleButton(div_left, mid_h - 22, 0);
    container.appendChild(div_left);
	pngImage ( div_left, this.ie, this.img_path + "pan_left"+".png", h_b, w_b );

   
	div_left.setAttribute('title', 'Deplacer la carte vers la gauche.');
    GEvent.addDomListener(div_left, "click", function(){
        map.panDirection(1, 0);
    });
    
    
    var div_top = document.createElement("div");
	div_top.id = "pan_top";
	
    this.setStyleButton(div_top, 0, mid_w + 3);
    container.appendChild(div_top);
	pngImage ( div_top, this.ie, this.img_path + "pan_top"+".png", w_b, h_b );
		
    
	div_top.setAttribute('title', 'Deplacer la carte vers le haut.');
    GEvent.addDomListener(div_top, "click", function(){
        map.panDirection(0, 1);
    });
    
    
    var div_bottom = document.createElement("div");
	div_bottom.id = "pan_bottom";
	
    this.setStyleButton(div_bottom, h - 25, mid_w + 3);
    container.appendChild(div_bottom);
	pngImage ( div_bottom, this.ie, this.img_path + "pan_bottom"+".png", w_b, h_b );

   
	div_bottom.setAttribute('title', 'Deplacer la carte vers le bas.');
    GEvent.addDomListener(div_bottom, "click", function(){
        map.panDirection(0, -1);
    });
    
	
	
	
    map.getContainer().appendChild(container);
    return container;
};

PanControl.prototype.updatePosition = function()
{
	var w = map.getSize().width;
    var mid_w = 0;
    if (w > 0) 
        mid_w = w / 2 - 25;
        
    var h = map.getSize().height;
    var mid_h = 0;
    if (h > 0) 
        mid_h = h / 2;
		
	this.setStyleButton( jQuery("#pan_right")[0], mid_h - 22, w - 25);
	this.setStyleButton( jQuery("#pan_left")[0], mid_h - 22, 0);
	this.setStyleButton( jQuery("#pan_top")[0], 0, mid_w + 3);
	this.setStyleButton( jQuery("#pan_bottom")[0], h - 25, mid_w + 3);
};

PanControl.prototype.getDefaultPosition = function()
{
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
};
PanControl.prototype.setStyleButton = function(but, top, left)
{
    but.style.top = top + "px";
    but.style.left = left + "px";
    but.style.position = "absolute";
    but.style.cursor = "pointer";
};

