$(function(){
    $("div#carousel").jCarouselLite({
        btnPrev: "img#prev",
        btnNext: "img#next",
        visible: 6
    });
    
    //load first image
    loadThumbnail($("div#carousel img.selected"));
    
    //set change action
    $("div#carousel img").click(function(){
        loadThumbnail($(this));
    });
    
    //preload images
    $("div#carousel img").each(function(){
        $("<img>").attr("src", $(this).attr("src").replace("height=100","height=255"));
    });
    
    //preload full size
    $("div#carousel img").each(function(){
        $("<img>").attr("src", $(this).attr("src").replace("height=100","height=475"));
    });
    
    //select next when scrolling
    $("img#next").click(function(){
        loadThumbnail($("div#carousel img.selected").parent().next().children());
    });
    $("img#prev").click(function(){
        loadThumbnail($("div#carousel img.selected").parent().prev().children());
    });
    
    //lightbox main image
    $("a#full-size").lightbox({
        fileLoadingImage:"images/loading.gif",
        fileBottomNavCloseImage:"images/lightbox/closelabel.gif"
    });
    
});

var loadThumbnail = function($thumbnail){
    //update image
    $("a#full-size img").fadeOut("normal",function(){
        $(this).attr("src", $thumbnail.attr("src").replace("height=100","height=255")).load(function(){
            $(this).fadeIn("normal");
        });
    });
    
    //src
    $("a#full-size").attr("href", $thumbnail.attr("src").replace("height=100","height=475"));
    
    //alt attribute
    $("a#full-size img").attr("alt", $thumbnail.attr("alt"));
    
    //title attribute
    $("a#full-size").attr("title", $thumbnail.attr("alt"));
    
    //remove selected
    $("div#carousel img.selected").removeClass("selected");
    
    //set selected
    $thumbnail.addClass("selected");
};

//google analytics
/*
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {var pageTracker = _gat._getTracker("UA-6889705-1"); pageTracker._trackPageview();} catch(err) {}
*/
