var tmp;
var nav = ['gallery', 'house_garden', 'object_service', 'rain_systems', 'robots', 'tree_care', 'fence_systems', 'swimming', 'greening', 'planing', 'team', 'contact'];

function init(display) {
	for (var i=0; i< nav.length; i++) {
		if (nav[i] !== display) {
			$('#' + nav[i]).hide();
		}
	}
	setBackground();
}

function show(layer, obj, galleryCat, picCnt, startIndex) {
	init(galleryCat);
	
	if (layer === 'gallery') {
		buildGallery(galleryCat, picCnt);
		var galleries = $('.ad-gallery').adGallery(
			{ start_at_index: startIndex }
		);
		$('#switch-effect').change(
				function() {
					galleries[0].settings.effect = $(this).val();
					return false;
				}
		);
		$('#toggle-slideshow').click(
				function() {
					galleries[0].slideshow.toggle();
					return false;
				}
		);
	}
	
	$(tmp).toggleClass('selected');
	tmp = obj;
	$(obj).toggleClass('selected');
	$('#' + layer).fadeIn('slow');
}

function setBackground() {
	var len = 3;
	var a = 1 + 83 * (Math.random());
	var x = '000' + Math.round(a);
	x = x.substring(x.length - len);
	$('#header').css({ background: 'url(img/background/footer/image' + x + '.jpg) no-repeat bottom' });
}

function closeGallery() {
	$('#gallery').hide();
}

function buildGallery(galleryCat, picCnt) {
	var t = [];
	var len = 3;
	for (var i=1; i <= picCnt; i++) {
		var x = '000' + i;
		x = x.substring(x.length - len);
		t.push('<li>');
		t.push('<a href="img/galleries/' + galleryCat + '/image' + x + '.jpg">');
		t.push('<img src="img/galleries/' + galleryCat + '/thumbs/t_image' + x + '.jpg"/>');
		t.push('</a>');
		t.push('</li>');
	}
	$('#galleryList').html(t.join(''));
	$("#gallery").draggable();
}
