// This is the website specific javascript file, anything that is site specific gets put in here

$(document).ready(function(){ 
 
	
	$('#s1').cycle({
		fx: 'fade',
		timeout:  5000,
		cssBefore: {  
        	left: 115,  
        	top:  115 
    	}
	});	
	
	$('#s2').cycle({
		fx: 'cover',
		timeout:  10000
		
	});	
	
	$('#navbar ul li:not(:last) a').append('&nbsp;-');
	$('.exhibition').each(function() {
		$(this).find('p:not(:first)').hide();
	});
	
//	$('.thumbs').jcarousel();
		init_gallery();
	
/*	$('.gallery .title').click(function() {
	
			init_gallery();

		return;
		if ($(this).parent().hasClass('open'))
			hide_galleries();
		else {
			$(this).parent().addClass('open');
			show_gallery();
		}
		
	
	});
	
*/	

	
	$('.thumbs a, .carousel a').each(function() {
		
		
		
		var $this = $(this);
		var img = $this.find('img');
		var href = $this.attr('href');
		if (!img.parent().hasClass('showing'))
			img.parent().animate({opacity:0.8});
		
		$this.hover(function() {
			img.parent().animate({opacity:1});
		}, function() {
			if (!img.parent().hasClass('showing'))
				img.parent().animate({opacity:0.8});
		});
		
	});
});

var $img;
var $gallery;
var index;
var count;
var $holder;
var $div;

function init_gallery() {
	if ($('.carousel').length == 0)
		return;

	$('.carousel').jcarousel();
		$div = $('#main_image');

	var new_hash = location.hash.replace('#/','');

	$img = $('a[href="'+new_hash+'"]:first');
//	$('.gallery .jcarousel-container').css('position','absolute').css('left','+99999px');
	if ($img.length) {	
		
	}
	else {
		$img = $('.carousel a:first')
		
	}
	show_image();
	
	$('.carousel a').click(function() {
		$img.removeClass('showing');
		$img.animate({opacity:0.8});
		$img = $(this);
		show_image();
		return false;
	})

	$('.next_image').click(function() {
			$img.parent().next().find('a').click();
			return false;
		});
		
	$('.previous_image').click(function() {		
			$img.parent().prev().find('a').click();
			return false;
		});
}

function hide_gallery() {

}

function check_prev_next() {
	if (index == 0)
		$('#main_image').find('.previous_image').hide();
	else
		$('#main_image').find('.previous_image').show();
		
	if (index == count - 1)
		$('#main_image').find('.next_image').hide();
	else
		$('#main_image').find('.next_image').show();
}

function show_image() {

	$img.animate({opacity:1});
	$img.addClass('showing');
	index = $img.parents('li').index();
	count = $img.parents('li').parent().children().length;
	location.hash = '#/'+$img.attr('href');
	$gallery = $img.parents('.gallery');
	$gallery.addClass('open');
	$('.gallery .jcarousel-container').css('position','absolute').css('left','-99999px');
	$('.gallery.open .jcarousel-container').css('position','relative').css('left','0px');

//	$gallery.find('.inner').show();
	check_prev_next();
	$('#image_pos').html(index+1);
	$('#image_count').html(count);
	show_main_holder();
	
	$('#watermark').css({
		position:'absolute',
		top:0,
		width:410,
		height:490,
		zIndex:1
	});
}

function show_main_holder() {

	
//	$.scrollTo($div,500,{offset:{top:-100}});
	$div.find('.title').html($img.attr('title'));
	$div.find('.description').html($img.parent().find('.description').html())
	
	$div.find('.image img').attr('src',($img.attr('href'))).show();

	
	}

