$(document).ready(function(){
	
	//apply form validation
	if($('#SiteNewsletterForm').length > 0 ){ // check if element is on page
		$("#SiteNewsletterForm").validate({
			rules: {
				txt_email: {
					required: true,
					email: true
				},
				txt_firstname: "required",
				txt_lastname: "required",
				txt_country: "required"
			},
			messages: {
				txt_email: "Please enter your email address.",
				txt_firstname: "Please enter your first name.",
				txt_lastname: "Please enter your last name.",
				txt_country: "Please enter your country name."
			}
		});
	}

	if($('#header #banner #strapline h2').length > 0 ){ // check if element is on page
		$("#header #banner #strapline h2").animate({opacity: 0.7}, 1500 );
	}
	 
	 // override some default options	
	if($('#art-festivals #main #main-center-panel ul.events-expander li .details').length > 0 ){ // check if element is on page
		$('#art-festivals #main #main-center-panel ul.events-expander li .details').expander({
			slicePoint: 0,  // default is 100,														 
			expandText: '<p>Festival information &gt;</p>',  // default is '[read more]'
			userCollapseText: '[collapse event]',  // default is '[collapse expanded text]'
			userCollapsePrefix: '', // text to come before the re-collapse link
			expandPrefix:     '' // text to come before the expand link
		});
	}
	
	if($('#booking #main #main-center-panel ul.events-expander li .details').length > 0 ){ // check if element is on page
		$('#booking #main #main-center-panel ul.events-expander li .details').expander({
			slicePoint: 0,  // default is 100,														 
			expandText: '<p>Booking information &gt;</p>',  // default is '[read more]'
			userCollapseText: '[collapse event]',  // default is '[collapse expanded text]'
			userCollapsePrefix: '', // text to come before the re-collapse link
			expandPrefix:     '' // text to come before the expand link
		});
	}
	
	if($('#events #main #main-center-panel ul.listing li .details').length > 0 ){ // check if element is on page
		$('#events #main #main-center-panel ul.listing li .details').expander({
			slicePoint: 0,  // default is 100,														 
			expandText: '<p>More detail &gt;</p>',  // default is '[read more]'
			expandEffect:     'fadeIn',
			userCollapseText: '[collapse event]',  // default is '[collapse expanded text]'
			userCollapsePrefix: '', // text to come before the re-collapse link
			expandPrefix:     '' // text to come before the expand link
		});
	}
	
	if($('#who #main #main-center-panel ul.events-expander li .details').length > 0 ){ // check if element is on page
		$('#who #main #main-center-panel ul.events-expander li .details').expander({
			slicePoint: 0,  // default is 100,														 
			expandText: '<p>Contact information &gt;</p>',  // default is '[read more]'
			expandEffect:     'fadeIn',
			userCollapseText: '[collapse event]',  // default is '[collapse expanded text]'
			userCollapsePrefix: '', // text to come before the re-collapse link
			expandPrefix:     '' // text to come before the expand link
		});
	}
	
	if($('#who #main #main-right-panel ul.events-expander li .details').length > 0 ){ // check if element is on page
		$('#who #main #main-right-panel ul.events-expander li .details').expander({
			slicePoint: 0,  // default is 100,														 
			expandText: '<p>Contact information &gt;</p>',  // default is '[read more]'
			expandEffect:     'fadeIn',
			userCollapseText: '[collapse event]',  // default is '[collapse expanded text]'
			userCollapsePrefix: '', // text to come before the re-collapse link
			expandPrefix:     '' // text to come before the expand link
		});
	}

	if($('#event_date').length > 0 ){ // check if element is on page
		$('#event_date').datepicker({ 
			dateFormat: 'dd/mm/yy',
			altField: '#p_date',
			altFormat: 'yy-mm-dd' 
		});
	}
	
	if (document.getElementById("galleria")){
		jQuery(function($) {
			
			$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
			$('.nav').css('display','none'); // hides the nav initially
			
			$('#prev').click(function(){
				$.galleria.prev();
				return false;
			});
			$('#next').click(function(){
				$.galleria.next(); 
				return false;
			});
			$('ul.gallery_demo').galleria({
				history   : true, // activates the history object for bookmarking, back-button etc.
				clickNext : true, // helper for making the image clickable
				insert    : '#main_image', // the containing selector for our main image
				onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
					
					// fade in the image & caption
					if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
						image.css('display','none').fadeIn(1000);
					}
					caption.css('display','none').fadeIn(1000);
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// fade out inactive thumbnail
					_li.siblings().children('img.selected').fadeTo(500,0.3);
					
					// fade in active thumbnail
					thumb.fadeTo('fast',1).addClass('selected');
					
					// add a title for the clickable image
					image.attr('title','Next image >>');
					$('.nav').css('display','block'); // shows the nav when the image is showing
				},
				onThumb : function(thumb) { // thumbnail effects goes here
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '0.3';
					
					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					
					// hover effects
					thumb.hover(
						function() { thumb.fadeTo('fast',1); },
						function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
					)
				}
			});
		});
	}
	
	if(jQuery.fn.showhide){
		//apply show hide plugin for use in gallery
		if($('a.showhide').length > 0 ){
			$('a.showhide').showhide({
				event:'mouseover'
			});
		}
	}

	$(document).pngFix(); 


});