$(document).ready(function(){
    $("a.proceed-to-valuation").hover(function() {
    
        var txt = "We have found the right bike, now let's see how what it is worth";
            
        setTooltip(this, txt);
    });

    $("a.manual-valuation").hover(function() {
        
        var txt = "Have we got something wrong, don't worry we can still help you. Just use the follow this link and select your bike";
    
        setTooltip(this, txt);
    });
});


function tooltip() {

    var originalText = $("li.intro-text").text();

    $("div.tooltip-container").animate({ marginTop: 0 }, "slow", "swing");
    if(originalText.length > 0) {
        $("span.tooltip-content").text(originalText);
    }

    $(".valuation-form").find("input[type=text], textarea, select[class=ddl]").each(function() {                              
        
        var v;                               
        v = $("label[for=" + $(this).attr("id") + "]");                               
         
        var txt
        if(v.attr("title").length > 0) {
            txt = v.attr("title");
        }
        else {
            txt = originalText;
        }
        
        $(v).mouseover(function(){
            setTooltip(this, txt);
        });
                     
        $(this).mouseover(function(){
            setTooltip(this, txt);
        });                       
    });  
    
    $(".valuation-form").find("span[class=rbl], span[class=cbl], span[class=up]").each(function() {
    
        var v;                               
        v = $("label[for=" + $(this).attr("id") + "]");               
        
        var txt
        if(v.attr("title").length > 0) {
            txt = v.attr("title");
        }
        else {
            txt = originalText;
        }
        
        $(v).mouseover(function(){
            setTooltip(this, txt);
        });
                      
        $(this).children().mouseover(function(){   
            setTooltip(this, txt);
        });        
    });   
}

function setTooltip(e, txt)
{         
    $("div.tooltip-container").stop(true, false);
    $("span.tooltip-content").stop(true, true);
    
    $("div.tooltip-container").animate({ marginTop: ($(e).offset().top - 210) }, "slow", "swing");               
    if($("span.tooltip-content").text() != txt) {        
        $("div.tooltip-wrapper").slideUp("fast", function(){            
            $("span.tooltip-content").text(txt);
            $("div.tooltip-wrapper").slideDown("slow");
        });
    }
}

