var liwidth = 0;

function setdistance(){
				
	$('#menu > li').each(function(index){ 
		
		liwidth += $(this).width();
	});
	
	//alert(liwidth);
	
	// container width = 950
	var con = 950;
	var numElements = $('#menu > li').length;
				
	var padd = Math.floor( (con - liwidth) / (numElements * 2) );
	padd = padd - 20
	
	var elemPadding = "4px " + padd + "px 4px " + padd + "px";
	
	$('#menu > li').css('padding', elemPadding);
			
}

var s = 1;
var t;
setTimeout("rotate()", 5000);


function rotate()
{
	// passing 0 to the function kills the rotation
	// rotation is killed when a block is clicked
	if(s >= 1)
	{
		var selNav = $('#nav li.selected');
		var selContent = $('#content li.selected');
		var content1 = $('#content li:first');
		var nav1 = $('#nav li:first');
		var lastItem = $('#content li:last').attr('id');
		var curItem = $(selContent).attr('id');
		var nextCon, nextNav, selHTML;
		
		$(selContent).fadeOut(400);
		$(selNav).removeClass('selected');
		$(selContent).removeClass('selected');
		$('div#box').detach();
		
		if(curItem == lastItem)
		{
			nextCon = content1;
			nextNav = nav1;
			selHTML = $(nav1).html();
		}
		else
		{
			nextCon = $(selContent).next();
			nextNav = $(selNav).next();
			selHTML = $(selNav).next().html();
		}
		
		$(nextCon).fadeIn(200, function(){
			$(nextNav).html('<div id="box"></div>' + selHTML);
			$(nextCon).addClass('selected');
			$(nextNav).addClass('selected');
		});
						
		t=setTimeout("rotate()", 5000);
	}
						
}

$('#nav li').click(function(){
	clearTimeout(t);
	s=0;
	var selNav = $('#nav li.selected');
	var selCon = $('#content li.selected');
	var selHTML = $(this).html();
	var selID = $(this).attr('id');
	
	$(selCon).hide();
	$(selNav).removeClass('selected');
	$(selCon).removeClass('selected');
	$('div#box').detach();
	
	
	$(this).addClass('selected');
	$('#content li#' + selID).show();
	$('#content li#' + selID).addClass('selected');
	$(this).html('<div id="box"></div>' + selHTML);
	
	// restart the rotater in 10 seconds
	
	s=1;
	t=setTimeout("rotate()", 10000);
	
});

function contact()
{
	window.location = "contactus.php?q=atp";
}

function ViewGallery(cat){
	
	cat = cat ? cat : '';
	
	window.location = "gallery.php?f=" + cat;

}


