$(document).ready(function(){

    $(".photo_gallery").hide(function(){
    	$(".page_0").show();
    	$(".page_0 img").show();
    });
    

    $('.page_0 img.photo_tn').hide().load(function(){ // Hide image and once it loads...
            $(this).each(function(){ // Loop through each
            //alert("test");
                    var imgWidth = $(this).width();
                    var imgHeight = $(this).height();
                    // If image is landscape...
                    if(imgWidth > imgHeight) {
                            $(this).height(144);
                    // If image is portrait...
                    } else if(imgWidth < imgHeight) {
                            $(this).width(144);
                    // If image is perfectly square...
                    } else {
                            $(this).width(144);   
                    }
                    $(this).show(); // Show scaled image
                    $(this).removeClass("photo_tn");
                    
            });           


    });
    
	url = $('#first_image').attr('href');
	title = $('#first_image').attr('title');
	$("#photo_container").find('img').attr('src',url);
	$("#photo_container").find('img').hide().load(function() {
		var imgWidth = $("#photo_container").find('img').width();
		//alert(imgWidth);
        if (imgWidth > 481) {
        	 $("#photo_container").find('img').width(481);
        }
		$("#photo_container").find('img').show();
	});
	
	
	
	$("#photo_title").html(title);
    
    

	$("a.thumb").click(function(){
		url = $(this).attr('href');
		title = $(this).attr('title');
		$("#photo_container").find('img').attr('src',url).hide().load(function() {
			var imgWidth = $("#photo_container").find('img').width();
			//alert(imgWidth);
	        if (imgWidth > 481) {
	        	 $("#photo_container").find('img').width(481);
	        }
			$("#photo_container").find('img').show();
		});
		
		
		
		$("#photo_title").html(title);
		return false;
	});
	
	$(".pagination").click(function(e){
	
		e.preventDefault();
		list_to_show = $(this).attr('href');
		$(".photo_gallery").hide();
		$("."+list_to_show).show();
		
		
		
		
		$("."+list_to_show +" img.photo_tn").hide(function(){ // Hide images 
                $(this).each(function(){ // Loop through each
                        var imgWidth = $(this).width();
                        var imgHeight = $(this).height();
                        // If image is landscape...
                        if(imgWidth > imgHeight) {
                                $(this).height(144);
                        // If image is portrait...
                        } else if(imgWidth < imgHeight) {
                                $(this).width(144);
                        // If image is perfectly square...
                        } else {
                                $(this).width(144);   
                        }
                        $(this).show(); // Show scaled image
                        $(this).removeClass("photo_tn");
                });
        });		
	});
	
	$("#photos_years").change(function() {
        var oldpath = window.location.pathname;
        var newpath = "http://" + window.location.host + $('option:selected', this).val();
        window.location = newpath;
    });       
	
});

