$(document).ready(function() {

// for content_scroll.tpl.php

   $("#down1").click(function() {
   	$("#km_content3").scrollTo( '+=247px', 500, { axis:'y'} );
   });
   $("#up1").click(function() {
   	$("#km_content3").scrollTo( '-=247px', 500, { axis:'y'} );
   });

// for main_referenzen.tpl.php

   $("#down2").click(function() {
   	$("#km_referenzen").scrollTo( '+=200px', 500, { axis:'y'} );
   });
   $("#up2").click(function() {
   	$("#km_referenzen").scrollTo( '-=200px', 500, { axis:'y'} );
   });

   jQuery('#carousel').jcarousel(
   {
   		animation: 'slow',
   		scroll: 1,
   		offset: 1,
   		visible: 1,
			buttonPrevHTML: '',
   		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
   		wrap: 'circular'
   });

	$('#ref_content_close').click(function(){
  	toggleRef('');
  });

// buttonNextHTML: '',

/*
   		auto: 0,

*/

});


function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    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_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};
*/

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="459" height="440" alt="' + item.title + '" />';
};

function KM_initClick()
{
	$('#button').click
	(
		function()
		{
			$('#km_referenzen_wrap').toggle('slow');
		}
	)

	$('#close').click
	(
		function()
		{
			$('#km_referenzen_wrap').toggle('slow');
		}
	)


}

$(document).ready
(
	function()
	{
		KM_initClick();
	}
);

function switchOn(id)
{
	$('#'+id).toggle();
}

function switchOff(id)
{
	$('#'+id).toggle();
}

function toggleRef(ref_src)
{
	if (ref_src != '')
	{
		showRef(ref_src);
	}
	top.$('#km_ref_wrap').toggle('slow');
}

function showRef(ref_src)
{
	top.$('#km_ref_content').attr("src",ref_src);
}