var items = [];
var current = 0;
var popup2 = true;

function showPopup(id,newItems){
    $('myOverlay').appear( { duration: 0.5 });
    $('placeholder').appear( { duration: 0.5 });
    //$('myOverlay').style.display = '';
    getPopupContent(id);
    items = newItems;
    current = id;

    if(items.length == 1){
        $('popup_next').style.display = 'none';
    } else {
        $('popup_next').style.display = '';
    }
}

function closePopup(){
    //$('myOverlay').style.display = 'none';
    $('placeholder').fade( { duration: 0.5 });
    $('myOverlay').fade( { duration: 0.5 });
}

function nextPopup(){
  
    for (var i=0; i<items.length; i++) {
        if (items[i] == current){
            if (i+1 == items.length){
                current = items[0];
                getPopupContent(items[0]);
                break;
            } else {
                current = items[i+1];
                getPopupContent(items[i+1]);
                break;
            }
        }
    }
}

function getPopupContent(id){
	new Ajax.Request('/cms/frontendhandle.php?type=inhoud&action=GET&id='+ id,
	{
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText;
			update(response);
		}
	});
}


function update( response){

    if (popup2){
        $('popup_content').update(response);
//        new Effect.Move($('popup_content'), { x: 0, y: 0, mode: 'absolute' ,duration:0.5});

//        new Effect.Move($('popup_content2'), { x: 550, y: 0, mode: 'absolute' ,duration:0.5});
	new Effect.appear($('popup_content'), { duration: 0.5 });

	new Effect.fade($('popup_content2'), { duration: 0.5 });
        popup2 = false;
    } else {
        $('popup_content2').update(response);

	new Effect.appear($('popup_content2'), { duration: 0.5 });

        new Effect.fade($('popup_content'), { duration: 0.5 });

//        new Effect.Move($('popup_content2'), { x: 0, y: 0, mode: 'absolute' ,duration:0.5});

//        new Effect.Move($('popup_content'), { x: 550, y: 0, mode: 'absolute' ,duration:0.5});
        popup2 = true;
    }
}

