$(function() {
		   
	$(".png").supersleight(); // png fix for IE6
	
	Cufon.replace('.frutiger', { fontFamily: 'Frutiger', hover: true, hoverables: { strong: true, em: true } });
	Cufon.replace('.frutigerlc', { fontFamily: 'FrutigerLightCondensed', hover: true, hoverables: { strong: true, em: true } });
	Cufon.replace('#navigation ul li a', { fontFamily: 'Frutiger', textShadow: '#333 1px 2px', hover: true, hoverables: { strong: true, em: true } });
	Cufon.replace('#navigation ul li ul li a', { fontFamily: 'FrutigerLightCondensed', textShadow: '#333 1px 2px', hover: true, hoverables: { strong: true, em: true } });
	Cufon.replace('.lhfsarahscript', { fontFamily: 'LHFSarahScript', hover: true, hoverables: { strong: true, em: true } });
	$(".calendar table").livequery(function() {
		Cufon.replace('.calendar table', { fontFamily: 'Frutiger', hover: true, hoverables: { strong: true, em: true } });
	});

	// disable # without proper anchor
	$("a, area").click(function(){
		var href = $(this).attr("href");
		if(href == "#") return false;
	});
	
	$("ul.events-list li.no-title").each(function(){
		$(this).find("div.wysiwyg p:first").addClass("no-padding");
	});
	
	$("div#content div.wysiwyg tr").each(function(){
		$(this).find("th:last").addClass("no-border");
	});
	$("div#content div.wysiwyg tr").each(function(){
		$(this).find("td:last").addClass("no-border");
	});
	$("div#content div.wysiwyg tbody tr:last td").each(function(){
		$(this).addClass("last");
	});

	// search box
	var val = $("input#keyword").val();
	if(val == "") $("input#keyword").val("Search This Site");
	$("input#keyword").focus(function(){
		var val = $(this).val();
		if(val == "Search This Site") $(this).val("");
	});
	$("input#keyword").blur(function(){
		var val = $(this).val();
		if(val == "") $(this).val("Search This Site");
	});
	$("form#searchbox").submit(function(){
		var keyword = $("input#keyword").val();
		if(keyword == "" || keyword == "Search This Site"){
			alert("Please enter keyword");
			return false;
		}
	});
	$("select#gallerySelect").change(function(){
		var gallery = $(this).find("option:selected").val();
		if(gallery != "" || gallery != "undefined") {
			window.location = "multimedia.php?id="+gallery;
		}
	});
	
	$("a[rel=photos]").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("a[rel=popupmap]").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'fade'
	});
	
	$("a.videos").fancybox();

	$("a.youtube-popup").click(function() {
		$.fancybox({
            'autoScale'				: false,
            'transitionIn'			: 'none',
            'transitionOut'			: 'none',
            'title'					: this.title,
            'width'					: 600,
            'height'				: 400,
            'href'					: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'					: 'swf',
            'swf'					: {'allowfullscreen':'true'}
		});
        return false;
	});
	
	 $('.youtube-rotator a.video img').hover(function(){
		var $this = $(this);
		cycle($this);
		timer = setInterval(function(){ cycle($this); }, 1000);
	 }, function(){
		clearInterval(timer);
	 });
	
	$('#startdate,#enddate').datepick({onSelect: customRange, pickerClass: 'popupDatepicker', dateFormat: 'mm/dd/yyyy'}); 

});

var timer, count = 0, cycle = function(el){
var s = el.attr('src'),
	root = s.substring( 0, s.lastIndexOf('/') + 1 );
	count = (count+1)%3;
	el.attr('src', root + ((count===0) ? 'default' : count) + '.jpg');
};


function customRange(dates) { 
    if (this.id == 'startdate') $('#enddate').datepick('option', 'minDate', dates[0] || null);
    else $('#startdate').datepick('option', 'maxDate', dates[0] || null);
}
