﻿var tooltip = new Tooltips ();
tooltip.id="#tooltip11";

function Tooltips ( options ) {
	if ( "undefined" != typeof Tooltips._instantiated ) { 
		// There can be only one...
		//return( Tooltips._instantiated ); 
	}

	if ( "undefined" == typeof options ) { options = {}; }
	this.delay = ( "undefined" == typeof options.delay ) ? 150 : options.delay; 

	this.timeout = new Object();
	this.id = 0;
	
	this.width = 250;
	this.height = 250;
	
	this.showPage = "infoPOI.aspx?poiID=";
	this.showFunction = showTooltip;
	this.hideFunction = hideTooltip;
	
	this.title;	

	Tooltips._instantiated = this;
};

function showTooltip()
{
    var tlp = tooltip;
    
    if( tlp.timeout[tlp.id] ) {
        clearTimeout( tlp.timeout[tlp.id] );
	    tlp.timeout[tlp.id] = null;
    }
        	    	    
	$("#" + this.id).children("img").attr("src", "images/map/poi_search_selected.gif");
	$("#" + this.id).parent().css("z-index","100000");
                    
    var pos = $(this).offset();
    
    $("#JT").height(tlp.height);
    $("#JT").width(tlp.width);
    
    var hh = pos.top + tlp.height + $(this).height();
    if(hh <= $(window).height())
    {
        $('#JT').css("top",pos.top - $(this).height() + $(this).height());
        $('#JT_arrow_left').css("top",-3);
        $('#JT_arrow_right').css("top",-3);            
    } else {
        $('#JT').css("top",pos.top - (tlp.height) + $(this).height());
        $('#JT_arrow_left').css("top",tlp.height - 23);
        $('#JT_arrow_right').css("top",tlp.height - 23);        
    }    

    var ww = pos.left + tlp.width + ($(this).width() * 2);    
    if (ww <= $(window).width())
    {
        $('#JT').css("left",pos.left + $(this).width() + 20);
        $('#JT_arrow_right').hide();
        $('#JT_arrow_left').show();
    } else {
        $('#JT').css("left",pos.left - (tlp.width + $(this).width()));
        $('#JT_arrow_right').show();
        $('#JT_arrow_left').hide();            
    }    

    $('#JT_close_left').html(tlp.title);
    $('#JT_copy').html(''); 
           
    $('#JT').show('fast');  
    $('#JT_copy').load(tlp.showPage+$(this).attr("poi")+"&lang=" + getCurrentLanguage());
        
    $('#JT')
    .hover( function () {  
        // Cancel tip hide timeout if the user hovers over the tooltip
        if ( tlp.timeout[tlp.id] ) {
	        clearTimeout( tlp.timeout[tlp.id] );
	        tlp.timeout[tlp.id] = null;		        
        }                    
        
        var tips = $( tlp.id );   

        $('#JT').fadeIn("slow");            
    }, function () {
        // Restart hide timeout
        var tips = $( tlp.id );
        tlp.timeout[tlp.id] = setTimeout( function () {
            $('#JT').fadeOut('slow');
        }, 100 );								
    });        
}
function hideTooltip()
{
    var tlp = tooltip;

    $("#" + this.id).children("img").attr("src", "images/map/poi_search2.gif")
	$("#" + this.id).parent().css("z-index","");
   
    tlp.timeout[tlp.id] = setTimeout( function () {
        $('#JT').hide('fast');
    }, 500 );           
}

function showTooltipHotPOI()
{
    var feaCol = gMC.doGetFeaturesCollectionById("HotPOI");
    var tlp = feaCol.Tooltip;
    
    if( tlp.timeout[tlp.id] ) {
        clearTimeout( tlp.timeout[tlp.id] );
	    tlp.timeout[tlp.id] = null;
    }          
        	    	    
	$("#" + this.id).children("img").attr("src", "images/map/poi_search2_old.gif");
	$("#" + this.id).parent().css("z-index","100000");
                    
    var pos = $(this).offset();

    $("#JT").height(tlp.height);
    $("#JT").width(tlp.width);
    
    var hh = pos.top + tlp.height + $(this).height();
    if(hh <= $(window).height())
    {
        $('#JT').css("top",pos.top - $(this).height() + $(this).height());
        $('#JT_arrow_left').css("top",-3);
        $('#JT_arrow_right').css("top",-3);            
    } else {
        $('#JT').css("top",pos.top - (tlp.height) + $(this).height());
        $('#JT_arrow_left').css("top",tlp.height - 23);
        $('#JT_arrow_right').css("top",tlp.height - 23);        
    }    

    var ww = pos.left + tlp.width + ($(this).width() * 2);    
    if (ww <= $(window).width())
    {
        $('#JT').css("left",pos.left + $(this).width() + 20);
        $('#JT_arrow_right').hide();
        $('#JT_arrow_left').show();
    } else {
        $('#JT').css("left",pos.left - (tlp.width + $(this).width()));
        $('#JT_arrow_right').show();
        $('#JT_arrow_left').hide();            
    }    
    
    $('#JT_close_left').html(tlp.title);
    $('#JT_copy').html('');        
           
    $('#JT').show('fast');  


    $('#JT_copy').load(tlp.showPage+$(this).attr("poi")+"&lang=" + getCurrentLanguage());
        
    $('#JT')
    .hover( function () {  
        // Cancel tip hide timeout if the user hovers over the tooltip
        if ( tlp.timeout[tlp.id] ) {
	        clearTimeout( tlp.timeout[tlp.id] );
	        tlp.timeout[tlp.id] = null;		        
        }                    
        
        var tips = $( tlp.id );   
        $('#JT').fadeIn("slow");            
    }, function () {
        // Restart hide timeout
        var tips = $( tlp.id );
        tlp.timeout[tlp.id] = setTimeout( function () {
            $('#JT').fadeOut('slow');
        }, 100 );								
    });    
}
function hideTooltipHotPOI()
{
    var col = gMC.doGetFeaturesCollectionById("HotPOI");
    var features = col.Features;
    
    var symbol = "evento.gif";
    
    for (var i = 0; i < features.length; i++)
    {
        var feature = features[i]
    
        if ($(this).attr("poi") == feature.ID)
        {
            //symbol = feature.Symbol;
	    symbol = "evento.gif";
            
            break;
        }
    }  

    $("#" + this.id).children("img").attr("src", "images/map/" + symbol)
	$("#" + this.id).parent().css("z-index","");

    var feaCol = gMC.doGetFeaturesCollectionById("HotPOI");
    var tlp = feaCol.Tooltip;
   
    tlp.timeout[tlp.id] = setTimeout( function () {
        $('#JT').hide('fast');
    }, 500 );           
}

function showTooltipEvent()
{   
    var tlp = tooltip;
 
    if( tlp.timeout[tlp.id] ) {
        clearTimeout( tlp.timeout[tlp.id] );
	    tlp.timeout[tlp.id] = null;
    }
        	    	    
	$("#" + this.id).children("img").attr("src", "images/map/poi_search_selected.gif");
	$("#" + this.id).parent().css("z-index","100000");
                    
    var pos = $(this).offset();
    
    var hh = pos.top + tlp.height + $(this).height();
    if(hh <= $(window).height())
    {
        $('#JT').css("top",pos.top - $(this).height() + $(this).height());
        $('#JT_arrow_left').css("top",-3);
        $('#JT_arrow_right').css("top",-3);            
    } else {
        $('#JT').css("top",pos.top - (tlp.height) + $(this).height());
        $('#JT_arrow_left').css("top", tlp.height - 23);
        $('#JT_arrow_right').css("top", tlp.height - 23);        
    }    

    var ww = pos.left + tlp.width + ($(this).width() * 2);    
    if (ww <= $(window).width())
    {
        $('#JT').css("left",pos.left + $(this).width() + 20);
        $('#JT_arrow_right').hide();
        $('#JT_arrow_left').show();
    } else {
        $('#JT').css("left",pos.left - (tlp.width + $(this).width()));
        $('#JT_arrow_right').show();
        $('#JT_arrow_left').hide();            
    }    
           
    $('#JT').show('fast');
    
    var id = $(this).attr("poi");
    var eventsId = "";
    
    var col = gMC.doGetFeaturesCollectionById("POI");
    var features = col.Features;    
    
    for (var i=0; i < features.length; i++)
    {
        try
        {
            feature = features[i];           
            
            if (id == feature.ID)
            {                
                eventsId = replace(feature.Data[3]," ","+") 
                
                break;
            }
        } catch (err) {            
        }
    }
      
    $('#JT_copy').load(tlp.showPage+$(this).attr("poi")+"&lang=" + getCurrentLanguage()+"&events="+eventsId);
        
    $('#JT')
    .hover( function () {  
        // Cancel tip hide timeout if the user hovers over the tooltip
        if ( tlp.timeout[tlp.id] ) {
	        clearTimeout( tlp.timeout[tlp.id] );
	        tlp.timeout[tlp.id] = null;		        
        }                    
        
        var tips = $( tlp.id );   

        $('#JT').fadeIn("slow");            
    }, function () {
        // Restart hide timeout
        var tips = $( tlp.id );
        tlp.timeout[tlp.id] = setTimeout( function () {
            $('#JT').fadeOut('slow');
        }, 100 );								
    });    
}



function showTooltipTitle()
{
    var tlp = tooltip;

    if( tlp.timeout[tlp.id] ) {
        clearTimeout( tlp.timeout[tlp.id] );
	    tlp.timeout[tlp.id] = null;
    }
        	    	    
	$("#" + this.id).children("img").attr("src", "images/map/poi_search_selected.gif");
	$("#" + this.id).parent().css("z-index","100000");
                    
    var pos = $(this).offset();
    
    var hh = pos.top + tlp.height + $(this).height();
    if(hh <= $(window).height())
    {
        $('#JT').css("top",pos.top - $(this).height() + $(this).height());
        $('#JT_arrow_left').css("top",-3);
        $('#JT_arrow_right').css("top",-3);            
    } else {
        $('#JT').css("top",pos.top - (tlp.height) + $(this).height());
        $('#JT_arrow_left').css("top",tlp.height - 23);
        $('#JT_arrow_right').css("top",tlp.height - 23);        
    }    

    var ww = pos.left + tlp.width + ($(this).width() * 2);    
    if (ww <= $(window).width())
    {
        $('#JT').css("left",pos.left + $(this).width() + 20);
        $('#JT_arrow_right').hide();
        $('#JT_arrow_left').show();
    } else {
        $('#JT').css("left",pos.left - (tooltip.width + $(this).width()));
        $('#JT_arrow_right').show();
        $('#JT_arrow_left').hide();            
    }    
           
    $('#JT').show('fast');
    
    var id = $(this).attr("poi");
    var eventsId = "";
    for (i=0; i < gMC.POIFeatures.length; i++)
    {
        try
        {
            feature = gMC.POIFeatures[i];           
            
            if (id == feature.ID)
            {                
                eventsId = replace(feature.Data[3]," ","+") 
                
                break;
            }
        } catch (err) {            
        }
    }
      
    //$('#JT_copy').load(tooltip.showPage+$(this).attr("poi")+"&lang=pt"+"&events="+eventsId);    
    $('#JT_copy').html("teste");
      
    $('#JT')
    .hover( function () {  
        // Cancel tip hide timeout if the user hovers over the tooltip
        if ( tlp.timeout[tlp.id] ) {
	        clearTimeout( tlp.timeout[tooltip.id] );
	        tooltip.timeout[tlp.id] = null;		        
        }                    
        
        var tips = $( tlp.id );   
        //$('#JT').show('fast');
        $('#JT').fadeIn("slow");            
    }, function () {
        // Restart hide timeout
        var tips = $( tlp.id );
        tlp.timeout[tlp.id] = setTimeout( function () {
            //$('#JT').hide('fast');
            $('#JT').fadeOut('slow');
        }, 100 );								
    }); 
}

function highlightTooltip()
{
    var tlp = tooltip;
    
    if( tlp.timeout[tlp.id] ) {
        clearTimeout( tlp.timeout[tlp.id] );
	    tlp.timeout[tlp.id] = null;
    }
        	    	    
	$("#" + this.id).children("img").attr("src", "images/map/poi_search_selected.gif");
	$("#" + this.id).parent().css("z-index","100000");
                    
    var pos = $(this).offset();
    
    var hh = pos.top + tlp.height + $(this).height();
    if(hh <= $(window).height())
    {
        $('#JT').css("top",pos.top - $(this).height() + $(this).height());
        $('#JT_arrow_left').css("top",-3);
        $('#JT_arrow_right').css("top",-3);            
    } else {
        $('#JT').css("top",pos.top - (tlp.height) + $(this).height());
        $('#JT_arrow_left').css("top",tlp.height - 23);
        $('#JT_arrow_right').css("top",tlp.height - 23);        
    }    
}
