function Showcase(type, intervalScroll, moduleId, module, contentId, additional)
{	
	//constructing
	this.type = type;
	this.intervalScroll = intervalScroll;
	this.moduleId = moduleId;
    this.module = module;
    this.contentId = contentId;
	this.additional = additional;

    //standaard settings
    this.imgWidth = 925;
    this.imgHeight = 244;
    this.ajaxScript = '/module/carousel/CarouselExternal.php';
    this.sizeFrame = 7;
    this.animatePijlersTime = 1500;
    this.animateSnapTime = 500;
    
    //dynamische waarden
    this.car;
    this.buttons = false;
    this.autoScroll = false;

    //initialisatie
    this.initCallback = function(carousel)
    {        
        this.car = carousel;
        
        //bind onclick op de pijlers
        $('#conceptpijler').click(function()
        {
            window.location = '/concept';
        });
        $('#creatiepijler').click(function()
        {
            window.location = '/creatie';
        });
        $('#codepijler').click(function()
        {
            window.location = '/code';
        });
        $('#conversiepijler').click(function()
        {
            window.location = '/conversie';
        });
        
        //hover
        $('#conceptpijler').mouseover(function()
        {        	
        	tooltip.show($('#concepttip').html());
        	$('#tt').removeClass('ttCreatie ttCode ttConversie'); 
        	$('#tt').addClass('ttConcept');        	
        });
        $('#conceptpijler').mouseout(function()
        {   	
        	tooltip.hide();
        });
        
        $('#creatiepijler').mouseover(function()
        {   	
        	tooltip.show($('#creatietip').html());
        	$('#tt').removeClass('ttConcept ttCode ttConversie');
        	$('#tt').addClass('ttCreatie'); 
        });
        $('#creatiepijler').mouseout(function()
        {   	
        	tooltip.hide();
        });
        
        $('#codepijler').mouseover(function()
        {   	
        	tooltip.show($('#codetip').html());
        	$('#tt').removeClass('ttConcept ttCreatie ttConversie');
        	$('#tt').addClass('ttCode'); 
        });
        $('#codepijler').mouseout(function()
        {   	
        	tooltip.hide();
        });
        
        
        $('#conversiepijler').mouseover(function()
        {   	
        	tooltip.show($('#conversietip').html());
        	$('#tt').removeClass('ttConcept ttCreatie ttCode');
        	$('#tt').addClass('ttConversie'); 
        }); 
        $('#conversiepijler').mouseout(function()
        {   	
        	tooltip.hide();
        });
        
        /*
        $('#conceptpijler').tooltip({tip:'#concepttip', position: 'top center'});
        $('#creatiepijler').tooltip({tip:'#creatietip', position: 'top center'});
        $('#codepijler').tooltip({tip:'#codetip', position: 'top center'});
        $('#conversiepijler').tooltip({tip:'#conversietip', position: 'top center'});
        */
        
        switch(this.type) //type specificatie
        {
    		case 'home':
    			break;
        	case 'projectOverzicht':
        		break;
        	case 'projectDetail':
        		break;
        	case 'medewerkersOverzicht':
        		break;
        	case 'mederwerkersDetail':
        		break;
        	case 'productOverzicht':
        		break;
        	case 'productDetail':
        		break;
        	case 'dienstenOverzicht':
        		break;
        	case 'dienstenDetail':
        		break;
        }

        //Scrolling uit als je met je muis erover heen gaat
        carousel.clip.hover(function() 
        {
            carousel.stopAuto();
        }, function() 
        {        	
        	if (carousel.options.size > 1)
        	{
        		carousel.startAuto();
        	}
        });
    }
	
    this.itemLoadCallback = function(carousel, state)
    {
    	//Bestaan de items al (caching)
        if (carousel.has(carousel.first, carousel.last)) 
        {        	
        	this.animatePijlers(carousel.first);
            
            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);
	        
	        for (var iData = 0; iData < json.length; iData++)
	        {
	            //voeg items toe aan carousel
                carousel.add(carousel.first + iData, json[iData]);
	        }
            
            //breedte pijlers
            showcase.animatePijlers(1, true);
            
            if (json.length <= 1)
            {
                $(carousel.buttonNext).attr('disabled', 'true');
                $(carousel.buttonNext).addClass('jcarousel-next-disabled');
                $(carousel.buttonNext).addClass('jcarousel-next-disabled-horizontal');
                
                //autoscrolling off
                carousel.stopAuto();
                
                jQuery("#listcarousel").draggable( "option", "disabled", true );
            }
    	}
    }
    
    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;
    }
    
    this.animatePijlers = function(current, noAnimateTime)
    {
        var conceptpijler = $('#conceptpijlerInfo' + current).text();
        var creatiepijler = $('#creatiepijlerInfo' + current).text();
        var conversiepijler = $('#conversiepijlerInfo' + current).text();            
        var codepijler = $('#codepijlerInfo' + current).text();
        var time;

        if (conceptpijler == '')
        {
            conceptpijler = 0;
        }
        if (creatiepijler == '')
        {
            creatiepijler = 0;
        }
        if (conversiepijler == '')
        {
            conversiepijler = 0;
        }
        if (codepijler == '')
        {
            codepijler = 0;
        }
        
        if (noAnimateTime === true)
        {
            time = 0;
        }
        else
        {
            time = this.animatePijlersTime;
        }
        
        $('#conceptpijler').animate({
            width: conceptpijler + '%'
        }, time);
        
        $('#creatiepijler').animate({
            width: creatiepijler + '%'
        }, time);
        
        $('#codepijler').animate({
            width: codepijler + '%'
        }, time);
        
        $('#conversiepijler').animate({
            width: conversiepijler + '%'
        }, time);        
    }
}

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