
/*===============================================================================
	site.js
	John Larson
	
	Miscellaneous script for interactive bits.
	

===============================================================================*/

	dbug.enable();
	App = {};

window.addEvent('domready', function() {
	App.contactFormOpen = false;
	App.roar = new Roar({
		duration: 8000,
		position: 'upperRight',
		margin: {x: 30, y: 20}
	});
	App.helloCount = 0;
	App.windowScroller = new Fx.Scroll(window);
	prepFileInputStyling('theFileInput', 235, true);
	
});	
	
	function submitContactForm(theForm) {
		
		if(theForm.name.value == '') {
			alert('Please enter your name.');
			theForm.name.focus();
			return false;
		}
		if(theForm.email.value == '') {
			alert('Please enter your email.');
			theForm.email.focus();
			return false;
		}
	}
	
	function completeContactSubmission() {
		$('contactFormThanks').setStyle('height', $('contactForm').getSize().y);
		swapSections('contactForm', 'contactFormThanks');
	}
	
	var helloMessageSet = ['<h3>Heya,</h3><br />How\'s it going?', 
		'I think my headshot looks better at the larger size.<br /><br />What do you think?',
		'It was actually taken by my talented and lovely fianc&eacute;e, Tracy!<br/><br /><a href="http://www.tracycarolyn.com">www.tracycarolyn.com</a>',
		'You should let me know you clicked on me so many times when we talk... it\'ll totally make my day.',
		'Think I had fun making this little easter egg?<br /><br />You betcha!',
		'That\'s all of the lines, I promise.<br /><br />It just repeats from here.'];
	
	function toggleJohn() {
		if(App.johnIsShowing) return;
		App.johnIsShowing = true;
		$('johnImage').tween('width', 270);
		$('helloDiv').set('html', helloMessageSet[App.helloCount % helloMessageSet.length]);
		App.helloCount++;
		$('helloDiv').fade('in');
		shrinkJohn.delay(4000);
		$('johnImage').setStyle('cursor', 'default');
	}
	
	function shrinkJohn(johnImage) {
		$('johnImage').tween('width', 110);
		$('helloDiv').fade('out');
		App.johnIsShowing = false;
		$('johnImage').setStyle('cursor', 'pointer');
	}
	
/*===============================================================================
/* SECTION::Effects Utilities */

	function swapToHoverSrc(theImage) {
		var ext = theImage.src.substring(theImage.src.length-3);
		if(theImage.src.indexOf('_on') == -1)
			theImage.src = theImage.src.replace('.' + ext, '_on.' + ext);
	}
	function swapFromHoverSrc(theImage) {
		var ext = theImage.src.substring(theImage.src.length-3);
		theImage.src = theImage.src.replace('_on.' + ext, '.' + ext);
	}
	
	
	function swapSections(oldSection, newSection, duration) {
		
		oldSection = $(oldSection);
		newSection = $(newSection);
		
		if(!duration)
			duration = 500;
		
		if(newSection.style.display == 'none') { // only swap if not already swapped!
			var oldSectionFx = oldSection.get('tween', { property : 'opacity', duration : duration });
			var newSectionFx = newSection.get('tween', { property : 'opacity', duration : duration });
			oldSectionFx.start(1,0).chain(function() {
				newSection.style.visibility = 'hidden';
				oldSection.style.display = 'none';
				newSection.style.display = '';
				newSectionFx.start(0, 1);
			});
		}
	}



	function prepFileInputStyling(theInput, width, isOneLine) {
		
		theInput = $(theInput);
		if(!theInput) return;
		
		var fakeFileUpload = new Element('div');
		fakeFileUpload.className = 'fakeFile verticalMiddle';
		var newInput = (new Element('input')).addClass('verticalMiddle').addClass('textfield');
		newInput.type = 'text';
		if(parseInt(width, 10) > 0) {
			newInput.setStyle('width', width);
			fakeFileUpload.setStyle('width', (width + 80) + 'px');
		}
		
		fakeFileUpload.appendChild(newInput);
		var image = (new Element('img')).addClass('verticalMiddle');
		image.src='images/buttonBrowse.gif';
		fakeFileUpload.appendChild(image);
		
		var parentDiv = $(theInput.parentNode);
		theInput.className = 'stealthFile verticalMiddle';
		parentDiv.appendChild(fakeFileUpload);
		parentDiv.addClass('verticalMiddle');
		theInput.onchange = theInput.onmouseout = function () {
			newInput.value = this.value;
		}
	}
	
/* END SECTION::Effects Utilities
===============================================================================*/
