﻿$(function() {
$('.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
});

$(document).ready(function() {

    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    $("ul.topnav li span").click(function() { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.subnav").slideDown('slow').show(); //Drop down the subnav on click

        $(this).parent().hover(function() {
        }, function() {
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
        });

        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function() {
        $(this).addClass("subhover"); //On hover over, add class "subhover"
    }, function() {	//On Hover Out
        $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });

    $("ul.subnav li a").click(function() {
        window.location = $(this).href;
    });
});

$(".items img").click(function() {      
    // calclulate large image's URL based on the thumbnail URL (flickr specific)     
    var url = $(this).attr("src").replace("_t", "");      
    // get handle to element that wraps the image and make it semitransparent     
    var wrap = $("#image_wrap").fadeTo("medium", 0.5);      
    // 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();
