var svcHt;

/* -------------------- HOME PAGE -------------------- */

function selectService(el, updateArticles)
{
    updateArticles = typeof(updateArticles) != 'undefined' ? updateArticles : false;
    $('.services-home > ul > li').removeClass('selected');
    el.addClass('selected', 100);
    
    var svc_id = el.attr('id').substr(4);
    
    if(updateArticles)
    {
    	$.get('/hajax/home_articles/'+svc_id, function(data) {$('#featured-articles').html(data);});
    }
}

/* -------------------- SERVICES & TECHNOLOGIES -------------------- */

// initalize services and technologies blocks
function initBlocks()
{
	// show first 6 services
	var i = 0;
	var height = 0;
	$('.services ul li').each(function() {
		if(i < 6)
		{
			$(this).show();
			height += 40;
		}
		i++;
		
	});
	$('.services ul').animate({height: height}, 500);
	// show first 10 technologies
	i = 0;
	height = 0;
	$('.technologies ul li').each(function() {
		if(i < 10)
		{
			$(this).show();
			height += 27;
		}
		i++;
	});
	$('.technologies ul').animate({height: height}, 500);
}

// expand services and technologies block to show all
function showAllBlocks()
{
	// animate services block
	var height = 0;
	$('.services ul li').each(function() {
		$(this).show();
		height += $(this).height();
		/*height += 40;
		if($(this).hasClass('selected'))
			height += $(this).find('p').height() + 35;*/
	});
	//$('.services ul').animate({height: height}, 500);
	svcHt = height;
	// animate technologies block
	height = 0;
	$('.technologies ul li').each(function() {
		$(this).show();
		height += 27;
	});
	//$('.technologies ul').animate({height: height}, 500);
	// hide more buttons
	$('.st-more a').hide();
}

// remove colors from services and technologies blocks
function resetBlocks()
{
	$('.services ul li').each(function() {
		var other = $(this);
		other.removeClass('selected');
		other.children('.service-description').hide();
	});
	$('.technologies ul li').each(function() {
		var other = $(this);
		other.removeClass('high low');
	});
}

// color the associated technologies for a specified service
function colorTechnologies(id)
{
	for(i in svcs_techs_high[id])
	{
		var sel = "#tech_"+svcs_techs_high[id][i];
		$(sel).addClass('high', 500);
	}
	setTimeout(function() {
		for(i in svcs_techs_med[id])
		{
			var sel = "#tech_"+svcs_techs_med[id][i];
			$(sel).addClass('med', 500);
		}
	}, 250 );
	setTimeout(function() {
		for(i in svcs_techs_low[id])
		{
			var sel = "#tech_"+svcs_techs_low[id][i];
			$(sel).addClass('low', 500);
		}
	}, 500 );

}

// animate the height to match the current service's description height
function animateHeight(el)
{
	//var bh = el.parent().height();
	var bh = svcHt;
	var dh = el.height() - el.find('span:first-child').height() + 20;
	var nh = bh + dh;
	el.parent().animate({height: nh}, 500);
}

function activateTab(el)
{
	var id = el.attr('id').substr(4);
		
	// get rid of old colors
	//resetBlocks();
	
	var selected = $('.services ul li.selected');
	
	if(typeof selected.attr('id') != 'undefined')
	{
		selected.children('.service-description').slideUp(500, function() {
			selected.removeClass('selected');
			// set this to selected and open the description
			el.addClass('selected');
			el.children('.service-description').slideDown(500);
			colorTechnologies(id);
		});
		
		$('.technologies ul li').each(function() {
			var other = $(this);
			other.removeClass('high med low');
		});
	}
	else
	{
		// set this to selected and open the description
		el.addClass('selected');
		el.children('.service-description').slideDown(500);
		colorTechnologies(id);
	}
	
	// animate the height if this is our first time
	//if( ! el.parent().hasClass('active'))
	
	// make the block active
	el.parent().addClass('active');
	
	
	clearTimeout(t);
}

/* -------------------- CASE STUDIES -------------------- */

// expand/close case studies blocks
function toggleCaseStudy(id)
{
	var video = $('#watch-'+id);
	var long = $('#long-'+id);
	var button = $('#togle-'+id);
	if(video.hasClass('photo'))
	{
		video.removeClass('photo').animate({width:384, height: 288}, 500);
		swfobject.embedSWF("http://highermedia.com/assets/flash/demo_player.swf", "thumb_" + id, "384", "288", "4", false, {"code": id, "base_path": "http://www.highermedia.com/"}, {"allowScriptAccess": "always", "allowFullScreen": "true"});
		long.slideDown(500);
		button.removeClass('expand').addClass('close');
	}
	else
	{
		video.addClass('photo').animate({width:184, height:138}, 500, function() {
			video.html('<img class="thumb" id="thumb_' + id + '" src="http://highermedia.com/assets/images/case_studies/thumbs/' + id + '.jpg" alt="" />');
		});
		long.slideUp(500);
		button.removeClass('close').addClass('expand');
	}
}
