jQuery.fn.center = function () {
	this.css("position","absolute");
	this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	return this;
}

var slideshow = function()
{
	jQuery('#carousel').jcarousel(
	{
		scroll: 1,
		initCallback: initSlideshow,
		itemVisibleInCallback: {onAfterAnimation: updateSlideshowControls},
		buttonNextHTML: null,
		buttonPrevHTML: null,
		auto: 5
	});
};

var initSlideshow = function(obj)
{
	// popup images
	// rel=landscape or portrait
	$("#carousel .imgs img").click(function(e)
	{
		var html	= "<img src='"+$(this).parent().attr("href")+"' alt='"+$(this).attr("alt")+"' />";
		var rel		= $(this).attr("rel");
		var width	= 640;
		var height	= 480;
		$("#popupimg").width(width);
		$("#popupimg").height(height);
		$("#popupimg").html(html).center().fadeIn("slow");	
		$("#popupbg").css({"opacity" : "0.6"}).fadeIn("slow");		
		return false;
	});
	$("#popupbg").click(function()  { $("#popupbg").fadeOut("fast"); $("#popupimg").fadeOut("fast"); });
    $("#popupimg").click(function() { $("#popupbg").fadeOut("fast"); $("#popupimg").fadeOut("fast"); });
};

var updateSlideshowControls = function(obj, li, index, state)
{
	jQuery("#slideshowCurrentItem").html(index);
};

var slideshowShowTxt = function()
{
	isTxtActive = true;
	jQuery('.jcarousel-btn-more').hide('slow');
	jQuery('.jcarousel-btn-close').show('slow');
	var carousel = jQuery('#carousel').data('jcarousel');
	carousel.stopAuto();
	var item = jQuery("#slideshowCurrentItem").html() -1;
	var el = '#carousel .desc:eq(' +item+ ')';
	jQuery(el).show('slow');
};

var slideshowHideTxt = function()
{
	isTxtActive = false;
	jQuery('.jcarousel-btn-more').show('slow');
	jQuery('.jcarousel-btn-close').hide('slow');
	var carousel = jQuery('#carousel').data('jcarousel');
	carousel.startAuto();
	var item = jQuery("#slideshowCurrentItem").html() -1;
	var el = '#carousel .desc:eq(' +item+ ')';
	jQuery(el).hide('slow');
};

