//specify random images below. You can have as many as you wish
var myimages=new Array()
myimages[0]="images/rand1.jpg"
myimages[1]="images/rand2.jpg"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[0]="#"
imagelinks[1]="#"

$(document).ready(function() {
	//Execute the slideShow
	if($("#randomlink").length){
		random_imglink();
	}

	$("a.external").attr('target','_blank');
	if($("#gallery").length){
		swfobject.embedSWF("rondackflash1.swf", "gallery", "592", "422", "9.0.0", "expressInstall.swf");
		//slideShow();
	}
});

function slideShow() {
	$('#gallery ul li').css({opacity: 0.0});
	$('#gallery ul li.show').css({opacity: 1.0});
	$('#gallery .caption').css({opacity: 0.7});
	$('#gallery .caption').css({height: $('#gallery ul li').find('img').css('height')});
	$('#gallery .content').html($('#gallery ul li.show').find('p'))
	.animate({opacity: 0.7}, 400);
	setInterval('gallery()',10000);
}

function gallery() {
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery ul li.show')?  $('#gallery ul li.show') : $('#gallery ul li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('p'))? $('#gallery ul li:first') :current.next()) : $('#gallery ul li:first'));	

	//Get next image caption
	var caption = next.find('p');

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({width: '1px'}, { queue:true, duration:300 });	

	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({width: '154px'},500 );

	//Display the content
	$('#gallery .content').html(caption);
}

function random_imglink(){
	var ry=Math.floor(Math.random()*myimages.length);
	$("#randomlink").html('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" alt=""></a>')
}
