// JavaScript Document
$(document).ready(function(){
	animate_nav();
	$('#ad_1 > img').each(function(i,e){
		rotate($(this),500,5000,i);							  
	});
	$('#updates > li').eq(0).addClass('active');
	setInterval("newsTick();",5000);
	restore_page();
	$('ul#navigation a').click(navigate);
	$('ul#spon a').click(sponsor);
});
function animate_nav()
{
	var d=1000;
	$('#navigation span').each(function(){
		$(this).stop().animate({
			'top':'-65px'								
		},d+=250);									
	});
	$('#navigation > li').hover(
		function(){
			var $this=$(this);
			$('span',$this).stop().animate({
				'top':'50px'							   
			},300).css({
				'z-index':'-1'
			});
		},function(){
			var $this=$(this);
			$('span',$this).stop().animate({
	        	'top':'-65px'
	        },800).css({
	        	'z-index':'99999'
	       });
		}
	);
}
function rotate(eleml,speed,timeout,i)
{
	eleml.animate({
		'marginLeft':'21px',
		'width':'0px'
	},speed,function(){
		var other;
		if(eleml.parent().attr('id')=='ad_1')
			other=$('#ad_2').children('img').eq(i);
		else
			other=$('#ad_1').children('img').eq(i);
		other.animate({
			'marginLeft':'0px',
			'width':'42px'
		},speed,function(){
			var f=function(){
				rotate(other,speed,timeout,i);
			}	
			setTimeout(f,timeout);
		});
	});
}
function newsTick() {
    var $active=$('#updates > li.active');
   	if($active.length==0)
		$active=$('#updates > li:last');
	var $next=$active.next().length ? $active.next() : $('#updates > li').eq(0);
	$active.addClass('last-active');
	$next.css({opacity:0.0}).addClass('active').animate({opacity:1.0},1000,function(){
		$active.removeClass('active last-active');																				
	});
}
function navigate()
{
	var address=$(this).attr('href');
	var $now=$(this);
	$('ul#navigation a').each(function(){
		$(this).removeClass('active');					   
	});
	$now.addClass('active');
	nav(address);
}
function sponsor()
{
	$('#spon-list').css('height','auto');
	var address=$(this).attr('href');
	var $now=$(this);
	$('ul#spon a').each(function(){
		$(this).removeClass('active');							 
	});
	$now.addClass('active');
	var arr=address.split('#');
	$(document).scrollTo($('#'+arr[1]),1000,{offset:{top:-210}});
	var file='./sponsors/'+arr[1]+'.php';
	$('#spon-list').hide().load(file).fadeIn('slow');
}
function nav(add)
{
	var arr=add.split('#');
	$(document).scrollTo($('#'+arr[1]),1000,{offset:{top:-70}});
}
function scrll(add,highlight)
{
	$('ul#navigation a').each(function(){
		$(this).removeClass('active');					   
	});
	$(highlight).addClass('active');
	nav(add);
}
function restore_page()
{
	var hash=window.location.hash;
	if(hash)
	{
		switch (hash)
		{
			case "#daksh-home" : scrll(hash,'#home'); break;
			case "#daksh-about" : scrll(hash,'#about'); break;
			case "#daksh-sponsors" : scrll(hash,'#sponsors'); break;
			case "#daksh-contacts" : scrll(hash,'#contacts'); break;
			default : scrll('#daksh-home','#home'); break;
		}
	}
}