var gallery

var list_down = false

var current_image
var total_images

$(function(){

		
	$(".gallery_list").hide()
	$(".selected").show()

	$(".gallery_list a").bind("click", function(){
		new_img = $(this).attr("href")
		
		$("#main_img").fadeOut("slow", function(){
			$("#main_img").attr({
				src: new_img
			})
		
			$("#main_img").fadeIn("slow")	;
		})
		
		return false
	})
	
	//Gallery selection
	$("#gallery_select").hide()
	$("#link_recent_weddings").bind("click", function(){
		if(!list_down){
			$("#gallery_select").slideDown(function(){
				list_down = true	
			})
		}
		else{
			$("#gallery_select").slideUp(function(){
				list_down = false
			})
		}
		return false	
	})
	
	$("#gallery_select a").bind("click", function(){
		gallery = $(this).attr("href")
		$(".selected").fadeOut(function(){
			$(".selected").removeClass("selected")
			$("#"+gallery).addClass("selected")
			$(".selected").fadeIn(function(){
				$(".selected a:first").click()
			})	
			
			
			
		})
		
		return false
	})
	
	//Rollover effect
	$(".gallery_list img").fadeTo(100, 0.5)
	$(".gallery_list img").bind("mouseover", function(){
		$(this).fadeTo(100, 1)
	})
	$(".gallery_list img").bind("mouseout", function(){
		$(this).fadeTo(100, 0.5)
	})
	
	
	/* Home Gallery
	***************************/
	
	total_images = $('.home_image').length
	$('.home_image').hide()
	current_image = Math.floor(Math.random()*(total_images+1))
	$("#main_img_"+current_image).fadeIn()
})

setInterval ( 'next_image()', 3000 );

function next_image(){
	if(current_image < total_images){
		$("#main_img_"+current_image).fadeOut(function(){
			current_image ++
			$("#main_img_"+current_image).fadeIn()
		})
	}
	else{
		$("#main_img_"+current_image).fadeOut(function(){
			current_image = 1
			$("#main_img_"+current_image).fadeIn()
		})
	}
}