//Carry out tasks when page is loaded
$(document).ready(function(){					   
	
	
	//$("#reg-interest").validator();
	$("#reg-interest").validator({
		effect: 'wall', 
		container: '.form-error',
		
		// do not validate inputs when they are edited
		errorInputEvent: null
		
		// custom form submission logic  
		}).submit(function(e)  { 
		   
		   // when data is valid 
		   if (!e.isDefaultPrevented()) {
			   $(".form-error").html('');
		   }
		   else{
			   $("div#form-intro").html('');
		   }
	});	//closing registration form validation
	
	
	//RHS nav roll over logic
	$('#side-nav ul li a img').mouseover(
		function(){
			if( $(this).hasClass('active-page') === false ){
				var section = $(this).attr('src');
				var newButtonState = section.replace('-off','-on');
				$(this).attr('src', newButtonState );
			}			
		}
	);
	$('#side-nav ul li a img').mouseout(
		function(){
			if( $(this).hasClass('active-page') === false ){
				var section = $(this).attr('src');
				var newButtonState = section.replace('-on','-off');
				$(this).attr('src', newButtonState );
			}
		}
	);
	
	
	
	//logic for adding the iframes as needed when a user selects on of the top nav links.
	//done so as each iframe doesn't load it's content until the user clicks the link to show it.
	$('#top-nav ul li a').click(
		function(){
			var toLoad = $(this).attr('data-reveal-id')
			var modalUrls = new Array();
			modalUrls['modal-about'] = 'http://engage.webtrends.com/about/';
			modalUrls['modal-conference'] = 'http://engage.webtrends.com/conference/';
			modalUrls['modal-media'] = 'http://engage.webtrends.com/media-gallery/';
			modalUrls['modal-papers'] = 'http://engage.webtrends.com/call-for-papers/';
			modalUrls['modal-events'] = 'http://engage.webtrends.com/past-events/';
			$('#'+toLoad+' iframe').attr('src', modalUrls[toLoad] );		
		}
	);
	
	
	
	
	//Image preloading for side navigation
	preload(
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/welcome-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/agenda-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/speakers-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/travel-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/sponsor-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/training-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/competition-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/community-on.png",
		"http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/images/nav/party-on.png"
	)
	
	
	
	flowplayer(".player", "http://"+document.domain+"/wp-content/themes/engage-2011-theme/assets/js/flowplayer-3.2.7.swf",{
	clip: {
		  autoPlay: false
		  // possibly more clip config
		}
	});
	
	
	$("video").VideoJS();

	
	
});//CLOSING DOCUMENT READY




/**
*	GENERAL FUNCTIONS TO USE IN DOCUMENT.READY ABOVE
**/



// adds an effect called "wall" to the validator
$.tools.validator.addEffect("wall", function(errors, event) {
	// get the message wall
	var wall = $(this.getConf().container).fadeIn();
	
	// remove all existing messages
	wall.find("p").remove();
	
	// add new ones
	$.each(errors, function(index, error) {
		wall.append(
			"<p><strong>" +error.input.attr("visiblename")+ "</strong> - " +error.messages[0]+ "</p>"
		);		
	});
		
// the effect does nothing when all inputs are valid	
}, function(inputs)  {

});//closing validator function





function preload() {
	var images = new Array()
	for (i = 0; i < preload.arguments.length; i++) {
		images[i] = new Image()
		images[i].src = preload.arguments[i]
	}
}





