$(function() {

	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: 0, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: 1, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 6, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 5000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 'slow', // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: superbgimage_show, // function-callback show image
		onClick: superbgimage_click, // function-callback click image
		onHide: superbgimage_hide, // function-callback hide image
		onMousemove: superbgimage_mousemove // function-callback mousemove
	};

	// initialize SuperBGImage
	$('#thumbs1').superbgimage();

});

// function callback on hiding image
function superbgimage_hide(img) {
	$('#showtitle').hide();
}

// function callback on showing image
// get title and display it
function superbgimage_show(img) {
	$('#superbgimage').css('background', 'none');
	$('#superbgimage').append($('#showtitle'));
	$('#showtitle p.imagecount').html('image ' + img + ' of ' + $.superbg_imgIndex);
	if ($('#thumbs1').css('display') == 'block') {
		$('#showtitle p.title').html($('#thumbs1 a' + "[rel='" + img + "']").attr('title'));
	} else {
		$('#showtitle p.title').html($('#thumbs2 a' + "[rel='" + img + "']").attr('title'));
	}
	$('#showtitle').fadeIn('fast');
}

// function callback on clicking image, show next slide
function superbgimage_click(img) {
	$('#thumbs').nextSlide();
}

my_slideshowActive = false;

// function callback onmousemove, show and move pause-indicator
function superbgimage_mousemove(img, e) {
	if (my_slideshowActive && ($('#pause').length > 0)) { 
		$("#pause").css("top",(e.pageY + 20) + "px").css("left",(e.pageX + 20) + "px").show();
	}
}


$(function() {

	function update_superbgOptions() {
		// speed
		var newspeed = 'slow';
		var newinterval = 4000;
		var newtransitionout = 0;
		var newrandomtransition = 0;
		var newrandomimage = 0;
	}

	// hide other sets except the 1st
	$("#thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10").hide().addClass('hidden');

	// prev slide
	$('a.prev').click(function() {
		return $('#thumbs').prevSlide();
	});

	// next slide
	$('a.next').click(function() {
		return $('#thumbs').nextSlide();
	});

	// start slideshow
	$('a.start').click(function() {
		update_superbgOptions();
		return $('#thumbs').startSlideShow();
	});

	// stop slideshow
	$('a.stop').click(function() {
		my_slideshowActive = false;
		return $('#thumbs').stopSlideShow();
	});

	// load image set 1
	$('a.loadset1').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 2
	$('a.loadset2').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs2').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});
	
	// load image set 3
	$('a.loadset3').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs3').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 4
	$('a.loadset4').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs4').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 5
	$('a.loadset5').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs5').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 6
	$('a.loadset6').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs6').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs7, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 7
	$('a.loadset7').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs7').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs8, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 8
	$('a.loadset8').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs8').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs9, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 9
	$('a.loadset9').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs9').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 10
	$('a.loadset10').click(function(){
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9, #thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs10').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs1, #thumbs2, #thumbs3, #thumbs4, #thumbs5, #thumbs6, #thumbs7, #thumbs8, #thumbs9').hide().addClass('hidden');
		return false;
	});

	// toggle overlay
	$("h1 a").click(function() {
		$(this).blur();
		if ($("#overlay").hasClass('hidden')) {
			$("#overlay").css('height','auto').removeClass('hidden').children().show();
			if ($('#thumbs1').hasClass('hidden')) {
				$('#thumbs1').hide();
			}
			if ($('#thumbs2').hasClass('hidden')) {
				$('#thumbs2').hide();
			}
			if ($('#thumbs3').hasClass('hidden')) {
				$('#thumbs3').hide();
			}
			if ($('#thumbs4').hasClass('hidden')) {
				$('#thumbs4').hide();
			}
			if ($('#thumbs5').hasClass('hidden')) {
				$('#thumbs5').hide();
			}
			if ($('#thumbs6').hasClass('hidden')) {
				$('#thumbs6').hide();
			}
			if ($('#thumbs7').hasClass('hidden')) {
				$('#thumbs7').hide();
			}
			if ($('#thumbs8').hasClass('hidden')) {
				$('#thumbs8').hide();
			}
			if ($('#thumbs9').hasClass('hidden')) {
				$('#thumbs9').hide();
			}
			if ($('#thumbs10').hasClass('hidden')) {
				$('#thumbs10').hide();
			}
		} else {
			$("#overlay").css('height','100px').addClass('hidden').children().hide();
			$("h1").show();
		}
		return false;
	});	
	
});

// Update gallery menu

$(document).ready(function(){
$('.control ul li').find('a').click(menu);function menu(){$(this).parents('ul:first').find('a').removeClass('activegallery').end().end().addClass('activegallery');}
function trigger(data){var el=$('.control ul li').find('a[href$="'+data.id+'"]').get(0);menu.call(el);}
if(!window.location.hash){$('.control ul li a:first').click();}});

// Triggers

$(document).ready(function(){
	$(".trigger").click(function(){
		$(".panel").toggle("fast");
		$(this).toggleClass("active");
		return false;
	});
});
$(document).ready(function(){
	$(".trigger_right, .close").click(function(){
		$(".panel_right").toggle();
		$(this).toggleClass("active");
		return false;
	});
});
