// Bubbles tooltip for homepage
// Requires jquery.hoverIntent.minified.js and jquery-1.2.6.min.js


function showTip(event){     
    if ($(".tooltip", this).css("display") == "block") { return false; } // if current tip already show              
    var wrapperWidth = $('#wrapper').width();  
    var winWidth = $(window).width();
    var  marginWidth = (winWidth - wrapperWidth)/2;    
   var relPos =event.pageX-marginWidth;      
   //alert(relPos);
   var leftPos =0;
   if(relPos > 505){
       leftPos = 350;
   }else if (relPos > 374 && relPos < 505){
       leftPos = 250;
   }
 
    $(".tooltip", this).addClass("png");
    $(".tooltip img", this).addClass("png");
    $(".tooltip", this).css({top:0+"px",left:-leftPos+"px"}).animate({top:-110+"px", opacity: "show"}, 1000);     
}

function hideTip(event){   
    $(".tooltip", this).animate({top: 0+"px", opacity: "hide"},350);    
    
}

$(document).ready(function(){   
//configuration for the tooltip

     var config = {    
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 300, // number = milliseconds for onMouseOver polling interval    
        over: showTip, // function = onMouseOver callback (REQUIRED)    
        timeout:300, // number = milliseconds delay before onMouseOut    
        out: hideTip // function = onMouseOut callback (REQUIRED)    
    };

    $('.products li a').each(function(){ 
          var tips = $(this).attr('title');         		
          if (!tips && tips.length == 0){ return;}	            
         var heading = $(this).text();
		 var link = $(this).attr('href');
         var imgName = $(this).parent().attr("class");		 
         //can't add png class here will create extra markups.                                
          $(this).before('<div  id="' + imgName+ '" class="tooltip"><img  src="/dirc/cil/cilv2.nsf/AttachmentsByTitle/icon_' + imgName + '.png/$FILE/icon_' + imgName + '.png" alt="" /><h2>' + heading +'</h2><p>' + tips +'</p></div>'); 
          $(this).attr('title','');                  	             	    	   
    });


    $(".products li").hoverIntent( config );

});  