/* ------------------
Global Scripts
Site: Cooch and Taylor
URL: www.coochtaylor.com
------------------ */

$(document).ready(function(){
	
	/* drop down menu animation */
	$('#nav > li.submenu').removeClass('submenu');
	$('#header > #nav > li').hoverIntent(function(){
		$(this).children('ul').slideDown();	
	},function(){
		$(this).children('ul').slideUp();	
	});
	
	/* search field hinter */
	/*$("#keywords").focus(function(){
		if ( $(this).val() == "Attorneys, Staff, Pages" ) {
			$(this).val('').removeClass('hint');
		}
	});
	$("#keywords").blur(function(){
		if ( !$(this).val() ) {
			$(this).val('Attorneys, Staff, Pages').addClass('hint');
		}
	});*/
	
	/* show hidden profile content in footer */
	$('#profileContent').hide();
	$('#profileLink').click(function(event){
		event.preventDefault();
		$('#profileContent').slideToggle();
	});
	
	/* toolbar */
	$('#toolbar li.submenu').removeClass('submenu');
	
	$('#toolbar li').hoverIntent(function(){
		$(this).children('ul').slideDown('slow');
	}, function() {
		$(this).children('ul').slideUp('fast');
	});
	
	/* font sizer */
	
	var originalFontSize = $('#mainContent').css('font-size');// save original font size
	
	// Reset Font Size
	$("#fontSize-reset").click(function(event){
		event.preventDefault();
		$('#mainContent').css('font-size', originalFontSize);
	});
	
	// Increase Font Size
	$("#fontSize-increase").click(function(event){
		event.preventDefault();
		var currentFontSize = $('#mainContent').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('#mainContent').css('font-size', newFontSize);
		return false;
	});
	
	// Decrease Font Size
	$("#fontSize-decrease").click(function(event){
		event.preventDefault();
		var currentFontSize = $('#mainContent').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('#mainContent').css('font-size', newFontSize);
		return false;
	});
	
	/* print page function */
	$('#toolbar_print').click(function(){
		window.print();
		return false;
	});
	
	/* hide breadcrumb if there are no crumbs */
	if ( $('#breadcrumb').children().length == 1 ) {
		$('#breadcrumb').hide();
	}
	
	/* content template 17 - fly out header */
	$('.template17').each(function(){
		var theFirstHeader = $(this).children('h1, h2, h3, h4, h5, h6').get(0); // selects the first header tag in the segment
		$(theFirstHeader).addClass('flyoutheader'); // adds class to style first header tag
	});
	
	
	/* basic lightbox */
	$(".lightbox").fancybox({
		'titleShow'		: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'autoDimensions': 'true',
		'overlayColor'	: '#000',
		'titlePosition' : 'inside'
	});
	
	/* media player */
	$('#leftSide a.media').media( { width: 555, height: 20 } );
	
	if ( $('#body-search')[0] ) { // search page scripts
		$('.filterList a').click(function(event){
			
			var theHref = $(this).attr('href');
			var theTargetId = theHref.substr(1);
			var myParent = $(this).parent('li');
						
			if( theTargetId == "" ) {
				event.preventDefault();
				$('.searchResultsDiv').fadeIn();	
			} else {
				event.preventDefault();
				$('.searchResultsDiv').hide();
				$(theHref).fadeIn();
			}
			
			$('.filterList li').removeClass('active');
			$(myParent).addClass('active');
			
		});
	} //  end search page scripts
	
	if ( $('#body-home')[0] ) { // home page scripts
		
		$('.slide .title').hide(); // hide all titles
		
		/* main feature slider */
		$('#mainFeature').cycle({
			fx: 'fade',
			delay: -1500,
			speed: 1500,
			timeout: 9000,
			before: function() {
				$(this).children('.background').stop().animate({ top: '-225px' }, 9500, 'linear');	 // begin background scrolling before transistion
			},
			after: function(){
				$(this).children('.title').stop().fadeTo( 4000, 1.0).delay(2000).fadeTo( 3000, 0.0); // fade in and fade out title
				$('.slide').not(this).children('.background').css( 'top' , '0px' ); // reset other background images 
			}
		});		
		
	} // end home page scripts
	
}); // close doc ready functions

$(window).load(function () { // run these functions after all images are loaded
	
  	/* image captions  */
	$('.imgCaption').each(function(){
		var theImage = $(this).find('img');
		var theImageWidth = theImage.width();
		var theImageHeight = theImage.height();
		var theCaption = $(this).children('span');
		$(this).css({ // set width and height of wrapper to image size
			width: theImageWidth + 'px',
			height: theImageHeight + 'px'
		});
		$(theCaption).hide(); // hide caption 
		$(this).hoverIntent(function(){ // show caption on hover
			theCaption.fadeIn('fast');
		},function(){
			theCaption.fadeOut('fast');
		});
	});
	
}); // close window load functions


