/* = CLEAR FIELD
-------------------------------------------------
	clears the value of any inpu field with the
	class name of clearDefault
-------------------------------------------------*/

function clickClear() {
	if(!document.getElementsByTagName) return false;
	
	var inputs = document.getElementsByTagName("INPUT");
	
	for ( var i = 0; i < inputs.length; i++)
	{
		if(inputs[i].className.match("clear-default"))
		{
			inputs[i].onclick = function() {
				if(this.value == this.defaultValue)
				{
					this.value = "";
				}
				return 0;
			};
			inputs[i].onfocus = function() {
				if(this.value == this.defaultValue)
				{
					this.value = "";
				}
				return 0;
			};
			inputs[i].onblur = function() {
				if(this.value == "")
				{
					this.value = this.defaultValue;
				}
				return 0;
			};
		}
	}
	return 0;
}

var slideInit = function(){
	
	if ($('ul#portfolio').size()) {
		$('ul#portfolio').innerfade({
			timeout: 5000,
			speed: 'slow',
			containerheight: '346px'
		});
		$('ul#portfolio').innerfadeNext('#next_button a');
		$('ul#portfolio').innerfadePrevious('#prev_button a');  
	}    
};
  
var archive = function () {
	
	if ($('ul.archive').size()) {
		           
		$('ul.archive li li').hide();
		
		$('ul.archive > li > a').click(function(event) {  
			event.preventDefault();
			if ($(this).parent('li.active').size()) {    
				$(this).parent('li').attr('class', '');
			    $(this).siblings('ul').children('li').hide('200');
			}
			else { 
				$(this).parent('li').attr('class', 'active');
			    $(this).siblings('ul').children('li').show('200');  
			} 
		}); 
		
		 $('ul.archive > li > ul > li > a').click(function(event) {  
                event.preventDefault();
				if ($(this).parent('li.active').size()) {    
					$(this).parent('li').attr('class', '');
				    $(this).siblings('ul').children('li').hide('200');
				}
				else { 
					$(this).parent('li').attr('class', 'active');
				    $(this).siblings('ul').children('li').show('200');  
				} 
			});
	}
}
function display_cto(){
	$('#call-to-action').slideToggle('slow');
}

function flowplayerListener() {  
	if (typeof(flowplayer)!='undefined'){
		flowplayer(".play", {src: "/js/flowplayer/flowplayer-3.2.2.swf", wmode: 'opaque'}, { //wmode param prevents video from overlapping modal window
			clip: {
				"autoPlay": false,
				"image": true,
				"start": 0,
				"autoBuffering" : true
			}
		});
		
		flowplayer(".startnow", {src: "/js/flowplayer/flowplayer-3.2.2.swf", wmode: 'opaque'}, { //wmode param prevents video from overlapping modal window
			clip: {
				"autoPlay": true,
				"image": true,
				"start": 0,
				"autoBuffering" : true
			}
		});
	
	} //if
} //fn

function equalHeight(){
	var top_height = 0;
	$('div.equal-height:first').siblings('div.equal-height').andSelf().each(function(){
        if (top_height < $(this).height())
            top_height = $(this).height();
	}).height(top_height);
}

//fix the positioning for the bottom three blocks of the home page
function blockLayoutFix(){
	$('.home #sub-content .news + .news').css({'margin-left':'16px'});
}

function dataTables(){
	$('table.specialty tr:nth-child(2) td').css({'background-color':'#f0f0f0'});
}

$(function() {
	clickClear();
	slideInit();
	equalHeight();
	$('#slide_control').show();   
	archive();
	flowplayerListener();
	blockLayoutFix();
	dataTables();
	$('#videolist').slideDown();
});

