// get position of child node
// var snoogans = getPosition(this.parentNode,this);
function getPosition(main,spec) {
	var items = main.getElementsByTagName(spec.tagName);
	var found = 0;
	for (p = 0; p < items.length; p++) {
		if (items[p] == spec) {
			found = 1;
			break;
		}
	}
	if (found) {
		return p;
	}
	else {
		return -1;
	}
}

$(document).ready(function(){

	// select input text on click
	$("input").click(function(){ $(this).select(); });

	// links with rel="external" will open in a new window
	$("a[rel=external]").click(function(){ window.open(this.href); return false; });
	
	checkForScrollingContent();
		
});

function checkForScrollingContent()
{
	// check to see if we need to attach the custom scroll bar to the content
	var custom_scroll = $("div#scrolling-content").length;
	if ( custom_scroll > 0 ) { $("div#scrolling-content").jScrollPane(); }
	
	// check for the client logo scrolling area
	var client_scroll = $("div#client-logos").length;
	if ( client_scroll > 0 ) { $("div#client-logos").jScrollPane(); }
}

function ourTeamNavigation()
{
	
	group_in_view = "group-one";
	group_out_view = "group-two";
	
	if ( team_set == 1 ) { $("a#more-bios").addClass("bios-more"); } 
	if ( team_set == 2 ) { $("a#more-bios").addClass("bios-back"); } 
	
	
	if ( $("ul#team-navigation li.group-two").hasClass("selected-bio") )
	{
		group_in_view = "group-two";
		group_out_view = "group-one";
		$("ul#team-navigation li.group-one").hide();
		$("ul#team-navigation li.group-two").show();
	}
	
	// turn off click when link is in selected state
	$("ul#team-navigation li").click(function(){ if ( $(this).hasClass("selected-bio") ) { return false; } });
	
	/*
	// removed hover based on recent feedback
	
		$("ul#team-navigation li").hover(
			function()
			{
				if ( $(this).hasClass("selected-bio") )
				{
					// do  nothing
				}
				else
				{
					$(this).css({borderColor: "#e5173f"});
				}
			},
			function()
			{
				if ( $(this).hasClass("selected-bio") )
				{
					// do  nothing
				}
				else
				{
					$(this).css({borderColor: "#ffffff"});
				}
			}
		);
	
	*/
	
	
	// show more bios
	$("a#more-bios").toggle(
		function(){
			$("ul#team-navigation li." + group_in_view + "").hide();
			$("ul#team-navigation li." + group_out_view + "").fadeIn(750);
			// $(this).text("back");
			if ( team_set == 1 ) { $(this).removeClass("bios-more").addClass("bios-back"); } 
			if ( team_set == 2 ) { $(this).removeClass("bios-back").addClass("bios-more"); } 
		},
		function(){
			$("ul#team-navigation li." + group_out_view + "").hide();
			$("ul#team-navigation li." + group_in_view + "").fadeIn(750);
			// $(this).text("more");
			if ( team_set == 1 ) { $(this).removeClass("bios-back").addClass("bios-more"); } 
			if ( team_set == 2 ) { $(this).removeClass("bios-more").addClass("bios-back"); } 
		}
	);
	
	
	
}

function ourTeamPhotoAnimation()
{
	$("div.team-photo")
		.animate(
			{opacity: 1},
			{
				duration: 500,
				easing: 'easeInSine'
			}
		);
}


function servicesDiagram()
{
	
	// preload team photo prior to animation
	$.imgpreload(['../img/content/services-diagram.jpg'],
	{
		all: function()
		{
			$("div#services-diagram").css({opacity: 0}).show();
			$("div#services-diagram")
			.animate(
				{opacity: 1},
				{
					duration: 750,
					easing: 'easeInSine'
				}
			);
		}
	});
		
	// please ignore the disgusting formatting
		
	// design
	$("div#services-diagram a#design-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#design").hover( function() { $("div#services-diagram a#design-hover").show(); }, function(){ $("div#services-diagram a#design-hover").hide(); } );
	
	// red ball
	$("div#services-diagram a#red-ball-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#red-ball").hover( function() { $("div#services-diagram a#red-ball-hover").show(); }, function(){ $("div#services-diagram a#red-ball-hover").hide(); } );
	
	// media
	$("div#services-diagram a#media-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#media").hover( function() { $("div#services-diagram a#media-hover").show(); }, function(){ $("div#services-diagram a#media-hover").hide(); } );
	
	// production
	$("div#services-diagram a#production-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#production").hover( function() { $("div#services-diagram a#production-hover").show(); }, function(){ $("div#services-diagram a#production-hover").hide(); } );
	
	// digital
	$("div#services-diagram a#digital-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#digital").hover( function() { $("div#services-diagram a#digital-hover").show(); }, function(){ $("div#services-diagram a#digital-hover").hide(); } );
	
	// research
	$("div#services-diagram a#research-hover").hover( function() { $(this).show(); }, function(){ $(this).hide(); } );
	$("area#research").hover( function() { $("div#services-diagram a#research-hover").show(); }, function(){ $("div#services-diagram a#research-hover").hide(); } );
}




function whyTriadTestimonials()
{
	// how many testimonials are there?
	total_testimonials = $("div#graphic-quote ul li").length;
	
	// animate in the first testimonial
	current_testimonial = 0;
	$("div#graphic-quote ul li:eq(0)").show();
	
	$("div#graphic-quote").css({opacity: 0}).show();
	$("div#graphic-quote")
	.animate(
		{opacity: 1},
		{
			duration: 500,
			easing: 'easeInSine',
			complete: function()
			{
				// start the rotator
				rotateTestimonials();
			}
		}
	);
}


function rotateTestimonials()
{
	rotating_testimonials = setInterval("showNextTestimonial();", 4500);
}


function showNextTestimonial()
{
	// fade current testimonial out of view
	if ( current_testimonial == (total_testimonials - 1) )
	{
		current_testimonial = 0;
		$("div#graphic-quote ul li").fadeOut(250);
		$("div#graphic-quote ul li:eq(0)").fadeIn(750);
	}
	else
	{
		current_testimonial++;
		$("div#graphic-quote ul li").fadeOut(250);
		$("div#graphic-quote ul li:eq(" + current_testimonial + ")").fadeIn(750);
	}
}
