	$(document).ready(function(){

		//Horizontal Sliding and gallery grid change
		$('.boxgrid.slideright').hover(function(){
			$(".cover", this).stop().animate({left:'225px'},{queue:false,duration:300});
			changeGrid($(this).attr('id'));
		}, function() {
			$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
			returnToNormal();
		});

        /***
         On mouse over, change all pictures to something relevant to the currently hovered gallery link
         On mouse out, change them back to what they were originally
        ***/

        // Change the grid of images to a set relevant to the currently hovered gallery
        function changeGrid(current_box) {

            var gallery_number = '00';
            var j = 1;
            var new_source = '';
            var path = 'images/gallery/';
            var prefix = 'sy_cst_part';

            $('#gallery img').each( function(i) {
                if($(this).parent().attr('id') == current_box)
                    gallery_number = '0' + i;
            });

            $('#gallery img').each( function(i) {
                if(($(this).attr('class') == 'cover') && ($(this).parent().attr('id') != current_box)) {
                    new_source = path + prefix + gallery_number + '0' + j + '.jpg';
                    $(this).attr('src', new_source);
                    j++;
                }
            });
        }

        // Return the pictures back to their original sources
        function returnToNormal() {

            $('#rhubarb img').attr('src', 'images/gallery/sy_cst_01.jpg');
            $('#hush img').attr('src', 'images/gallery/sy_cst_02.jpg');
            $('#huff img').attr('src', 'images/gallery/sy_cst_03.jpg');
        }
	});
