
$( document ).ready( function(){
	
	/**
	 * Datepicker for date of birth
	 */
	$("#dob").datepicker({
		dateFormat:'dd-mm-yy',
		changeMonth:true,
		changeYear:true,
		defaultDate:'-18y',
		yearRange:'1900:-18'
	});
	
	/**
	 * Fancybox
	 */
	/*$( 'a.fancy-gallery' ).click( function(){
		
		$("a.fancy-gallery").fancybox({
			'type' : 'image',
			'titlePosition'  : 'inside',
			'titleShow': false
		});
		return false;
	} );*/
	$("a.fancy-gallery").each(function() {
	var element = this;
	$(this).fancybox({
		'type' : 'image',
		'titlePosition'  : 'inside',
		'titleFormat'   : function() {
			var astring = '<div class="atfb"><!-- AddThis Button BEGIN -->'
+'<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;pubid=xa-4ee72ee04c968cdc"'
+ ' addthis:url="' + element.href + '"><img src="http://s7.addthis.com/static/btn/sm-share-en.gif" width="83" height="16" alt="Bookmark and Share" style="border:0"/></a>'
+'<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4ee72ee04c968cdc"></script>'
+'<!-- AddThis Button END --></div>';
			return astring;
		},
		onComplete: function(){
			addthis.button('.addthis_button');
		}
		});
	});

	
	
	/**
	 * Slider on some pages
	 */
	$('#home-slider-bg').cycle({ 
		fx: 'shuffle',
		shuffle: { 
			top:  -458, 
			left:  950 
		},
		timeout: 10000,
		pager:  '#nav',
		onPagerEvent: function(zeroBasedSlideIndex, slideElement){
			//alert(zeroBasedSlideIndex);
			changeSlideContent( zeroBasedSlideIndex );
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
			//alert(nextSlideElement);
			//alert(options.nextSlide);
			if( first == true ){
				first = false;
			} else {
				changeSlideContent( options.nextSlide );
			}
		}
	});
	
	/**
	 * Google Map
	 */
	$( '#google-map' ).gMap()
		.gMap( 'centerAt', { latitude: 52.628869, longitude: 1.303103, zoom: 16 } )
		.gMap('addMarker', { latitude: 52.628869, longitude: 1.303103 });
	
} );

var first = true;
function changeSlideContent( num ){
	$( '#slider-page-content' ).fadeOut('fast', function() {
		$( '#slider-page-content' ).html( $( '#slider_con_'+num ).html() ).fadeIn('slow');
	} );
}

