/* <![CDATA[ */
$(document).ready(function(){
	
	$("ul#ticker01").removeClass('ticker-format').liScroll({travelocity: 0.05});
	
	$.preloadCssImages();
	
	$('#network').hover( function(){ $('#network-content').fadeIn('fast'); }, function(){ $('#network-content').fadeOut('fast'); } );
	$('#sub-navi-selected').prev().css({ 'background': 'url()' });
	$('a').focus(function(){ $(this).blur(); });
	$('.index-pic').hover(
		function(){
			var pic = $(this).children('a').children('img');
			$(pic).stop().animate({'opacity':'1'},300);
			$(pic).parent().next('div').animate({'left':'2px'},200);
		},
		function(){
			var pic = $(this).children('a').children('img');
			$(pic).stop().animate({'opacity':'0.7'},300);
			$(pic).parent().next('div').stop().animate({'left':'185px'},200);
		}		
	);
	
	//Index-Gallery	
	$('#index-up').click(function(){
		var scroller = $('#scroller');
		var top = parseInt( scroller.css('top') );
		var top_scroll = top + 105;
		var check_active = top % 105;
		if( top_scroll <= -105 ){ $('#index-up').css({'opacity':'1'}); } else {  $('#index-up').css({'opacity':'0.4'}); } 
		if( top_scroll <= $.max_scrolldown + 105 ){ $('#index-down').css({'opacity':'0.4'}); } else {  $('#index-down').css({'opacity':'1'}); } 
		if( top < 0 && check_active == 0 ){
			scroller.animate({'top':top_scroll+'px'},200);
		}
		return false;
	});
	$('#index-down').click(function(){
		var scroller = $('#scroller');
		var top = parseInt( scroller.css('top') );
		var top_scroll = top - 105;
		var check_active = top % 105;
		if( top_scroll <= -105 ){ $('#index-up').css({'opacity':'1'}); } else {  $('#index-up').css({'opacity':'0.4'}); } 
		if( top_scroll <= $.max_scrolldown + 105 ){ $('#index-down').css({'opacity':'0.4'}); } else {  $('#index-down').css({'opacity':'1'}); } 
		
		if( top <= 0 && check_active == 0 && top_scroll > $.max_scrolldown ){
			scroller.animate({'top':top_scroll+'px'},200);
		}
		return false;
	});
});
$.fn.betterTooltip = function(options){
	
	/* Setup the options for the tooltip that can be 
	   accessed from outside the plugin              */
	var defaults = {
		speed: 200,
		delay: 300
	};
	
	var options = $.extend(defaults, options);
	
	/* Create a function that builds the tooltip 
	   markup. Then, prepend the tooltip to the body */
	getTip = function() {
		var tTip = 
			"<div class='tip'>" +
				"<div class='tipMid'>"	+
				"</div>" +
				"<div class='tipBtm'></div>" +
			"</div>";
		return tTip;
	}
	$("body").prepend(getTip());
	
	/* Give each item with the class associated with 
	   the plugin the ability to call the tooltip    */
	$(this).each(function(){
		
		var $this = $(this);
		var tip = $('.tip');
		var tipInner = $('.tip .tipMid');
		
		var tTitle = (this.title);
		this.title = "";
		
		var offset = $(this).offset();
		var tLeft = offset.left;
		var tTop = offset.top;
		var tWidth = $this.width();
		var tHeight = $this.height();
		
		/* Mouse over and out functions*/
		$this.hover(
			function() {
				tipInner.html(tTitle);
				setTip(tTop, tLeft);
				setTimer();
			}, 
			function() {
				stopTimer();
				tip.hide();
			}
		);		   
		
		/* Delay the fade-in animation of the tooltip */
		setTimer = function() {
			$this.showTipTimer = setInterval("showTip()", defaults.delay);
		}
		
		stopTimer = function() {
			clearInterval($this.showTipTimer);
		}
		
		/* Position the tooltip relative to the class 
		   associated with the tooltip                */
		setTip = function(top, left){
			var topOffset = tip.height();
			var xTip = (left-30)+"px";
			var yTip = (top-topOffset-80)+"px";
			tip.css({'top' : yTip, 'left' : xTip});
		}
		
		/* This function stops the timer and creates the
		   fade-in animation                          */
		showTip = function(){
			stopTimer();
			tip.animate({"top": "+=20px", "opacity": "toggle"}, defaults.speed);
		}
	});
};
/* ]]> */
