function Carousel(type, imgWidth, imgHeight, intervalScroll, moduleId, module, contentId, additional)
{	
	//constructing
    this.type = type;
    this.intervalScroll = intervalScroll;
    this.moduleId = moduleId;
    this.module = module;
    this.contentId = contentId;
    this.additional = additional;
    this.imgWidth = imgWidth;
    this.imgHeight = imgHeight;
    
    //standaard settings
    this.ajaxScript = '/module/carousel/CarouselExternal.php';
    this.sizeFrame = 2;
    //this.animateSnapTime = 500;
    
    //dynamische waarden
    this.car;
    this.buttons = false;
    this.autoScroll = false;

    //initialisatie
    this.initCallback = function(carousel)
    {        
        this.car = carousel;
        
        //Scrolling uit als je met je muis erover heen gaat
        carousel.clip.hover(function() 
        {
            carousel.stopAuto();
        }, function() 
        {
            carousel.startAuto();
        });
    }
	
    this.itemLoadCallback = function(carousel, state)
    {    	
    	//Bestaan de items al (caching)
        if (carousel.has(carousel.first, carousel.last) || this.type == 'default') 
        {  
            return;
        }
        
        //de AJAX call
        jQuery.ajax({
            url: this.ajaxScript,
            data:
            {
                type: this.type,
                moduleid: this.moduleId,
                module: this.module,
                contentid: this.contentId,
                additional: this.additional
            },
            dataType: 'json',
            type: 'POST',
            success: function(json) 
            {
                self.itemAddCallback(carousel, type, json);
            }}
        );
    }

    itemAddCallback = function(carousel, type, json)
    {    	
    	if (json != null)
    	{
    		//Zet de grootte aan aantal items
	        carousel.size(json.length);
	        
	        //reset carousel
	        jQuery('#listcarousel').empty();
	        
	        for (var iData = 0; iData < json.length; iData++)
	        {
	            //voeg items toe aan carousel
                carousel.add(carousel.first + iData, json[iData]);
	        }
            
            if (json.length <= 1)
            {
                $(carousel.buttonNext).attr('disabled', 'true');
                $(carousel.buttonNext).addClass('jcarousel-next-disabled');
                $(carousel.buttonNext).addClass('jcarousel-next-disabled-horizontal');
                carousel.stopAuto();
                //jQuery("#listcarousel").draggable( "option", "disabled", true );
            }
    	}
    }
    
    /* Speciale filter voor landen */
    this.filter = function(carousel, location, year)
    {
     	//de AJAX call
        jQuery.ajax({
            url: this.ajaxScript,
            data:
            {
                type: this.type,
                moduleid: this.moduleId,
                module: this.module,
                contentid: this.contentId,
                location: location,
                year: year
            },
            dataType: 'json',
            type: 'POST',
            success: function(json) 
            {
                self.itemAddCallback(carousel, type, json);
            }}
        );
    }
    
    /* ---DRAGGING PURPOSES---
    this.getWidth = function()
    {
    	var width;
    	
        var aantal = Math.floor(this.car.options.size / this.car.options.scroll); //aantal slides
        var aantalImg = aantal * this.car.options.scroll; //totaal aantal nog te tonen plaatjes
    	var resImg = this.car.options.size - aantalImg; //verschil 
    	var scrollImg = (aantal - 1) * this.car.options.scroll;
        
    	width = ((scrollImg + resImg) * (this.imgWidth - this.sizeFrame)) + ((scrollImg + resImg) * this.sizeFrame);
    	
    	return width;
    }
    
    this.getLastSnapItems = function()
    {
    	var size = this.car.options.size;
    	var scroll = this.car.options.scroll;
    	
    	var aantal = Math.floor(size / scroll);
    	var res = size - (aantal * scroll);
    	
    	return res;
    }
    
    this.getSnapPoints = function()
    {
    	var snapPoints = Array();
    	var width = this.getWidth();
    	var totalImg = this.car.options.size;
    	var aantalImg = this.car.options.scroll;
    	var aantal = Math.floor(totalImg / aantalImg);
    	var resImg = totalImg - (aantal * aantalImg);
    	
    	var snapPoint = 0;

    	for(var i=0; i < aantal; i++)
    	{
    		if (i == 0)
    		{
    			snapPoints[i] = 0;
    		}
    		else
    		{
    			snapPoint = snapPoint + ((aantalImg * (this.imgWidth - this.sizeFrame)) + (aantalImg * this.sizeFrame));
    			
    			snapPoints[i] = snapPoint;
    		}
    	}
    	
    	snapPoints[i++] = snapPoint + ((resImg * (this.imgWidth - this.sizeFrame)) + (resImg * this.sizeFrame));

    	return snapPoints;
    }
    
    this.getClosestSnappoint = function(position)
    {
    	var snapPoints = this.getSnapPoints();
    	var verschil;
    	var rverschil;
    	var verschillen = Array();
    	var results = [];

    	for(var i=0; i < snapPoints.length; i++)
    	{
    		verschil = position + snapPoints[i]; //positie is altijd negatief of 0
    		
    		if (verschil < 0)
    		{
    			rverschil = 0 - verschil;
    		}
    		else
    		{
    			rverschil = 0 + verschil;
    		}
    		
    		verschillen[verschillen.length] = rverschil;

    		if (snapPoints[i] > 0)
    		{
    			results["verschil" + rverschil.toString()] = parseInt('-' + snapPoints[i]); //string key 
    		}
    		else
    		{
    			results["verschil" + rverschil.toString()] = snapPoints[i]; //string key
    		}
    	}
    	
    	verschillen.sort(sortNumber);
    	
    	return results['verschil' + verschillen[0].toString()];
    }
    
    this.snapToSnappoint = function(snappoint)
    {    	
    	var snapPoints = this.getSnapPoints();
    	
        //Animatie
        $("#listcarousel").animate({
            left: snappoint
        }, this.animateSnapTime);
        
    	if (0 > snappoint)
    	{
    		snappoint = snappoint.toString();
    		snappoint = parseInt(snappoint.substr(1));
    	}
    	
    	var snap = jQuery.inArray(snappoint, snapPoints);

    	if (snap >= 0)
    	{    		
    		if (snap > 0 && ((snap + 1) < snapPoints.length))
    		{
    			snap = 1 + (this.car.options.scroll * snap);
    			
    			this.car.buttonPrev.attr('disabled', 'false');
                
				prevFistSnap = snap - ((this.car.options.scroll * 2) - 1);
				prevLastSnap = snap - ((this.car.options.scroll) - 1);
    		}
    		else
    		{
    			snap = 1 + (this.car.options.scroll * (snap - 1)) + this.getLastSnapItems();
    			
				prevFistSnap = (snap - this.getLastSnapItems()) - (this.car.options.scroll + 1);
				prevLastSnap = (snap - this.getLastSnapItems()) - 1;
    			
    	        $(this.car.buttonPrev).attr('disabled', 'false');

    	        //voor laatste item standaard buttons uitzetten tenzij rotatie aanstaat
    		}
            
    		this.car.first = snap;
    		this.car.last = snap;
            
            if (snap == 0)
            {
                this.animatePijlers(1);
            }
            else
            {
                this.animatePijlers(snap);
            }
            
    		this.car.prevFirst = prevFistSnap;
    		this.car.prevLast = prevLastSnap;
    	}
    	else
    	{
    		this.car.first = 0;
    		this.car.last = 1;

            this.animatePijlers(1);
            
    		$(this.car.buttonPrev).attr('disabled', 'true');
    		$(this.car.buttonPrev).attr('disabled', 'false');
    	}
        
        this.car.buttons();
    }
    
    this.itemStopDragCallback = function(ev,ui)
    {            	
    	snappoint = this.getClosestSnappoint(ui.position.left);

        this.snapToSnappoint(snappoint);
    }
    
    this.itemDragging = function(ev,ui)
    {        
		var maxPos = this.getWidth();

    	if (ui.position.left > 0) ui.position.left = 0;
		if (ui.position.left < -maxPos) ui.position.left = -maxPos;
    }*/
}

//Custom nummer sortering
function sortNumber(a,b)
{
	return a - b;
}
