$(document).ready(function(){
	rotateNews();
	//rotateBanner();
	setInterval( "slideSwitch()", 5000 );
	$('.expandName').toggle(expandExpander, collapseExpander);
});

function initSiteCredit(){
	$("#initLink").fadeOut("normal");
	$("#CreditsLink").animate( { right:"0" }, { duration:1000 } );
	setTimeout("revertSiteCredit()",7000);
}

function revertSiteCredit(){
	$("#CreditsLink").animate( { right:"-375" }, 1000, "linear", function(){$("#initLink").fadeIn("normal");} );
}
var newsCounter = 1;
var newsLength;
function rotateNews(){
	//need to do some trickery here. we need to dupe the first one to the bottom of the list so we can slide to it, then immediately snap to the top of the container so it doesn't look like it jumps
	var dupedItem = $('#newsContent .homeNewsItem:first').html();
	dupedItem = '<p class="homeNewsItem">'+dupedItem+'</p>';
	$('#newsContent').append(dupedItem);
	
	newsLength = $('#newsContent .homeNewsItem').length;
	setInterval(shiftNews, 4000);	
}
function shiftNews(){
	if(newsLength !== newsCounter){
		var newPos = parseInt($('#newsContent').css('top'));
		newPos -= 19;
		newPos = newPos+'px';
		$('#newsContent').animate({top: newPos}, 500);
		newsCounter++;
	}
	else{
		$('#newsContent').css('top', '3px');
		newsCounter = 1;
		var newPos = parseInt($('#newsContent').css('top'));
		newPos -= 19;
		newPos = newPos+'px';
		$('#newsContent').animate({top: newPos}, 500);
		newsCounter++;
	}
}

function slideSwitch() {
    var $active = $('#banner img.active');
    
    if ( $active.length == 0 ) $active = $('#banner img:first');

    var $next =  $active.next().length ? $active.next()
        : $('#banner img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
			switch ($next.attr('id')){
				case 'b1':
					$('#bannerHotspot').attr('href', '/Portfolio#pid(310)');
					//$('#bannerHotspot').html('Pfizer Roundabout');
					break;
				case 'b2':
					$('#bannerHotspot').attr('href', '/Portfolio#pid(200)');
					//$('#bannerHotspot').html('Stiles Resivoir Dam, New London, CT');
					break;
				case 'b3':
					$('#bannerHotspot').attr('href', '/Careers');
					//$('#bannerHotspot').html("Fuss &amp; O'Neill Headquarters, Manchester, CT");
					break;	
				case 'b4':
					$('#bannerHotspot').attr('href', '/Portfolio#pid(384)');
					//$('#bannerHotspot').html('Solar');
					break;
				
			}
        });
}

function expandExpander(e){
	var id = $(e.currentTarget).attr('id');
	$(e.currentTarget).css('background', 'url(/graphics/sub/serviceArrowDown.gif) no-repeat right');
	$('#content'+id+'').slideDown('fast');
}
function collapseExpander(e){
	var id = $(e.currentTarget).attr('id');
	$(e.currentTarget).css('background', 'url(/graphics/sub/serviceArrowRight.gif) no-repeat right');
	$('#content'+id+'').slideUp('fast', function(){$('#content'+id+'').css('display', 'none');});
}
