$(document).ready(function () {
	//Execute the slideShow
	slideShow2();
	slideShow1();
});
function slideShow1() {
	//Set the opacity of all images to 0
	$('#HeaderRotate a').css({ opacity: 0.0 });

	//Get the first image and display it (set it to full opacity)
	$('#HeaderRotate a:first').css({ opacity: 1.0 });
	//Set the caption background to semi-transparent

	$('#HeaderRotate .caption').css({ opacity: 0.7 });

	//Resize the width of the caption according to the image width
	$('#HeaderRotate .caption').css({ width: $('#HeaderRotate a').find('img').css('width') });
	//Get the caption of the first image from REL attribute and display it

	$('#HeaderRotate .content').html($('#HeaderRotate a:first').find('img').attr('rel'))
			.animate({ opacity: 0.7 }, 400);

	//Call the gallery function to run the slideShow2, 6000 = change to next image after 6 seconds
	setInterval('headerrotate()', 4000);
}

function slideShow2() {
	//Set the opacity of all images to 0
	$('#Sponsors a').css({ opacity: 0.0 });

	//Get the first image and display it (set it to full opacity)
	$('#Sponsors a:first').css({ opacity: 1.0 });

	//Set the caption background to semi-transparent
	$('#Sponsors .caption').css({ opacity: 0.7 });

	//Resize the width of the caption according to the image width
	$('#Sponsors .caption').css({ width: $('#Sponsors a').find('img').css('width') });

	//Get the caption of the first image from REL attribute and display it
	$('#Sponsors .content').html($('#Sponsors a:first').find('img').attr('rel'))
	.animate({ opacity: 0.7 }, 400);

	//Call the gallery function to run the slideShow2, 6000 = change to next image after 6 seconds
	setInterval('gallery2()', 4000);
}

function gallery2() {
	//if no IMGs have the show class, grab the first image
	var current = ($('#Sponsors a.show') ? $('#Sponsors a.show') : $('#Sponsors a:first'));

	//Get next image, if it reached the end of the slideShow2, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#Sponsors a:first') : current.next()) : $('#Sponsors a:first'));

	//Get next image caption
	var caption = next.find('img').attr('rel');

	//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)
	.removeClass('hide');

	//Hide the current image
	current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');

	//Set the opacity to 0 and height to 1px
	$('#Sponsors .caption').animate({ opacity: 0.0 }, { queue: false, duration: 50 }).animate({ height: '1px' }, { queue: true, duration: 300 });

	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#Sponsors .caption').animate({ opacity: 0.7 }, 100).animate({ height: '0px' }, 500);

	//Display the content
	//$('#Sponsors .content').html(caption);
}

function headerrotate() {

	//if no IMGs have the show class, grab the first image
	var current = ($('#HeaderRotate a.show') ? $('#HeaderRotate a.show') : $('#HeaderRotate a:first'));

	//Get next image, if it reached the end of the slideShow2, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#HeaderRotate a:first') : current.next()) : $('#HeaderRotate a:first'));

	//Get next image caption
	var caption = next.find('img').attr('rel');

	//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)
			.removeClass('hide');

	//Hide the current image
	current.animate({ opacity: 0.0 }, 1000)
			.removeClass('show');

	//Set the opacity to 0 and height to 1px
	$('#HeaderRotate .caption').animate({ opacity: 0.0 }, { queue: false, duration: 50 }).animate({ height: '1px' }, { queue: true, duration: 300 });

	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#HeaderRotate .caption').animate({ opacity: 0.7 }, 100).animate({ height: '0px' }, 500);

	//Display the content
	//$('#Sponsors .content').html(caption);
}
