var testObject = new Image();

// inizializza un pulsante
function Button(name, x, y, width, height){
    this._name = name;
    this._x = x;
    this._y = y;
    this._width = width;
    this._height = height;
}

Button.prototype._name;
Button.prototype._x;
Button.prototype._y;
Button.prototype._width;
Button.prototype._height;

Button.prototype._on_over_img;
Button.prototype._href;

Button.prototype.setMouseoverImage = function(url){
    this._on_over_img = new Image();
    this._on_over_img.src = url;
}

Button.prototype.setHref = function(url){
    this._href = url;
}



Button.prototype.render = function(container){

    hit_area = $(document.createElement('div'));
    hit_area.attr("id", "harea_" + this._name);
    hit_area.attr("class", "hit_area");
    hit_area.css({
        'margin-left': this._x + 'px',
        'margin-top': this._y + 'px',
        'width': this._width + 'px',
        'height': this._height + 'px'
    });
   

  
      hit_area.click(function(e){
        var btn = $(this);
        var id = btn.attr('id');
        var name = id.substr(id.indexOf('_') + 1);
        var link = $(btn.children()[0]);
        var ref = link.attr('href');
        
        btn.css({
            background: "url(" + $('#over_' + name).attr("src") + ") no-repeat",
            opacity: 100
        });
        
        btn.effect('puff', new function(){
            btn.css("opacity", "0");
            btn.css("display", "block");
        });
        
        location.href = ref;
        
        $(".hit_area").css("display", "none");
        
        
    });
    
    hit_area.mouseover(function(e){
    
		
        var id = $(this).attr('id');
        var name = id.substr(id.indexOf('_') + 1);
        
        if (testObject.style.opacity == undefined) {
            $('#over_' + name).css('display', 'inline');
        }
        else {
            $('#over_' + name).fadeIn('slow');
        }
        
				var prefx = (user_language == "ENG") ? "eng_" : "ita_";
				$("#" + prefx + name).children().attr("src", "voci_menu/over/" + prefx + name + ".png");			
				
    });
    
    hit_area.mouseout(function(e){
    
        var id = $(this).attr('id');
        var name = id.substr(id.indexOf('_') + 1);
        
        if (testObject.style.opacity == undefined) {
            $('#over_' + name).css('display', 'none');
        }
        else {
            $('#over_' + name).fadeOut('slow');
        }
				
				        
				var prefx = (user_language == "ENG") ? "eng_" : "ita_";
				$("#" + prefx + name).children().attr("src", "voci_menu/" + prefx + name + ".png");			

				
    }); 
  
    
    link = $(document.createElement('a'));
    link.attr("href", this._href);
    link.css("display", "none");
    link.append("_");
    hit_area.append(link);
    
    img_over = $(document.createElement('img'));
    img_over.attr("id", "over_" + this._name);
    img_over.attr("class", "button");
    img_over.attr("src", this._on_over_img.src);
    
		img_over.css({
        'margin-left': this._x + 'px',
        'margin-top': this._y + 'px'
    });
		
    $("#" + container).prepend(hit_area);
    $("#" + container).prepend(img_over);
     
}

function btnName(obj){
	
        var id = obj.attr('id');
        return id.substr(id.indexOf('_') + 1);
	
}
