(function($) {
	// JavaScript Document
	$(document).ready(function(){
		//function initialize Carousel
		$(function() {
			$(".carousel").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				visible: 1,
				circular: false,
				btnGo:["#CarouselNav .1", "#CarouselNav .2","#CarouselNav .3", "#CarouselNav .4","#CarouselNav .5"],
				afterEnd: function(visible) {
					var idx = visible.prevAll('li').length;
				
					$("#CarouselNav li")
						.removeClass("CarouselCurrent")
						.eq(idx).addClass("CarouselCurrent");
				}
			});
		
			$("#CarouselNav li:first").addClass("CarouselCurrent"); 
		});
	
		//function initialize lightbox
		$(function() {
			$('#gallery a').lightBox({fixedNavigation:true});
		});

		//function initialize the date range Jquery UI
		$(function() {
		 	function formatDate(dat){
				var myDate = new Date( dat *1000);
				var theyear=myDate.getFullYear();
				var themonth=myDate.getMonth()+1;
				var thetoday=myDate.getDate();
				var dateFomated = thetoday+"/"+themonth+"/"+theyear;
				return dateFomated;
			}
			$("#slider-range").slider({
				range: true,
				min: 157766400,
				max: 1267747200,
				values: [157766400, 1267747200],
				slide: function(event, ui) {
					$("#amount").val('' + formatDate(ui.values[0]) + ' - ' + formatDate(ui.values[1]));
				}
			});
			if($("#amount").length > 0) $("#amount").val('' + formatDate($("#slider-range").slider("values", 0)) + ' - ' + formatDate($("#slider-range").slider("values", 1)));
		});

		//function to highlight selected items on the filter by author
		$(function() {
			$("#authorFilterList li a").attr("href", "javascript:void(0);");
			$("#authorFilterList li a").click(function () {
				$(this).toggleClass("authorSelected");
			})
			$("#moreAuthorsInput button").click(function () {
				var newAuthor =  $("#moreAuthorsInput input").val();
				$("#authorFilterList").append("<li><a href='javascript:void(0)' class='authorSelected'>"+newAuthor+"</a></li>");
			})
		})

		// undisguise email addresses
		$(function() {
			$(".PBPmail").each(function () {
				var email = $(this).html().replace(/ at /g,"@").replace(/ dot /g,".");
				$(this).before("<a href='mailto:"+email+"'>"+email+"<\/a>").remove();
			});
		})

		// clear search box on click when it contains defaultValue
		$(function() {
			$("#SphinxSearchForm_SphinxSearchForm_Search").click(function () {
				if($(this).attr('value')==$(this).attr('defaultValue')) $(this).attr('value','');
			})
		})

	 });
})(jQuery);