jQuery(document).ready(function() {
	var backgroundXMLPath = "/images/board/background.xml";
	if ($destinationSlug=='index') {
		backgroundXMLPath = "/images/index/background.xml";
	} else if ($destinationSlug !='') {
		backgroundXMLPath = "/images/touring/"+$destinationSlug+"/background.xml";
	}
	$.ajax({
		type: "GET",
		url: backgroundXMLPath,
		dataType: "xml",
		success: setBackground
    });

});
function setBackground(xml) {
	var items = new Array();
    $(xml).find("img").each(function () {
    	items.push($(this));
    });
    var selected = items[Math.floor(Math.random()*items.length)];
    var captionStr='';
    $('#container').css({background:'url(' + selected.attr('src') + ') center center repeat-y'});
    if (selected.attr('href')) {
		captionStr = '<a href="' + selected.attr('href') + '">' + selected.attr('caption') + '</a>';
    } else {
		captionStr = selected.attr('caption');
    }
    
    $('#container').append('<div id="backgroundCaption">'+captionStr+'</div>');
//	var backgroundCaptionTop = $('#contents').height() - $('#section1 h2').height() - parseInt($('#section1 h2').css('padding-bottom')) - parseInt($('#contents_inner').css('padding-top')) - $('#backgroundCaption').height() - 15;
    $('#backgroundCaption').css({bottom:$('#backgroundCaption').height()+10+'px'});
    $('#backgroundCaption').hide();
}


