$(document).ready(function() {
	$.get("/include/xml/homebuttons.xml",function(xml){
	    var buttonArray = new Array();
	    var i = 0;
	    var noButtons = 0;
		$('button',xml).each(function(i) {
            var target = $(this).find("url").attr("target") ? $(this).find("url").attr("target") : "_top";
		    if ( $(this).attr("display") != 'no' ) {
				buttonArray[i++] = '<a target="' + target + '" href="' + $(this).find("url").text() + '"><img class="btn_top" src="' + $(this).find("img_url").text() + '" /></a>';
				noButtons++;
			};
		});
		if (noButtons == 3) {
		    for ( var x in buttonArray ) {
			   	$("#btn_top_box").append(buttonArray[x]);
		    };
		} else {
			for ( var j = 0; j < 3; j++ ) {
				randno = Math.floor ( Math.random() * noButtons );
			   	$("#btn_top_box").append(buttonArray[randno]);
			   	buttonArray.remove(randno);
			   	noButtons--;
			};
		};
		$(".btn_top:last").css("margin-right","0px");
	});
});


Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
};