// BUILT ON TOP OF JQUERY ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/*************************************************************************************************/

$(document).ready(function() {
						   
	//$('.peas').dropShadow({left: 4, top: 4, opacity: 0.3, blur: 4});
	//$('.pancake').dropShadow({left: 4, top: 4, opacity: 0.3, blur: 5});
	
	// homepage carousel
	$("#carousel").wslide({
		width: 502,
		height: 740,
		autolink: false,
		fade: true,
		duration: 2000
	});
	
	// animate the carousel
	setTimeout('initAnimCarousel()', 3000);
	
	$('#carousel-menu a').click(function() {
	  carouselSelection = $('#carousel-menu a').index(this);
	  resetAnimCarousel();
	});
	
	// hides the testimonials as soon as the DOM is ready
	// (a little sooner than page load)
	$('.testimonial .inner').hide();
	
	// toggles the testimonials on clicking the noted link
	$('.testimonial a.read').click(function() {
		$(this).next('.inner').toggle(400);
		return false;
	});


				   
});

var carouselSelection = 0;
var animIntervalID = 0;

function initAnimCarousel() {
	repeatAnimCarousel();
	animIntervalID = setInterval('repeatAnimCarousel()', 8000);
}

function repeatAnimCarousel() {
	carouselSelection++;
	if (carouselSelection > 6) carouselSelection = 0;
	$('#carousel-menu a:eq('+carouselSelection+')').click();
}

function resetAnimCarousel() {
	clearInterval(animIntervalID);
	animIntervalID = setInterval('repeatAnimCarousel()', 8000);
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}

window.onload = externalLinks;