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);
};
function mycarousel_getItemHTML(item)
{
	return '<img src="fileadmin/templates/' + item.thumb + '" width="' + item.width + '" height="' + item.height + '" alt="' + item.title + '" title="' + item.title + '" onmouseover="$(this).css(\'cursor\', \'pointer\')" onclick="switchPic(\'' + item.image + '\',\'' + item.title + '\')" />';
};
function mycarousel_initCallback(carousel)
{
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};
function switchPic(url, title) {
	var img = new Image();
	$('#bg_pic img').fadeOut(250);
	
	$(img).load(
			function () {
				$('#bg_pic img').replaceWith(this);
				$(img).fadeIn(250);
				$('#bg_pic img').attr('width', '546');
				$('#bg_pic img').attr('height', '584');
				$('#bg_pic img').attr('title', title);
				$('#bg_pic img').attr('alt', title);
				$('#bg_pic img').attr('border', '0');
			}
	).error(function () {
	}).attr('src', 'fileadmin/templates/' + url);
};

$(document).ready(
	function(){

		jQuery('#mycarousel').jcarousel({
			wrap: 'circular',
			auto: 0.3,
			animation: 2000,
			scroll: 1,
			initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		});

		$('#bildleiste').draggable({ axis: 'y' });
		$('#bildleiste').hover(function(){$(this).css('cursor', 'move');},function(){});
		var width = Math.ceil((((document.body.clientWidth) * 0.6) - 8));
		$('#bildleiste_schlitz').css('margin-left', width);
		var height = Math.ceil((self.innerHeight || jQuery.boxModel && document.documentElement.offsetHeight || document.body.clientHeight) * 0.55);
		$('#bildleiste').css('margin-top', height);

		$(window).resize(function(){
			var width = Math.ceil((((document.body.clientWidth) * 0.6) - 8));
			$('#bildleiste_schlitz').css('margin-left', width);
		});
	}
);
