var closePopUps = function(){
		$(".popup").each(function(){
			$(this).fadeOut("fast");
		});
		$("#backgroundPopup").fadeOut("fast");
}

$(document).ready(function(){
	$("#menu").corner("round br 25px");
	$("#menu h3").corner("round tr br");
	$("#menu ul li").corner("round tr br");
	$("h1").corner("round 15px");
	$("#content h3").corner("round");
	$("#content h2").corner("round");
	//IE & safari choke on this
	//$("#header ul li").corner("round");
	$("#content a").corner("round 3px");
	$("#footer").corner("round 10px");
	
	if (!$.browser.msie) {
		$(".popup").corner("round 15px");
	}
	//$(".popup img").corner("round 15px");
	$(".photo_title").corner("round 15px");
	
	//$("#backgroundPopup").opacity(40);
	$("a.photo_zoom").click(function(event){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;

	   	event.preventDefault();
	   	$('#backgroundPopup').css({"background-color":"#000", "opacity": 0.75 }).fadeIn("fast");
	   	var popup = $(this).parent().find(".popup");
		popup.fadeIn("fast");//
		popup.css({
				"top": windowHeight/2-(popup.height()/2),
				"left": windowWidth/2-(popup.width()/2)
			});
	 });

	$('#backgroundPopup').click(closePopUps);
	$('.popup a').click(function(event){event.preventDefault();closePopUps();} );
	//$('ul.alternating li:odd').addClass('odd');
	//$('ul.alternating li:even').addClass('even');
	$('dl dd:odd').addClass('odd');
	$('dl dd:even').addClass('even');
	
	onAfterCycle = function() {
	    var max_image_height = 0
	    $('#rotator img').each(function() {max_image_height = Math.max(this.height, max_image_height);} )
	    $('#rotator').height(max_image_height)

	    var max_image_width = 0
	    $('#rotator img').each(function() {max_image_width = Math.max(this.width, max_image_width);} )
	    $('#rotator').width(max_image_width)


	    $('#rotator img').each(function(){ $(this).css({'margin-top' : (max_image_height - this.height)/2 } );})
	}

	$('#rotator').cycle({
		fx: 'scrollRight',
		timeout: 6000,
		speed: 1300,
		before: onAfterCycle,
		after: onAfterCycle
	});
	//onAfterCycle();
	//$('#rotator img').ready(function(){onAfterCycle()});
	//alert("ready");
	$(window).load(
	  function(){
    	onAfterCycle();
  	  }
	)
});
