//WAIT FOR THE PAGE TO BE READY
$(document).ready(function(){

	/*$('#tv_holder').flash({
		src: 'flash/tv.swf',
		width: 513,
		height: 313,
		background: '#000000',
		wmode: 'transparent',
		flashvars: { image1: $('#tv_holder').children('em').html() }
	});*/
	
	loadNum = Math.floor(Math.random()*8) + 1;
	prevImg = 0;
	
	function loadImage(i){
		prevImg = i;
		var img = new Image();
		$(img).load(function(){
			$(this).hide();
			$('#tv_holder').append(this);
			$(this).css({opacity:0, display:'block'}).animate({opacity:1}, 500, cycleImage);
		}).attr('src', 'images/tv/xmas_'+i+'.jpg');
	}
	loadImage(loadNum);
	
	function cycleImage(){
		loadNum = Math.floor(Math.random()*8) + 1;
		if(prevImg == loadNum){
			cycleImage();
		}else{			
			$('#tv_holder').animate({opacity:1},2000, function(){
				$('#tv_holder img').animate({opacity:0}, 500, function(){
					$('#tv_holder img').remove();
					loadImage(loadNum);
				});
			})
		}
	}
	
	$('#ssp_gallery').flash({
		src: 'flash/slideshow.swf',
		width: 513,
		height: 380,
		background: '#000000',
		wmode: 'transparent'
	});
	
// End jQuery goodness
});

//<span class="overlay"></span><img src="" alt="Image" />
