var allcookies = document.cookie;
var pos = allcookies.indexOf("back=");
if (pos != -1) {
    var start = pos + 5;                       // Start of cookie value
    var end = allcookies.indexOf(";", start);  // End of cookie value
    if (end == -1) end = allcookies.length;
    var value = allcookies.substring(start, end);  // Extract the value
    value = decodeURIComponent(value);             // Decode it
	var loopCounter = value;
} else {
	var loopCounter = 0;
}

// setuping events

if (window.addEventListener) {
		window.addEventListener("load",setupLoad,false);
   } else if (window.attachEvent) {
		window.attachEvent("onload", setupLoad);
   } else {
		window.onload= setupLoad;
}

function setupLoad(evnt) {
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("back=");
	if (pos != -1) {
	    var start = pos + 5;                       // Start of cookie value
	    var end = allcookies.indexOf(";", start);  // End of cookie value
	    if (end == -1) end = allcookies.length;
	    var value = allcookies.substring(start, end);  // Extract the value
	    value = decodeURIComponent(value);             // Decode it
		if (value != 0) {
			document.body.style.background = 'url(' + backList[value] +') no-repeat';
		}
	}
}

function getBack() { // changing the background
	 if (loopCounter < backList.length) {
	 	loopCounter++;
	 	if (loopCounter == backList.length) {
	 		loopCounter = 0;
	 	}
		document.body.style.background = 'url(' + backList[loopCounter] +') no-repeat';
		document.cookie = "back=" + loopCounter + "; path=/"; //document.cookie = "back=" + loopCounter +"; max-age=" + (60*60*24*10) + "; path=/";
	}
}


