function setOpacity(testObj,value) {
	$(testObj).css("opacity", value/100);
	$(testObj).css("font-size","14px");
}

var startwidthpublicaties;
$(startKiosk(baseUrl, proxyUrl));

function startKiosk(baseUrl, proxyUrl) {
    $.ajax({        
        type: "POST",
        contentType: "application/xml; charset=utf-8",
        url: proxyUrl,
        data: "{}",
        dataType: "xml",
        success: function (response) { wssucces(response); }
    });
}

var aantalKoppen;
aantalKoppen = 6;

function wssucces(data) {
    var widthsmall = 141;
    $("#covers").empty();

    var firstid;
    var counti = 0;
    var naam = ""


    $(data).find("WS_Publicatie").each(
	    function () {

	        var lai = "<li naam='" + $(this).find("naam").text().replace("Ij", "IJ") + "' paperid='" + $(this).find("id").text() + "' >";
	        if ($(this).find("link").text() !== "") {
	            lai = lai + "<a class='kioskLink' href='" + baseUrl + $(this).find("link").text() + "/" + $(this).find("naam").text().replace(" ", "_").replace("Ij", "IJ") + "'>";
	        } else {
	            lai = lai + ""
	        }

	        if ($(this).find("img").text().indexOf('/sites') > 0) {
	            lai = lai + "<div class='imageo'><img width='121px' height='172px' src='" + baseUrl + $(this).find("img").text() + "' /></div>";
	        } else {
	            lai = lai + "<div class='imageo'><img width='121px' height='172px' src='" + $(this).find("img").text() + "' /></div>";
	        }
	        lai = lai + "<div class='title'>";

	        lai = lai + $(this).find("naam").text().replace("Ij", "IJ");
	        lai = lai + "</div>";

	        if ($(this).find("link").text() !== "") {
	            lai = lai + "</a>";
	        } else {
	            lai = lai + ""
	        }

	        lai = lai + "</li>";


	        $("#covers").append(lai);




	        counti = counti + 1;
	        if (counti == 1) { firstid = $(this).find("id").text() }

	        
        }


    );
	    var publicaties = $("#publicaties ul").html();
	    var aantalcovers = $("#covers li").size();
	    var startPosition = aantalcovers+(Math.random() * aantalcovers);
	    startPosition = Math.round(startPosition);

        
        $("#publicaties ul").prepend(publicaties).append(publicaties);

	    //alert(publicaties);

	    aantalcovers = $("#covers li").size();
	    var addid = 0;
	    //alert(aantalcovers);

	    var focusedCover = startPosition;
	    var animating = false;


	    updateOpacity(focusedCover);
	    updatePosition(focusedCover, widthsmall, false, 300);


	    function updateOpacity(focusedCover) {
	        $("#covers li").each(function () {

	            addid = addid + 1;


	            setOpacity($(this), 10);


	        });

	        setOpacity($("#covers li:eq(" + focusedCover + ")"), 100);
	        setOpacity($("#covers li:eq(" + (focusedCover - 1) + ")"), 30);
	        setOpacity($("#covers li:eq(" + (focusedCover + 1) + ")"), 30);
	        setOpacity($("#covers li:eq(" + (focusedCover - 2) + ")"), 10);
	        setOpacity($("#covers li:eq(" + (focusedCover + 2) + ")"), 10);

	        $("#covers li:eq(" + (focusedCover - 2) + ")").attr("fromcenter", "-2");
	        $("#covers li:eq(" + (focusedCover - 2) + ")").css("z-index", "1003");

	        $("#covers li:eq(" + (focusedCover - 1) + ")").attr("fromcenter", "-1");
	        $("#covers li:eq(" + (focusedCover - 1) + ")").css("z-index", "1002");

	        $("#covers li:eq(" + (focusedCover) + ")").attr("fromcenter", "0");
	        $("#covers li:eq(" + (focusedCover) + ")").css("z-index", "1001");

	        $("#covers li:eq(" + (focusedCover + 1) + ")").attr("fromcenter", "1");
	        $("#covers li:eq(" + (focusedCover + 1) + ")").css("z-index", "1002");

	        $("#covers li:eq(" + (focusedCover + 2) + ")").attr("fromcenter", "2");
	        $("#covers li:eq(" + (focusedCover + 2) + ")").css("z-index", "1003");

	    }

	    function updatePosition(focusedCover, widthsmall, animated, bump, speed) {

	        var newPosition = -1 * (widthsmall) * (focusedCover - 1);
	        newPosition = newPosition - 32;
	        if (!animated) {
	            $("#covers").css("left", newPosition);
	        } else {
	            animating = true;

	            if (bump !== 0) {
	                $("#covers").animate({ left: newPosition + bump }, speed);
	            }

	            $("#covers").animate({ left: newPosition }, 300, function () { makeInfinite() });
	        }
	    }

	    

	    $("#publicatiesLeft").click(function () {
	        //if (!animating) {

	        $("#covers").clearQueue();
	        $("#covers").stop();
	        makeInfinite();

	        focusedCover = focusedCover - 1;
	        updateOpacity(focusedCover);
	        updatePosition(focusedCover, widthsmall, true, 20, 300);

	        //$("#covers").animate({ left: clicktarget + 10 }, 300, function () { getSelected(0); });
	        //$("#covers").animate({ left: clicktarget }, 300);
	        //}
	    });

	    $("#publicatiesRight").click(function () {
	        //if (!animating) {

	        $("#covers").clearQueue();
	        $("#covers").stop();
	        makeInfinite();

	        focusedCover = focusedCover + 1;
	        updateOpacity(focusedCover);
	        updatePosition(focusedCover, widthsmall, true, -20, 300);

	        //$("#covers").animate({ left: clicktarget + 10 }, 300, function () { getSelected(0); });
	        //$("#covers").animate({ left: clicktarget }, 300);
	        //}
	    });


	    function makeInfinite() {
	        //animating = false;
	        //alert("was " + focusedCover)
	        if (focusedCover > ((aantalcovers / 3) * 2)) {

	            focusedCover = focusedCover - (aantalcovers / 3);
	            updatePosition(focusedCover, widthsmall, false, 0, 300);
	            updateOpacity(focusedCover);
	        }
	        if (focusedCover < (aantalcovers / 3)) {
	            focusedCover = focusedCover + (aantalcovers / 3);
	            updatePosition(focusedCover, widthsmall, false, 0, 300);
	            updateOpacity(focusedCover);
	        }
	        //alert("is " + focusedCover)
	    }
}    
    


/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
