$(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: 0, // 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
		onMouseenter: superbgimage_mouseenter, // function-callback mouseenter
		onMouseleave: superbgimage_mouseleave, // function-callback mouseleave
		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 onmouseenter, stop slideshow, show pause-indicator
function superbgimage_mouseenter(img) {
	if ($.superbg_slideshowActive) {
		my_slideshowActive = true;
		if ($('#pause').length == 0) { 
			$('body').prepend('<div id="pause"><img src="pause.png" \/><\/div>');
		}
		$('#pause').css('position', 'absolute').css('z-index', 3).show();
		return $('#thumbs').stopSlideShow();
	}
}

// function callback onmouseleave, start slideshow, hide pause-indicator
function superbgimage_mouseleave(img) {
	if (my_slideshowActive && ($('#pause').length > 0) && ($('#pause').css('display') == 'block'))  { 
		$('#pause').hide();
		return $('#thumbs').startSlideShow();
	}	
}

// 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() {

	// update superbgimage options
	function update_superbgOptions() {

		// speed
		var newspeed = 0;
		if (($("input[name='optspeed']").val() == 'slow') || ($("input[name='optspeed']").val() == 'normal') || ($("input[name='optspeed']").val() == 'fast')) {
			newspeed = $("input[name='optspeed']").val(); 
		} else {
			newspeed = parseInt($("input[name='optspeed']").val(), 10); 
			if (isNaN(newspeed)) {
				newspeed = 'slow';
				$("input[name='optspeed']").val('slow');
			}
		}
		
		// slidshow interval
		var newinterval = parseInt($("input[name='optinterval']").val(), 10); 
		if (isNaN(newinterval)) {
			newinterval = 5000;
			$("input[name='optinterval']").val(newinterval);
		}
		if ($.superbg_slideshowActive) { // restart slideshow
			clearInterval($.superbg_interval);
			return $('#thumbs').startSlideShow();
		}

		// transition out
		var newtransitionout = 0;
		if ($("input[name='opttransout']:checked").val() == 'on') {
			newtransitionout = 1;
		} else {
			newtransitionout = 0;
		}

		// random transition
		var newrandomtransition = 0;
		if ($("input[name='optrandomtrans']:checked").val() == 'on') {
			newrandomtransition = 1;
		} else {
			newrandomtransition = 0;
		}
		
		// random image
		var newrandomimage = 0;
		if ($("input[name='optrandom']:checked").val() == 'on') {
			newrandomimage = 1;
		} else {
			newrandomimage = 0;
		}

		// onclick-callback
		if ($("input[name='optclick']:checked").val() == 'on') {
			onclickfunc = superbgimage_click;
			$('#superbgimage img').each(function() { // add click-callback to all images
				$(this).unbind('click').click(function(){ superbgimage_click($(this).attr('rel')); });
			});	
		} else {
			onclickfunc = null;
			$('#superbgimage img').each(function() { // remove click-callback from all images
				$(this).unbind('click');
			});	
		}

		// onshow-callback
		if ($("input[name='optshow']:checked").val() == 'on') {
			onshowfunc = superbgimage_show;
			$('#showtitle').fadeIn('fast');
		} else {
			onshowfunc = null;
			$('#showtitle').hide();
		}
		
		// update options
		$.fn.superbgimage.options = { 
			transition: parseInt($("#transition").val(), 10),
			speed: newspeed,
			slide_interval: newinterval,
			transitionout: parseInt(newtransitionout, 10),
			randomtransition: parseInt(newrandomtransition, 10),
			randomimage: parseInt(newrandomimage, 10),
			onClick: onclickfunc,
			onShow: onshowfunc
		};
	
	}

	// hide options
	$("#options").css('height','15px').css('padding', '0px').addClass('hidden').children().hide();
	$("#options .legend").show();
	
	// hide set 2
	$("#thumbs2").hide().addClass('hidden');
	// hide set 3
	$("#thumbs3").hide().addClass('hidden');
	// hide set 4
	$("#thumbs4").hide().addClass('hidden');
	// hide set 5
	$("#thumbs5").hide().addClass('hidden');
	// hide set 6
	$("#thumbs6").hide().addClass('hidden');
	// hide set 7
	$("#thumbs7").hide().addClass('hidden');
	// hide set 8
	$("#thumbs8").hide().addClass('hidden');
	// hide set 9
	$("#thumbs9").hide().addClass('hidden');
	// hide set 10
	$("#thumbs10").hide().addClass('hidden');
	
	// fade overlay with controls, fade container to display titles
	$('#overlay');
	$('#showtitle').fadeTo('slow', 0.40);
	$('#showtitle').hover(
		function () {
			$(this).fadeTo('fast', 1.00);
		},
		function () {
			$(this).fadeTo('fast', 0.40);
		}
	);

	// 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').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});

	// load image set 2
	$('a.loadset2').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	
	
	// load image set 3
	$('a.loadset3').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 4
	$('a.loadset4').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 5
	$('a.loadset5').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 6
	$('a.loadset6').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 7
	$('a.loadset7').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 8
	$('a.loadset8').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 9
	$('a.loadset9').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').superbgimage({ reload: true }).show().removeClass('hidden');
		$('#thumbs10').hide().addClass('hidden');
		return false;
	});	

	// load image set 10
	$('a.loadset10').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		$('#thumbs3').stopSlideShow();
		$('#thumbs4').stopSlideShow();
		$('#thumbs5').stopSlideShow();
		$('#thumbs6').stopSlideShow();
		$('#thumbs7').stopSlideShow();
		$('#thumbs8').stopSlideShow();
		$('#thumbs9').stopSlideShow();
		$('#thumbs10').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').hide().addClass('hidden');
		$('#thumbs3').hide().addClass('hidden');
		$('#thumbs4').hide().addClass('hidden');
		$('#thumbs5').hide().addClass('hidden');
		$('#thumbs6').hide().addClass('hidden');
		$('#thumbs7').hide().addClass('hidden');
		$('#thumbs8').hide().addClass('hidden');
		$('#thumbs9').hide().addClass('hidden');
		$('#thumbs10').superbgimage({ reload: true }).show().removeClass('hidden');
		return false;
	});	

	// change transition with selectbox
	$("#transition").change(function() {
		update_superbgOptions();
	});	

	// change option speed
	$("input[name='optspeed']").change(function() {
		update_superbgOptions();
	});		
	
	// change option slide_interval
	$("input[name='optinterval']").change(function() {
		update_superbgOptions();
	});		

	// change option transitionout
	$("input[name='opttransout']").click(function() {
		update_superbgOptions();
	});	
	
	// change option randomtransition
	$("input[name='optrandomtrans']").click(function() {
		update_superbgOptions();
	});
	
	// change option randomimage
	$("input[name='optrandom']").click(function() {
		update_superbgOptions();
	});	

	// change option onClick-callback
	$("input[name='optclick']").click(function() {
		update_superbgOptions();
	});	
	
	// change option onShow-callback
	$("input[name='optshow']").click(function() {
		update_superbgOptions();
	});		

	// toggle fieldsets
	$(".legend").click(function() {
		if ($(this).parent().hasClass('hidden')) {
			$(this).parent().css('height', 'auto').css('padding', '10px').removeClass('hidden').children().show();
			$(this).show().css('display', 'block');
		} else {
			$(this).parent().css('height','15px').css('padding', '0px').addClass('hidden').children().hide();
			$(this).show().css('display', 'block');
		}
	});	

	// 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;
	});
});

