﻿// JScript File

$(document).ready(function(){
	var check;
	var i;
	for(i=0;i<20;i++){
		if($(".a"+i+"").attr("id")){
		check=$(".a"+i+"").attr("id").slice(1,2);
		}
	}
		
	var selected=check*($("#b0").width()+1);
	var position;
	
	$("#sprite").css({backgroundPosition:''+selected+'px 4px'});
		
	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position=$(this).attr("id").slice(1,2)*($(this).width()+1)/*width of your list item*/;
	$("#sprite").stop().animate({backgroundPosition:''+position+'px 4px'},{duration:300});
	});
	
	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite").stop().animate({backgroundPosition:''+selected+'px 4px'},{duration:300});
	});
	
	
	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).click(function(){
	selected=$(this).attr("id").slice(1,2)*($(this).width()+1);
	});
	
	
	var position2;
	var selected2=0;
	$("#sprite2").css({backgroundPosition:''+selected2+'px 4px'});
		
	$("#c0,#c1,#c2,#c3,#c4,#c5,#c6,#c7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position2=$(this).attr("id").slice(1,2)*($(this).width()+1)/*width of your list item*/;
	$("#sprite2").stop().animate({backgroundPosition:''+position2+'px 4px'},{duration:300});
	});
	
	$("#c0,#c1,#c2,#c3,#c4,#c5,#c6,#c7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite2").stop().animate({backgroundPosition:''+selected2+'px 4px'},{duration:300});
	});
	
	
	$("#c0,#c1,#c2,#c3,#c4,#c5,#c6,#c7").css({backgroundPosition:'0px 0px'}).click(function(){
	selected2=$(this).attr("id").slice(1,2)*($(this).width()+1);
	});
	
	var position3;
	var selected3=0;
	$("#sprite3").css({backgroundPosition:''+selected3+'px 4px'});
		
	$("#d0,#d1,#d2,#d3,#d4,#d5,#d6,#d7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position3=$(this).attr("id").slice(1,2)*($(this).width()+1)/*width of your list item*/;
	$("#sprite3").stop().animate({backgroundPosition:''+position3+'px 4px'},{duration:300});
	});
	
	$("#d0,#d1,#d2,#d3,#d4,#d5,#d6,#d7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite3").stop().animate({backgroundPosition:''+selected3+'px 4px'},{duration:300});
	});
	
	
	$("#d0,#d1,#d2,#d3,#d4,#d5,#d6,#d7").css({backgroundPosition:'0px 0px'}).click(function(){
	selected3=$(this).attr("id").slice(1,2)*($(this).width()+1);
	});
	
	
		var position4;
	var selected4=0;
	$("#sprite4").css({backgroundPosition:''+selected4+'px 4px'});
		
	$("#e0,#e1,#e2,#e3,#e4,#e5,#e6,#e7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position4=$(this).attr("id").slice(1,2)*($(this).width()+1)/*width of your list item*/;
	$("#sprite4").stop().animate({backgroundPosition:''+position4+'px 4px'},{duration:300});
	});
	
	$("#e0,#e1,#e2,#e3,#e4,#e5,#e6,#e7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite4").stop().animate({backgroundPosition:''+selected4+'px 4px'},{duration:300});
	});
	
	
	$("#e0,#e1,#e2,#e3,#e4,#e5,#e6,#e7").css({backgroundPosition:'0px 0px'}).click(function(){
	selected4=$(this).attr("id").slice(1,2)*($(this).width()+1);
	});
	
	
});

$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();

});
function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a: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('caption'))? $('#gallery a:first') :current.next()) : $('#gallery 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);

	//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({height: '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({height: '70px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	
	
}
