/*
var lightboxcfg = {
	overlayBgColor: '#000',
	overlayOpacity: 0.8,
   imageLoading:        '/templates/default/images/lightbox/lightbox-ico-loading.gif',     // (string) Path and the name of the loading icon^
   imageBtnPrev:        '/templates/default/images/lightbox/lightbox-btn-prev.gif',        // (string) Path and the name of the prev button image^
   imageBtnNext:        '/templates/default/images/lightbox/lightbox-btn-next.gif',        // (string) Path and the name of the next button image^
   imageBtnClose:       '/templates/default/images/lightbox/lightbox-btn-close.gif',    // (string) Path and the name of the close btn^
   imageBlank:          '/templates/default/images/lightbox/lightbox-blank.gif',        // (string) Path and the name of a blank image (one pixel)^
	containerResizeSpeed: 350,
	txtImage: 'Bild',
	txtOf: 'von'
};
var colorboxcfg = {
	transition:"none",
	width:"75%",
	height:"75%",
	scalePhotos: true,
	current: "Bild {current} von {total}",
	next: "weiter &raquo;",
	previous: "&laquo; zur&uuml;ck"
};
*/

var fancyboxcfg = {
	'imageScale': true,
	'overlayShow': true
};

$(document).ready(function() {

	var maxHeight = 0;
   $('#pics a.piclink').fancybox(fancyboxcfg);

	if ($('#pics ul li').length > 1) {
		var buttons =   '<p class="picsarrow picspagenext"><a href="#" title="Ein Bild weiter bl&auml;ttern"><span>weiter</span></a></p>';
		buttons +=  '<p class="picsarrow picspageback"><a href="#" title="Ein Bild zur&uuml;ck bl&auml;ttern"><span>zur&uuml;ck</span></a></p>';
		$('#pics .pview').append(buttons);

		$('#pics .picspagenext').click( function() { picsforward(); return false; } );
		$('#pics .picspageback').click( function() { picsbackward(); return false;  } );

		// picstimer = setTimeout("picsforward()", picstimeoutms);
	}
	for (var i=0;i<$('#pics ul li').length;i++) {
		var curHeight = $("#pics ul li").eq(i).height();
		if (maxHeight<curHeight) maxHeight = curHeight;
	}
	if ($("#pics").eq(0) && maxHeight>0 && $("#pics").eq(0).height()<maxHeight) {
	   $("#pics").eq(0).height(maxHeight);
	}
	if ($("#pics .pview div").eq(0) && maxHeight>0 && $("#pics .pview div").eq(0).height()<maxHeight) {
	   $("#pics .pview div").eq(0).height(maxHeight);
	}

	$('#pics .pview').mouseover( function() { picsautomode = false; clearTimeout(picstimer); } ); // Stop
	$('#pics .pview').mouseout( function() { if ($('#pics ul li').length>1) {picsautomode = false; } } ); // Start
	$('#pics .pview').focus( function() { picsautomode = false; clearTimeout(picstimer); } ); // Stop keyboard

	var liwidth = $("#pics ul li").eq(0).show();
});

var picsautomode = false;
var picstimer = 0;
var picstimeoutms = 4000;
var picsrunning = false;

function picsforward() {
    if (picsrunning) return;
    picsrunnging = true;
    clearTimeout(picstimer);
    picstimer = 0;
    var liwidth = $("#pics ul li").eq(0).width();

    $("#pics ul").animate({ left: (-1*liwidth)}, "slow", "", function(){ afterpicsforward() } );

}

function afterpicsforward() {
    $("#pics ul li").eq(0).clone().appendTo($("#pics ul"));
    $("#pics ul li").eq(1).clone().prependTo($("#pics ul"));
    $("#pics ul").css("left", 0);
    $("#pics ul li").eq(1).remove();
    $("#pics ul li").eq(1).remove();

    $('#pics a.piclink').fancybox(fancyboxcfg);
    // var tmppicsullia = $("#pics ul li a");
    // tmppicsullia.eq(0).fancybox();
    picsrunning = false;
    if (picsautomode && !picstimer) { picstimer = setTimeout("picsforward()", picstimeoutms); }
}

function picsbackward() {
    if (picsrunning) return;
    picsrunnging = true;
    clearTimeout(picstimer); // Sicherheitsnetz
    picstimer = 0;
    var liwidth = $("#pics ul li").eq(0).width();

    $("#pics ul li").eq(0).clone().prependTo($("#pics ul"));
    $("#pics ul").css("left", (-1*liwidth));

    var tmppicsulli = $("#pics ul li");
    tmppicsulli.eq(0).html(tmppicsulli.eq(tmppicsulli.length-1).html());

    $("#pics ul").animate({ left: 0}, "slow", "", function(){ afterpicsbackward() } );

}

function afterpicsbackward() {
    var tmppicsulli = $("#pics ul li");
    tmppicsulli.eq(tmppicsulli.length-1).remove();
    // var tmppicsullia = $("#pics ul li a");
    // tmppicsullia.eq(0).fancybox();
    $('#pics a.piclink').fancybox(fancyboxcfg);
    picsrunning = false;
}

