$(document).ready(function(){ 
	
	// Home Page Video Feature
	// strVimeoInitialID is set in the home/.masthead template
	if ($("#flash-player.home-player").length > 0) {
		
		swapVideo(strVimeoInitialID);
		$('#slider-list li a').click( function() {
			swapVideo($(this).attr('rel'));
			return false;
		});
		
	};
	
	// Home Page Slider Carousel
	$('#footer-images').cycle();
	$('#slider-stage').carousel('#previous', '#next');
	
	$("#contact-form").RSV({
			displayType: "display-html",
			errorFieldClass: "error",
			errorTextIntro: "<h3>Please fix the following errors.</h3>",
			errorTargetElementId: "error-results",
			rules: [
			"required,name,Please enter your name.",
			"required,email,Please enter your email address.",
			"valid_email,email,Please enter a valid email address."
			]
		});
	
	$("#street-form").RSV({
			displayType: "display-html",
			errorFieldClass: "error",
			errorTextIntro: "<h3>Please fix the following errors.</h3>",
			errorTargetElementId: "error-results",
			rules: [
			"required,name,Please enter your name.",
			"required,email,Please enter your email address.",
			"valid_email,email,Please enter a valid email address."
			]
		});
	$("#download-form").RSV({
			displayType: "display-html",
			errorFieldClass: "error",
			errorTextIntro: "<h3>Please fix the following errors.</h3>",
			errorTargetElementId: "error-results",
			rules: [
			"required,name,Please enter your name.",
			"required,email,Please enter your email address.",
			"valid_email,email,Please enter a valid email address."
			]
		});
	$("#entryform").RSV({
			displayType: "display-html",
			errorFieldClass: "error",
			errorTextIntro: "<h3>Please fix the following errors.</h3>",
			errorTargetElementId: "error-results",
			rules: [
			"required,approve,Please agree with the terms of use."
			]
		});
	// jquery stuff goes here!!
	$('A[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

	// $('#slider-list li a').click( function() {
	// 	// alert('here');
	// 	$('#flash-player').removeClass('hide');
	// 	$('#flash-player-completed').addClass('hide');
	// 	playIt($(this).attr('rel'));
	// 	return false;
	// })
	// $('#flash-player-completed a.player').click( function() {
	// 	// alert('here');
	// 	$('#flash-player').removeClass('hide');
	// 	$('#flash-player-completed').addClass('hide');
	// 	playIt($(this).attr('rel'));
	// 	return false;
	// })

});

/**
 * Swaps the vimeo video out with the new video ID
 *
 * @param string The vimeo video ID.
 * @return void
 * @author Jesse Bunch
 **/
function swapVideo(strVideoID) {
	
	// Get the target video's SWF URL & name
	
	

     // var strNewVidURL = "http://player.vimeo.com/video/" + strVideoID + "title=0&amp;byline=0&amp;portrait=0&amp;iframe=true";

	/*
    <iframe src="http://player.vimeo.com/video/15601746?title=0&amp;byline=0&amp;portrait=0" width="580" height="326" frameborder="0"></iframe>
   */


var strNewVidURL = "http://vimeo.com/moogaloop.swf?clip_id=" + strVideoID + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1"; 



	// Switch out the SWF
	var flashvars = {
		wmode: 'transparent',
		backcolor: '#3b2510',
		frontcolor: '#af7c49',
		lightcolor: '#dddc6ae',
		screencolor: '#000000'
	};
	var params = {
		wmode: 'transparent',
		allowfullscreen: 'true',
		allowscriptaccess: 'always'
	};
	var attributes = {wmode: 'transparent'};
	
	swfobject.embedSWF(strNewVidURL, "flash-player", "944", "551", "9.0.0","/content/swfobject/expressInstall.swf", flashvars, params, attributes);
	
	return false;
	
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
	else 
	countfield.value = maxlimit - field.value.length;
}

// add any other non-jquery js here, including swf object
