$(document).ready(function() {
	
	// booking form expanders
	if($(".booking-wrapper fieldset.closed").length){
		$(".booking-wrapper fieldset.closed").children(".booking-optional").hide();
		$(".booking-wrapper fieldset.closed legend").click(function() {
		  $(this).parent().children(".booking-optional").slideToggle();
		  $(this).parent().toggleClass("closed","remove");
		  $(this).parent().toggleClass("open","add");
		});
		$(".booking-wrapper fieldset.open").click(function() {
		  $(this).children(".booking-optional").slideToggle();
		  $(this).toggleClass("open","remove");
		  $(this).toggleClass("closed","add");
		});
	}
	

	// datepicker
	if($(".datepicker").length){	
		$( ".datepicker" ).datepicker({
				dateFormat: 'dd MM yy',
				showOn: 'both',
				buttonImage: "/App_Themes/ECI/img/buttons/calendar.gif",
				buttonImageOnly: true
		});
	}


//	// datepicker 3 fields
//	if($(".datepicker").length){	
//		var altFormat1 = $( ".datepick" ).datepicker( "option", "altFormat" );
//		var altFormat2 = $( ".datepick" ).datepicker( "option", "altFormat" );
//		
//		$(function() {
//			$( ".datepicker" ).datepicker({
//				dateFormat: 'dd',
//				showOn: "button",
//				buttonImage: "img/buttons/calendar.gif",
//				buttonImageOnly: true,
//				altField: ( ".mm", ".yyyy" ),
//				altFormat: ( "mm", "yy" )
//			});
//		});
//	}
	
	// Set slider children to width of parent
	if($("div.equal").length){
		$.fn.setAllToMaxWidth = function(){
			return this.width( Math.min.apply(this, $.map( this , function(e){ return $(e).width() }) ) );
		};
		$("div.equal").setAllToMaxWidth();
	};
	
	// Setup Slider
	if($(".slider").length){
		$(".slider").scrollable({ size:1, items:'.items', clickable:false, circular:true, speed:600 }).autoscroll({ autoplay: true, interval: 3200 }).navigator();
	};
	
	// FitText
	if($(".headline").length){
		//$(".headline").fitText(1.2);
	};
	
	
	// Tabs
	if($("#tabs").length){
		$( "#tabs" ).tabs();
	};
	
	
	// Clear Form Labels
	$('input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
	
	// Gallery - galleria.aino.se
	if($(".gallery").length){
		
		$(".gallery").galleria({

			height:570,
			flickr: 'search:dublin college',
			flickrOptions: {
        		sort: 'date-posted-asc',
				max: 8,
				thumbSize: 'medium'
    		},
			imagePosition: 'top center',
			thumbnails: true,
			showCounter: false,
			showInfo: true,
			autoplay: 5000,
			showImagenav: true,
			transition: 'fadeslide',
			imageCrop: 'width',
			lightbox: true
			
		});
	}
	
	
});
