/**********************************************
	Carousel Script
	
	This script uses the jcarousel lib
	to scroll through gallery images
	
	Written by: 
		Adam Quaile, adamquaile@gmail.com
		www.62degrees.co.uk

**********************************************/

$(document).ready(function() {
	$('.expand').click(function() {
		$('#event-description').animate({
			height: '400px'
		})
		$('#gallery').animate({
			height: '0px'
		})
		$('.expand, #gallery-controls').hide();
		$('.collapse').show();
	})
	$('.collapse').click(function() {
		$('#event-description').animate({
			height: '5.3em'
		})
		$('#gallery').animate({
			height: '392px'
		})
		$('.collapse').hide();
		$('.expand, #gallery-controls').show();
	})
	
	
    $('.prev').click(function() {
    	var current = $('#gallery .wrapper').css('left').substring(0, $('#gallery .wrapper').css('left').length-2);
    	var extra   = $('#gallery img').width();
    	var max = $('#gallery').attr('meta:max');
    	var ease = parseInt(current) + parseInt(extra);
    	ease = (ease > 0) ? max : ease;
    	
    	$('#gallery .wrapper').animate({
    		left: (ease % max)+'px'
    	}, 'slow')
    })
    $('.next').click(function() {
    	var current = $('#gallery .wrapper').css('left').substring(0, $('#gallery .wrapper').css('left').length-2);
    	var extra   = $('#gallery img').width();
    	var max = $('#gallery').attr('meta:max');
    	var ease = parseInt(current) - parseInt(extra);

    	
    	$('#gallery .wrapper').animate({
    		left: (ease % max)+'px'
    	}, 'slow')
    })
});

