// JavaScript Document
$(function() { 
 	var timerid;
    // same thing here. 

if (tobj.ie6||tobj.ie7) { //if ie6 or 7 
	 	
		$('.RightTabTitle').show();
	 }
	
if (!(tobj.ie6||tobj.ie7)) {
	$(".RightTab").css("z-index", -1);
	$(".RightTabContent a").css("opacity", "0.1");

	function RightTabClose(){
		
		$(".RightTab").animate({
		left:"468px"
		},100, "easeInQuint" ,function (){
		  this.style.zIndex=-1;
		  $(".RightTabContent a").css("opacity", "0.1");
										
		  });   
		  
	}

	$(".RightTab").mouseenter(function(){
		if ($(".RightTab").css("z-index")==-1){
			this.style.zIndex=2
			$(".RightTabContent a").css("opacity", "1");
			
			$(".RightTab").animate({
			left:"473px"
			},100, "easeOutQuint" ,function (){
			  this.style.zIndex=3;
			});
		} else {
			clearTimeout(timerid);
				
		}
			
	  });      

	
		
	
	
	
	$(".RightTab").mouseleave(function() {
	 timerid=setTimeout(RightTabClose, 300);
	 
	 	
	}
	 );
	
	
	
	function moveRightTabHeader() {
	if ($('.RightTabHeader').size()>0) {
		var contTop=document.getElementById('maininfo').offsetTop+140;
		var contHeight=$('.content').height();
		var tabHeight=$('.RightTabHeader').height()+15;
		var scrollTop=$(window).scrollTop();
		var newTopOffset=0;
		var oldTopOffset=$('.RightTabHeader').offset().top;
		var speed=1500;
		
		if (scrollTop>contTop) {
			newTopOffset=scrollTop-contTop;	
			if (newTopOffset>contHeight-tabHeight) {
				newTopOffset=contHeight-tabHeight-20;
			}
			
		} else newTopOffset=0;
		
		var diff=newTopOffset-oldTopOffset;
		if (diff<0) diff=diff*-1;
		
		speed=7000-diff*4;
		if (speed<1000) speed=2000;
		speed=500;
		 //console.log("Scoll position %d, diff %d, conttop %d", $(window).scrollTop(),diff,contTop);		
		 
		$('.RightTab').stop(true,false);
		RightTabClose();
		$('.RightTab').animate({
			
			top: newTopOffset+'px'},speed,"easeOutCubic");
	 }
		
	}
	
	moveRightTabHeader();
	
	$(window).scroll(function() {
		if ($(".RightTab").css("z-index")==-1)			  
		  moveRightTabHeader();					  
	});
	
	$(".RightTabContent").click(function(){
		setTimeout(moveRightTabHeader, 100);
		
		});
		   
}

	
	
	// Tooltips for top article menu icons
	$.easing.bouncy = function (x, t, b, c, d) { 
		var s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
		} 
	 
	// create custom tooltip effect for jQuery Tooltip 
	$.tools.tooltip.addEffect("bouncy", 
 
		// opening animation 
		function(done) { 
			this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show(); 
		}, 
	 
		// closing animation 
		function(done) { 
			this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  { 
				$(this).hide(); 
				done.call(); 
			}); 
		} 
		);

	//$('.articleMenuIcons img[title]').tooltip({tip:'#hintsmall',effect: 'slide', slideOffset: -5});
	
	
	$(".articleMenuIcons img[title]").tooltip({ 
     
        // use single tooltip element for all tips 
        tip: '#hintsmall',  
         
        // tweak the position 
       
         
        // use "slide" effect 
        effect: 'slide',
		slideOffset: -3
         
    // add dynamic plugin  
    }).dynamic( { 
     
        // customized configuration on bottom edge 
        bottom: { 
         
            // slide downwards 
            direction: 'down', 
			slideOffset: 5,
             
            // bounce back when closed 
            bounce: true 
        } 
    }); 
	
	
});