Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
}

var phwidth = 150; // pictureholder width
// var phheight = 384; // pictureholder height
var caption_height = 150; // How many pixels high for caption box if on
var caption_border = 1; // Caption border pixels
var username="skeelerclubstedebroec";
var album="SkeelerenPurmerend06062011";
var album="SkeelerenNassaupark14062011";
var album="SkeelerenNassauparkToertocht04092011";
var sponsor="Sponsoren";
var photosize=144;
var pictures = new Array(); // will hold an array of all the pics
var sponpic = new Array(); // will hold an array of all the pics
var currentpic=0;
var currentspon=0;
var toonsponsor=0;

function setCookie(c_name,value,exdays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++){
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name){
            return unescape(y);
        }
    }
}

function checkCookie(){
    if (getCookie("currentspon")>0){
        currentspon=getCookie("currentspon");
    }
}

function loadpics(j)
{
    for(i=0;i<j.feed.entry.length;i++)
    {
	pictures[i] = {	photo: new Image,
			title: ''};
        pictures[i].photo.src = j.feed.entry[i].media$group.media$content[0].url+"?imgmax="+photosize;
    }
    pictures.shuffle();
}

function loadspon(j)
{
    for(i=0;i<j.feed.entry.length;i++)
    {
	sponpic[i] = {	photo: new Image,
			title: ''};
        sponpic[i].photo.src = j.feed.entry[i].media$group.media$content[0].url+"?imgmax="+photosize;
    }
    init_show();
}

function init_show(){
    pcomplete = sponpic[3].photo.complete;
    if (!pcomplete)
    {
	setTimeout("init_show()", 10);
	return;
    }
    var img1 = document.createElement("img");
    document.getElementById("demo").appendChild(img1);
    img1.id = 'img1';
    img1.src = sponpic[0].photo.src;
    img1.width = sponpic[0].photo.width;
    img1.height = sponpic[0].photo.height;
    img1.style.overflow = 'hidden';
    img1.style.position = 'relative';
//    img1.style.left = -72+'px';
    img1.style.top = 20+'px';
//    img1.style.opacity = 0.50;
//    img2.style.position = 'absolute';
//    img2.style.left = 0+'%';
//    img2.style.top = 0+'px';
//    img2.style.opacity = 0.50;
//    img2.style.filter = 'alpha(opacity=50)';
    checkCookie();
    slideit();
}

function slideit(){
    var x=document.getElementById("img1");
    var y=1;
    if (toonsponsor==0) y=Math.floor(currentpic/3)-currentpic/3;
//    y=1;
    if (y==0){
        toonsponsor=1;
        x.src = sponpic[currentspon].photo.src;
        x.width = sponpic[currentspon].photo.width;
        x.height = sponpic[currentspon].photo.height;
        currentspon++;
        if (currentspon==sponpic.length) currentspon=0;
        setCookie("currentspon",currentspon,14);
    } else {
        toonsponsor=0;
        x.src = pictures[currentpic].photo.src;
        x.width = pictures[currentpic].photo.width;
        x.height = pictures[currentpic].photo.height;
        currentpic++;
        if (currentpic==pictures.length) currentpic=0;
    }
    setTimeout("slideit()", 2500);
}

function loadScript(url){
    var script = document.createElement("script")
    script.type = "text/javascript";
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

function displayDate()
{
var x=document.getElementById("demo");
x.setAttribute("style","width:"+phwidth+"px; height: "+caption_height+"px; border-width:"+caption_border+"px; border-style:solid; margin-top: 5px; padding: 5px; text-align: left; border-radius: 10px; box-shadow: 10px 10px 5px #888888;");
loadScript('http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?category=photo&alt=json&callback=loadpics');
loadScript('http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+sponsor+'?category=photo&alt=json&callback=loadspon');

}

document.write('<div id="demo" style="width: '+phwidth+'px; height: '+caption_height+'px; overflow: hidden; position: relative;">');
document.write('</div>');
displayDate();
