/*
jquery.lazytooltiper
4/26/2010
v.1.0001
*/
(function($) {
$.fn.lazytooltiper=function(o){
	base=this;
       return this.each(function(){
                    return new $.lazytool(this,o);
         });
};

$.lazytool=function(el,o) {
                   
   					 $lzt=this;
   	$lzt.options= $.extend({}, $.lazytool.defaults, o || {});
    var dtip=$($lzt.options.div_to_show);         
   
    if ($lzt.options.method=='hover'){
        $(el).hover(function(){
          $lzt.position(dtip,$(el),'enter');
        },
        function(){
        return false;
        });
       }
       else
       {
        $(el).click(function(){
              $lzt.position(dtip,$(el),'enter');
             return false;
            });
       } 

           
         $($lzt.options.close_button).click(function(){
         	
               $lzt.position(dtip,$(el),'out');    
              return false;         
        })
}
$.lazytool.defaults={
    centered:false,
        default_info:'heading',
        offset_left:10,
        offset_top:0,
        div_to_show:'#locationlocationlocation',
        overlay:'#overlay',
        close_button:'#close-location',
        default_left:-1400,
        method:'click',
        default_top:300
};
var $lazytooltiper=$.lazytool;
	$lazytooltiper.fn = $lazytooltiper.prototype = {
        lazytooltiper: '0.0.1'
    };
     $lazytooltiper.fn.extend=$lazytooltiper.extend=$.extend;
    

$lazytooltiper.fn.extend({
	
	viewport: function(){
                return {
                    x: $(window).scrollLeft(),
                    y: $(window).scrollTop(),
                    cx: $(window).width(),
                    cy: $(window).height()
                };
            },
	position: function (t,el,action){
    
        var de = document.documentElement;
        var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
        var v=$lzt.viewport();
           
        if (action === 'enter')
        {           
             if ($lzt.options.centered){  
					 left=v.x+(v.cx-t.outerWidth())/2;top=v.y+(v.cy-t.outerHeight())/2;
	         
	             t.animate({left:left,top:top},500,function(){});   
             }
             else{                    
	            var left=el.offset().left;
	            var top=el.offset().top;
	            $($lzt.options.overlay).css({width:v.cx+v.x,height:v.cy+v.y,opacity:0.6,display:'block'});
	               if (v.x + v.cx < left + t.outerWidth()) {
	                    left =left - (left + t.outerWidth() -v.x-v.cx);
	                    if (left<0||left<v.x)
	                    {
	                        left=v.x;
	                    }
	               }
	               if (v.y + v.cy < top + t.outerHeight()) {
	                   top=top-(top+t.outerHeight()-v.y-v.cy);
	                    if (top<0||top<v.y)
	                    {
	                        top=v.y;
	                    }
	               }
	                t.animate({left:left,top:top},500,function(){});   
				  }
        }
        else
        {
           //alert('you are clicking me'); 
           $($lzt.options.overlay).css({display:'none'});    
			  		
            t.animate({left:$lzt.options.default_left+'px',top:$lzt.options.default_top+'px'});
        }
 }

});

})(jQuery);
