jQuery.fn.fadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

$(document).ready(function() {
	$('.clicknclear').click(function() {
		$(this).attr('rel', $(this).val());
		$(this).val('');
	}).blur(function() {
		if ($(this).val().length < 1)
			$(this).val($(this).attr('rel'));
	});

	/* TABS */
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	if (location.hash && location.hash.match(/^#tab/)) {
		// Activate selected tab 
		var selectedTab = location.hash;
		// Selected tab link (add active to surrounding li) - <ul class="tabs"><li><a href="#tabX">My Tab</a></li></ul>
		$("ul.tabs li a[href='" + selectedTab + "']").parent().addClass("active").show();
		// Selected tab content
		$(selectedTab).addClass('active').show();
	} else {
		// Activate first tab
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
	}

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class from other <li>
		$(this).addClass("active"); //Add "active" class to selected tab <li>
		$(".tab_content").hide(); //Hide all tab content 

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show().fadeIn('slow'); //Fade in the active ID content
		return false;
	});

		
	

	// Expandable content areas
	$('.expand-content').hide();
	$('#expand-link').click(function (e) {
		e.preventDefault();
		$('.expand-content').fadeToggle();
	});

	if (typeof jQuery.fn.fancybox == 'function')
		$('a[rel]="gallery"').fancybox({ 'zoomSpeedIn': 500, 'zoomSpeedOut': 500, 'overlayOpacity': 0.8 }); 


	// Apply date picker if loaded
	if (typeof jQuery.fn.datepicker == 'function')
		$('input.selectdate').datepicker({dateFormat: 'dd/mm/yy', showOn: 'button', buttonImage: '/skin/images/icon-calendar.gif', buttonImageOnly: true});


});
