$(function(){



	// apply anchor of child to parent
	$('.product, #top-nav li, .event-wrap, #mod-news .news-wrap, .gallery-item, .cycle-text').click(function(){
		link = jQuery(this).find('a').attr('href');
		window.location = link;
	});



	// add class to final li in #top-nav
	$('#top-nav li').last().addClass("final-nav");



	// add class to final li in accordion
	$('#side-accordion .month').last().addClass("final-month");



	// add class to final li in #foot-nav
	$('#foot-nav a').last().addClass("final-nav");



	// add class to odd news items for zebra-effect
	$('#mod-events .event-wrap:odd').addClass("zebra");



	// add class to odd gallery items for zebra-effect for margins
	$('#spread .gallery-item:odd').addClass("zebra");


	// add br after 4th club to create new line
	$('#index-clubs a:nth-child(5)').after('<br />');



	// carousel
	$("#cycle-wrap").multipleElementsCycle({
		container: '#cycle',
		prev: '#cycle-prev a',
		next: '#cycle-next a',
		speed: 1000,
		start: 0,
		show: 4,
		showCount: 4
	});



	// accordion
	$('#side-accordion').accordion({
		header: '.accordion-header',
		active: '.selected',
		autoheight: false
	});


	// front page banner
	$('#banner-cycle').css('visibility' , 'visible').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 5000,
		pager:  '#banner-index-nav'
	});


	// gallery
	$('#gallery-main').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 0,
		pager:  '#gallery-thumbs',
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '.gallery-thumb:eq(' + idx + ')'; 
		}
	});


});

$(document).ready(function(){

	// Clear default function
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
	        // Textareas don't read val() function from jquery so we use normal js
	        if(default_value == ""){
	          default_value = this.value;
	        }
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("");
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value);
			});
		});
	};
	
	$('input.clear-default').clearDefault();
	$('textarea.clear-default').clearDefault();
	

});
