// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


$(document).ready(function(){

    $('#banner-thumbs, #banner-caption').supersleight();

    $('a[rel=category_images]').colorbox();

    // Custom Safe Mail routine for handling email links with custom text.
    $("a.safemail").each(function(){
        $(this).attr('href', 'mailto:' + $(this).attr('href').replace(/ at /,"@").replace(/ dot /g,"."));
    });

    // execute your scripts when the DOM is ready. this is a good habit
    $(function() {
        // initialize scrollable gallery
        $("div.scrollable-gallery").scrollable({
            size: 10
        }).mousewheel();
    });

    $(function() {
        // initialize scrollable banner
        $("div.scrollable-banner").scrollable({
            vertical:true,
            size: 4
        }).mousewheel();

    });

    $(function() {

        $(".items img").click(function() {

            // calclulate large image's URL based on the thumbnail URL (flickr specific)
            var url = $(this).attr("src");

            // get handle to element that wraps the image and make it semitransparent
            //            var wrap = $("#image_wrap").fadeTo("medium", 0.5);
            var wrap = $("#image_wrap");

            // the large image from flickr
            var img = new Image();

            // call this function after it's loaded
            img.onload = function() {

                // make wrapper fully visible
                wrap.fadeTo("fast", 1);

                // change the image
                wrap.find("img").attr("src", url);

            };

            // begin loading the image from flickr
            img.src = url;

        // when page loads simulate a "click" on the first image
        }).filter(":first").click();

        $(".showcase_items img").click(function() {

            var url = $(this).attr("src");

            var wrap = $("#image_wrap");

            var img = new Image();

            img.onload = function() {

                wrap.fadeTo("fast", 1);

                wrap.find("img").attr("src", url);

            };

            img.src = url;

            if(jQuery.trim($(this).attr('title')) == ''){
//                $("#banner-caption").css("visibility", "hidden");
                $("#banner-caption").hide();
            }else{
//                $("#banner-caption").css("visibility", "visible");
                $("#banner-caption").show();
            }
            $("#photo-caption").html($(this).attr('title'));

        }).filter(":first").click();
    });


});
