/* JavaScript File Area Digital CMS	(Area Digital 4.2)				*/
/* functions.js 													*/
/* Modified january 05th 2010								 		*/
/* http://www.areadigital.org/ 									    */

$(document).ready(function() { 

// ------------------------------------ css - controls the first child and last child for IE browsers ---------------------------------------------------------
	
	if ($.browser.msie) { }

// ------------------------------ clean up margin - grabs the last element in a widget and add margin zero ----------------------------------------------------

	$('.factbox div *:last-child').css({'margin-bottom': '0', 'padding-bottom': '0'});
	$('.widget .data *:last-child:not(div, input, form, fieldset, dl, th, td, th > *, td > *, ul > *)').css({'margin-bottom': '0', 'padding-bottom': '0'});
	$('.widget .data p:last-child').css({'margin-bottom': '0', 'padding-bottom': '0'});
	
// ---------------------------------- target blank - checks for anchor tags that should be open in new window -------------------------------------------------

	$('a[rel=external]').attr({'target': '_blank'});
	$('a[rel=nofollow external]').attr({'target': '_blank'});

// ------------------------------------------ css - adds the even and odd classes to all tables  --------------------------------------------------------------

	$('table tr:nth-child(even)').addClass('even');
	$('table tr:nth-child(odd)').addClass('odd');

// --------------------------------------- prefill - moves the form label and adds them into the value -------------------------------------------------------
	
	$('.prefill').each(function (i) { var data = $(this).metadata(); this.value = decodeURI(data.label); });
	$('.prefill').blur(function() { var data = $(this).metadata(); if (this.value == '') this.value = decodeURI(data.label); });
	$('.prefill').focus(function() { var data = $(this).metadata(); if (this.value == decodeURI(data.label)) this.value = ''; });

// ------------------------------------ search - makes sure that the search directs to the correct page -------------------------------------------------------

	$('.search-field').each(function (i) { $(this).submit(function(){ $(this).attr('action', $(this).attr('action') + $('input[name=term]', this).val())}); });

// ---------------------------------------- teaser slider - slides the text panel element up and down ---------------------------------------------------------
	
	$('.teaser.slider:visible').each(function (i) {
		
		var startSize =  $('.caption', this).css('height');
		startSize = parseInt(new String(startSize).replace('px', ''));
		
		var height =  $('.teaser.slider img').height();
		$('.teaser.slider').css({'height' : height});
			
		$('.teaser.slider').hover(function () {
			
			var endSize = ($('.caption > p', this).height() + startSize + 12);
			
			if ($('.caption > p', this).height() != null)
				$('.caption', this).stop().animate({bottom: '0px', height: endSize + 'px'},{queue:false, duration:160});
		}, function () {
			if ($('.caption > p', this).height() != null)
				$('.caption', this).stop().animate({bottom: '0px', height: startSize + 'px'},{queue:false, duration:160});
		});
	});

// ------------------------------------------------------------------------------------------------------------------------------------------------------------

});


