// JavaScript Document
 $(document).ready(function() {
// do stuff when DOM is ready
    $('h1').each(function() {
      string = $(this).text();
      filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
      $(this).html('<img src="/cmsimages/title-' + filename + '.jpg" alt="' + string + '" />');
    });

	/*
	$('#modalBG, #modalClose').click(function(){
		closeModal();
	});
	*/
	
	
	//SLIDESHOW

	$('ul#slideshow').innerfade({
	speed: 1000,
	timeout: 5000,
	type: 'sequence',
	containerheight: 	'220px',
	slide_timer_on: 	'yes',
	slide_ui_parent: 	'slideshow',
	slide_ui_text:		'null',
	pause_button_id: 	'null',
	slide_nav_id:		'slideshow'
	});

	$('span.slidehover').hover(function(){
		slidenum = $(this).attr('rel');
		if (slidenum) slidenum -= 1;
		if(!$("ul#slideshow").hasClass('paused')) $.pause();
		$('ul#slideshow li').fadeOut();
		$('ul#slideshow li:eq('+ slidenum +')').fadeIn();
	});
	
	//END SLIDESHOW
  
	// scrollbars stuff
	$('#uparrow').click(function(){
		$('.scroll-pane')[0].scrollBy(-280);
	});
	
	$('#downarrow').click(function(){
		$('.scroll-pane')[0].scrollBy(280);
	});
	
	$('.scroll-pane').jScrollPane({scrollbarWidth: 16, scrollbarMargin: 10, animateTo: true, reinitialiseOnImageLoad: true, showArrows: true, dragMinHeight:60, dragMaxHeight:60 });

	//topnav image replacement
	
	$('#headernav ul.navtop li a').each(function() {
      string = $(this).text();
      filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
      $(this).html('<img src="/cmsimages/nav-' + filename + '.png" alt="' + string + '" />');
      $(this).css({height: '17px', overflow: 'hidden'});
      $(this).children('img').css({marginTop: '-29px'});
      
      $(this).hover(function(){
      	thismargin = $(this).children('img').css("margin-top");
      	$(this).children('img').css({marginTop: '0px'});
      },
      function(){
      	$(this).children('img').css({marginTop: thismargin});
      });
    });
    
    $('#headernav ul.navtop li.selected a img').css({marginTop: '0px'});
    
    // FORM VALIDATION
		$.extend($.validator.messages, {  
		  required: "",  
		  email: "Email not valid"
		});
		$("#contactForm").each(function(){
			this.reset();
		});

		$("#contactForm").validate({
	 
			 errorPlacement: function(error, element){
			 	//error.appendTo( element.prev("label") );
			 }
			 
		});
		// END FORM VALIDATION
	
});


/* 
function openModal(){
	$('#modalBG').animate({opacity: 0.5}, 500).show();
	$('.modal').center({vertical:false}).show();
}

function closeModal(){
	$('#modalBG').hide();
	$('.modal').hide();
	//removes the swf in the modal
	$('#movie').innerHTML = "";
	//makes it ready for the next  swf
	$('#movie').append('<div id="movie">You need Flash to see this move.</div>');
}
*/



function loadVid(movie){		
	var flashvars = {};
	var params = {
	allowfullscreen: "true",
	allowscriptaccess: "always",
	wmode:"transparent"
	};
	var attributes = {
	id: "VideoPlayback"
	};
	swfobject.embedSWF("cmsflash/" + movie + ".swf", "movie", "620", "348", "9.0.0", "", flashvars, params, attributes);	
	
	
	$('.modal').modal({onClose: function (dialog) {
			var bob = dialog;
			//removes the swf in the modal
			dialog.orig[0].innerHTML = "";
			//gets it ready for the next video
			$(dialog.orig[0]).append('<div id="movie">You need Flash to see this move.</div>');
			$.modal.close(); // must call this!
		}});
	
};



