	
	/**
	*	Sequentie voor jquery.jcarousel.js
	*	14 - 6 - 2010
	*	t.b.v. onderscheidt tussen top6 en overige inzendingen
	*	Rop van de laar
	*	versie 1.1
	*	laatst gewijzigd: 17-06-2010 14:16u
	* 	todo: TESTEN!,UITZOEKEN,TESTEN, iets verzinnen voor de extra thumb (info-item)
	*/ 
 

//state vars
var initialised = false;
var infoPaused = false;
var photoClicked = false;

function mycarousel_initCallback(carousel)
{
    carousel.photoClicked = photoClicked;
    
    // enable thumbnail-control functionality
	jQuery('.jcarousel-control a').bind('click', function() {
        carousel.stopAuto();
		var cnt = jQuery.jcarousel.intval(jQuery(this).children('.pgcnt').text());
		
		if(cnt > 6)cnt = cnt+1;
		//alert(cnt);
        carousel.scroll(cnt,true);
        return false;
    });
	
	// Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.photoClicked = false;
        carousel.stopAuto();
    }, function() {
    //  Continue autoscrolling after the user moves the cursor off of the clip.
        if(carousel.photoClicked == false ) {
          carousel.startAuto(4);
        }
        carousel.photoClicked = false;
        
    });

	var initLength = 7;

		//Voeg info item, de project omschrijving, toe.
		var info = '<img src=\'sites/all/themes/klickr-1.0/img/gallery-text.png\'/>';
		carousel.add(initLength++, "<div id=\'info-screen\'>"+info+"</div>");
		
		//loop door de 2e lijst en voeg list-items toe
		var count = 0;
		$('#viewscarousel-photogallery-block-1 a').removeClass('lightbox-processed');
		$("#viewscarousel-photogallery-block-1 li").each(function() {
			count++;
//			carousel.add(initLength++,'<div>'+$(this).html()+'</div>');
			carousel.add(initLength++,$(this).html());
			//alert($(this).html());
		});
		count = count + 7;
		var lastItem = '.jcarousel-item-'+count;
		$(lastItem).addClass('last-item');
		var container = $('#viewscarousel-photogallery-attachment-1');
		container.width(container.width()+500);
		//verwijder de tweede lijst
		$('#viewscarousel-photogallery-block-1').remove();
        Lightbox.initList();
        
        $('li a .pg-table').bind('click', function() {
          carousel.photoClicked = true;
          setTimeout(function() {
            $('#bottomNavClose, #lightbox, #overlay').bind('click', function() {
              carousel.startAuto(4);
              carousel.photoClicked = false;
            });
          },0)
        });
};


function itemLoadCallbackFunction(carousel, state)
{
	//na initalisatie is carousel.first item 1
	// in dat geval en alleen de eerste keer scroll rechtstreeks naar item 6 (of 7 afhankelijk van styling)
	//alert(carousel.first);
	if(carousel.first==1 && !initialised){
		carousel.scroll(7,true);
		initialised = true;
	}else if(carousel.first==7 && !infoPaused){
		infoPaused = true;
		carousel.stopAuto();
		carousel.options.animation = 400;
		//laat het info-item een bepaalde tijd staan (milliseconden) en scroll daarna naar het begin.
		carousel.timer = setTimeout(function() { reInitialise(carousel); }, 10000);
	}
	//Wanneer de pauze al geweest is sla infoItem over. i.t.t. verwijderen zodat men via link nog wel naar infovenster kans
	//ik moet nog even uitzoeken of dit niet een conflict oplevert met de buttons...
	else if(carousel.first==6 && infoPaused){
		carousel.stopAuto();//hier wordt de timeOut gereset dus we wachten zelf 4 sec om door te gaan en scrollen dan naar item7
		carousel.timer = setTimeout(function() { skipInfo(carousel); }, 4000);
	}
	else{return;}
};
function skipInfo(carousel){
	carousel.stopAuto();
	carousel.scroll(8,true);
	carousel.startAuto(4);
};
function reInitialise(carousel){
	//alert("set To First Item And Normal Speed");
	carousel.options.easing = 'swing';
	carousel.stopAuto();
	carousel.scroll(1,true);
	carousel.startAuto(4);
};

 
jQuery(document).ready(function() {
    $('#photogallery .content').css('background-image', 'none');
    $('.view-photogallery .view-content  ul').css('visibility','visible')
	var listlength = $('#viewscarousel-photogallery-block-1 li').length + 7;
	//zet size op 25 (= 24 inzendingen + info-item.)
	//zonder voorgedefiniëneerde lengte werkt carousel.add() niet in itemLoadCallbackFunction.
    jQuery('#viewscarousel-photogallery-attachment-1').jcarousel({
        auto: 2,
        wrap: 'last',
		scroll:1,
		animation:3000,
		size:listlength,
		easing:'linear',
		itemLoadCallback: itemLoadCallbackFunction,
        initCallback: mycarousel_initCallback
    });
});