
var mycarousel_itemList = new Array();

/**
* The index() method calculates the index from a given index who is out of the actual item range.
**/
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};


/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item) {
	
		//var xxx = print_r(item, true); alert(xxx);
	
		var onclick = ""; // "return false;";
		if (false && item.href=="") {
			item.href = "#";
			var output = '<a href="'+item.href+'" onclick = "bildergal_a_click(this); return false;">';
		}
	    else {
	    	var output = '<a href="'+item.href+'" >';
	    }
	    output += '<img src="' + item.src_thumb + '" width="100%" class="thumb" alt="' + item.title + '" />';
	    output += '<img src="' + item.src_big + '" class="big" style="display: none" />';
	    output += '</a>';
	    
	    return output;
	
};



jQuery(document).ready(function() {
	jQuery('#bilderliste .big').hide();
	
	/**
	 * Die Itemliste dynamisch aufbauen
	 **/
	$('#bilderliste li').each(function(){
		
		var src_thumb = $("img.thumb", this).attr("src");
		var src_big = $("img.big", this).attr("src");
		var title = $("img.thumb", this).attr("title");
		var href = $("a", this).attr("href");
		
		mycarousel_itemList.push({ href: href,
									src_thumb: src_thumb, 
									src_big: src_big, 
									title: title
								});
	});
	
	
	
	//Startindex des Karussells (carousel) festlegen
	var cstart = $_GET["cstart"];
	if(!cstart){
		cstart = 1;
	}
	
    jQuery('#bilderliste').jcarousel({
        wrap: 'circular',
        vertical: true,
        scroll: 1,
        start: cstart,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
    
	    
	$("#bilderliste a").live("click", function(){
		var href = $(this).attr("href");
		
		// Wenn das Linkziel leer ist, wird das Bild in der ersten Spalte ersetzt.
		if (href=="#" || href=="undefined" || href==""|| href==undefined) {
	    	var src = $(this).children("img.big").attr("src");
			$("#spalte1 img:first").attr("src", src).removeAttr("height").removeAttr("width");
			return false;
		}
		// Ansonsten wird der Link geöffnet
		else {
			
		}
	});

});




