var base_href = 'http://www.stoll-fotodesign.de';
$(document).ready(function () {
	$(".text").hide();
	$("a.info").click(function() {
	  $(this).next().slideToggle(300);
	});
	$(".text").click(function() {
	  $(this).slideToggle(300);
	});
	
	$left = 135;
	// klick aufs bild
	$("#portfolio .image img").bind("click", function() { 
		if ( $(this).parent().hasClass("active") ) { // wenn bild aktiv
			if ( $left > 135 + -(parseInt($("#pagination a:last").text())-1)*700) {  // wenn bild nicht das letzte ist
				moveForward();
				$(this).parent().removeClass("active");
				$(this).parent().next().addClass("active");
				$("#pagination a.active").next().addClass("active");
				$("#pagination a.active:first").removeClass("active");
			}
			else { // wenn letztes bild
				$("#portfolio").animate({
				  left: 135
				}, 300);
				$left = 135;
				$(".text").hide();
				$(this).parent().removeClass("active");
				$("#portfolio .image:first").addClass("active");
				$("#pagination a.active").removeClass("active");
				$("#pagination a:first").addClass("active");
			}
		}
		else { // wenn bild nicht aktiv
			if ( $(this).parent().next().hasClass("active") ) {  // wenn nächstes bild aktiv ist
				moveBack();
				$(this).parent().next().removeClass("active");
				$(this).parent().addClass("active");
				$("#pagination a.active").prev().addClass("active");
				$("#pagination a.active:last").removeClass("active");
			}
			else { // wenn vorheriges bild aktiv ist
				moveForward();
				$(this).parent().prev().removeClass("active");
				$(this).parent().addClass("active");
				$("#pagination a.active").next().addClass("active");
				$("#pagination a.active:first").removeClass("active");
			}
		}
	});
	
	// klick in der pagination
	$("#pagination a").bind("click", function() { 
		$("#portfolio").animate({
		  left: 135 + (parseInt($(this).text())-1)*-700
		}, 300);
		$left = 135 + parseInt($(this).text()-1)*-700
		$("#pagination a").removeClass("active");
		$(this).addClass("active");
		$(".text").hide();
		$("#portfolio .image").removeClass("active");
		$("#i" + parseInt($(this).text())).addClass("active");
	});
	
	var check_url = window.location.href.replace(base_href,"");
	
	// Navigation
	if(check_url == '/' || check_url.indexOf('/home')  != -1) {
		$('.home').addClass('active');
		$('.home a').each(function() {
			if($(this).attr('href') == check_url) {
				$(this).parent().addClass('active');
			}
		});
	}
	if(check_url.indexOf('/kontakt') != -1 && check_url.indexOf('/backend') == -1) {
		$('.kontakt').addClass('active');
		$('.kontakt a').each(function() {
			if($(this).attr('href') == check_url) {
				$(this).parent().addClass('active');
			}
		});
	}
	if(check_url.indexOf('/portfolio') != -1 && check_url.indexOf('/backend') == -1) {
		$('.portfolio').addClass('active');
		$('.portfolio a').each(function() {
			if($(this).attr('href') == check_url) {
				$(this).parent().addClass('active');
			}
		});
	}
	if(check_url.indexOf('/referenzen') != -1 && check_url.indexOf('/backend') == -1) {
		$('.referenzen').addClass('active');
		$('.referenzen a').each(function() {
			if($(this).attr('href') == check_url) {
				$(this).parent().addClass('active');
			}
		});
	}
	if(check_url.indexOf('/studio') != -1 && check_url.indexOf('/backend') == -1) {
		$('.studio').addClass('active');
		$('.studio a').each(function() {
			if($(this).attr('href') == check_url) {
				$(this).parent().addClass('active');
			}
		});
	}
	
	$('.panorama').click(function() {
		window.open('/panoramen/' + $(this).attr('rel') + '/index.htm', 'Panorama', 'width=700,height=550,scrollbars=no');
	});
	
    $(".add_picpool").each(function(i){
    	element = $(this);
        $(this).parent().append(' <a href="javascript:;" onclick="window.open(\'/index/bilderpool?field=true&name='+$(this).attr("id")+'\', \'dsfasdf\', \'width=500,height=500,scrollbars=yes\')">Bilderpool öffnen</a> | <a href="javascript:;" onclick="$(this).prev().prev().val(\'\')">entfernen</a>');
    }); 
	
    $(".add_panoramapool").each(function(i){
    	element = $(this);
        $(this).parent().append(' <a href="javascript:;" onclick="window.open(\'/index/panoramapool?field=true&name='+$(this).attr("id")+'\', \'dsfasdf\', \'width=500,height=500,scrollbars=yes\')">Panoramapool öffnen</a> | <a href="javascript:;" onclick="$(this).prev().prev().val(\'\')">entfernen</a>');
    });  
	
	$('#background-element').append(' <a href="javascript:;" onclick="window.open(\'/index/bilderpool?field=true&name=background\', \'dsfasdf\', \'width=500,height=500,scrollbars=yes\')">Bilderpool öffnen</a>');
	
	// Impressum
	$(".adress").hide();
	$(".prconsult, .dimento").css("padding","0 0 11px");
	$(".prconsult, .dimento").css("display","block");
	$(".adress, .prconsult, .dimento").css("cursor","pointer");
	
	$(".dimento").click(function() {
		$(this).next().toggle();
		$(".prconsult").toggle();
	});
	$(".prconsult").click(function() {
		$(this).next().toggle();
		$(".dimento").toggle();
	});
	$(".adress").click(function() {
		$(this).toggle();
		if ($(this).prev().hasClass("dimento") == true) {
			$(".prconsult").slideToggle();
		}
		else {
			$(".dimento").slideToggle();
		}
	})
});

function removeLightbox() {
	$('#lightboxbg').remove();
	$('#lightbox').remove();
}


function moveForward () {
	$("#portfolio").animate({
	  left: $left - 700
	}, 300);
	$left= $left - 700
	$(".text").hide();
}

function moveBack () {
	$("#portfolio").animate({
	  left: $left + 700
	}, 300);
	$left= $left + 700
	$(".text").hide();
}

/*
$('.panorama').click(function() {
	$('#lightbox').remove();
	var documentHeight = $(document).height();
	var documentWidth = $(document).width();

	$('body').append('<div id="lightboxbg"></div>');
	$('#lightboxbg').css('width', (documentWidth) + 'px');
	$('body').append('<div id="lightbox">&nbsp;</div>');
	
	$('#lightbox').css('width', '600px');
	$('#lightbox').css('top', ($(window).scrollTop()+20) + 'px');
	$('#lightbox').css('left', ((documentWidth-600)/2) + 'px');

	$('#lightboxbg').css('height', documentHeight + 'px');
	$('#lightboxbg').fadeIn('fast');
	
	$.get("/index/panorama?id=1", function (data) {	
		$('#lightbox').html(data);
		var elem = document.getElementById("to_be_rewritten");
		document.write(elem.innerHTML);
	});
});
*/
