/*

Davenport Design & Advertising
www.davenportdesign.net

By Zach Raffensperger (March 2009)

core.js (requires jquery 1.3.2)

*/


$(document).ready(function() {

	// MORE/LESS TOGGLE (used on service page)
	$('.toggle').click(function() {
		speed = 200;
		a = $(this);
		oldTxt = a.attr('title');
		newTxt = '(less)';
		spans = a.parent().find('span');
		c = spans.eq(0);
		f = spans.eq(1);
		if (f.is(':hidden')) {
			c.hide(speed);
			f.show(speed * 2);
			a.text(newTxt);
		} else {
			c.show(speed);
			f.hide(speed * 2);
			a.text(oldTxt);
		}
	});
	
	// HOMEPAGE ANIMATION
	var mh = $('#masthead');
	if (mh.length > 0) {
		mh.children().hide(); // this fixes overlapping shadows during load
		mh.children().find('div:first').show();
		mh.innerfade({
			speed: 1000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '300px'
		});
	}
	
	// INPUT VALUE AUTOCLEAR AND REPLACE (requires class="input" and title="something")
	var inputs = $(".input");
	inputs.focus( function() {
		tag = $(this).get(0).tagName;
		if (tag == 'SELECT' || $(this).attr('title') == '') return;
		if (tag == 'INPUT') {
			if ($(this).attr('title') == $(this).val()) $(this).val('');
		} else if (tag == 'TEXTAREA') {
			if ($(this).attr('title') == $(this).text()) $(this).text('');
		}
		
	});
	inputs.blur(function() {
		tag = $(this).get(0).tagName;
		if (tag == 'SELECT' || $(this).attr('title') == '') return;
		if (tag == 'INPUT') {
			if ($(this).val() == '' || $(this).val() == ' ') $(this).val($(this).attr('title'));
		} else if (tag == 'TEXTAREA') {
			if ($(this).val() == '' || $(this).val() == ' ') $(this).text($(this).attr('title'));
		}
			
	});
	
	// STAFF PHOTO ENLARGEMENTS (this trickery is primarily in the css)
	$('.staff .photo').hover(
		function() {$(this).find('img').show(250);},
		function() {$(this).find('img').hide(500);}
	);
	
});
