/**
 * js_main.js
 */

/**
 * animateFeatureTray
 *
 * @param integer steps is how many step and in what direction
 */
function animateFeatureTray ( steps )
{
	window.featureCurrentPosition += steps;
	var offset = - Math.round(window.featureWidth * window.featureCurrentPosition / window.featurePicsPerTray) + 6;
	var imageCount = jQuery('.ngg-gallery-thumbnail-box').length;
	var imageWidth = jQuery('.ngg-gallery-thumbnail-box').width();
	var featureWidthTotal = (imageCount-4) * imageWidth;
	
	if (offset > 0) {
		jQuery('#featureTray').animate({
			'left': - featureWidthTotal + 5
		});
		window.featureCurrentPosition = imageCount - window.featurePicsPerTray;
	}
	else if (offset < - featureWidthTotal) {
		jQuery('#featureTray').animate({
			'left': 4
		});
		window.featureCurrentPosition = 0;
	}
	else {
		jQuery('#featureTray').animate({
			'left': offset
		});
	}
}

/**
 * document ready, add handlers...
 */
jQuery(document).ready(function () {
	
	// add "last" to nav...
	jQuery('#nav li:last').addClass('last');
	
	// configure featureTray...
	window.featureWidth = jQuery('#featureWrap').width();
	window.featureCurrentPosition = 0;
	window.featurePicsPerTray = 4;
	
	// slide the featureTray...
	jQuery('#featureWrap .pointerL').bind('click', function () {
		animateFeatureTray(-1);
		return false;
	});
	jQuery('#featureWrap .pointerR').bind('click', function () {
		animateFeatureTray(1);
		return false;
	});
	
	// hide & show the text in the input boxes...
	jQuery('#mc_mv_FNAME').bind('focus', function () {
		if( typeof(window.mcInputName) == 'undefined') {
			window.mcInputName = this.value;
			this.value = '';
		}
	});
	jQuery('#mc_mv_FNAME').bind('blur', function () {
		if( typeof(window.mcInputName) !== 'undefined' && this.value == '') {
			this.value = window.mcInputName;
			window.mcInputName = undefined;
		}
	});
	jQuery('#mc_mv_EMAIL').bind('focus', function () {
		if( typeof(window.mcInputEmail) == 'undefined') {
			window.mcInputEmail = this.value;
			this.value = '';
		}
	});
	jQuery('#mc_mv_EMAIL').bind('blur', function () {
		if( typeof(window.mcInputEmail) !== 'undefined' && this.value == '') {
			this.value = window.mcInputEmail;
			window.mcInputEmail = undefined;
		}
	});
	
	// jquery rounded corners...
	//jQuery('.rounded').corners('12px');

});

