/**
* Homepage: Background randomiser selection. Updates artist name image & url (footer)
* Rysen Sydney
* 28.11.10
**/
$(document).ready(function(){

	var bgtotal	= 11, //Total number of bg images
		$bgimg	= $('#bgimg'),
		$arturl = $('#arturl'),
		$url	= ['mb.htm','jf.htm','pc.htm','cb.htm','dc.htm','jd.htm','ks.htm','jl.htm','fm.htm','cm.htm', 'gs.htm' ];
	
	$.preloadImages("images/template/hp-logo.png","images/template/hp-content.png","images/template/bg/hp-nav.png","images/template/bg/foot.png");  
	bgselector($bgimg,bgtotal,$arturl,$url);
	
	// Set size of background image
	var fullscreenroptions = { width: 2560, height: 1440, bgID: '#bgimg' };
	jQuery.fn.fullscreenr(fullscreenroptions); 
});

//Background Randomiser: Sets bg image & the artist's name & url
function bgselector($bgimg,bgtotal,$arturl,$url) {
	var randomnumber = Math.floor(Math.random()*(bgtotal))+1,
		imgpath = ('images/template/bg/bg'+randomnumber+'.jpg');
		
	$bgimg.attr('src', imgpath).load(function() {  
		// image is found and loaded
	}).error(function() {
		// image not loaded
		$bgimg.attr('src', 'images/template/s.gif');
	}).attr('src',imgpath);
		
	//Set artist name and URL
	var bgpos = 0,
		spriteheight = 319,		//Footer: 319px sprite height. artist height 29px
		artheight = 29;	
	if (randomnumber > 1) {bgpos = spriteheight-((randomnumber-1) * artheight); }	
	$arturl.css('background-position', '0 ' + bgpos +'px');
	$arturl.attr('href', $url[randomnumber-1]);
}

//Preloads images
 jQuery.preloadImages = function(){
  for(var i = 1; i<=arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}



