var gallery = {
	albums : [{albumTitle: "wilco", 
				photos: [
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_01.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_02.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_03.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_04.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_06.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_07.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_08.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_09.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_10.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_11.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_12.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_13.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_14.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_15.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_16.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_17.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_18.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_19.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
					{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_20.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"}
					]
				},
				{albumTitle: "more wilco", 
				photos: [
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_21.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
			 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_22.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_23.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_24.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_25.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_26.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
			 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_27.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_28.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_29.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_30.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_31.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
			 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_32.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_33.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_34.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_35.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_36.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
			 	{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_37.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_38.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_39.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"},
				{photo: "http://www.wilcoworld.net/photos/sets/solidsound/lg/ss2010_anelson_40.jpg", photoTitle: "Solid Sound Festival", photoCaption: "This was taken at the Solid Sound Festival"}
					]
				}],
	thumbWidth: 72
};

var i=0, j=0, ele = $("#imageContainer"), scroller = $('.scrollable'), thumbs, items = $('.items');
gallery.swapPhoto = function(galleryIndex, photoIndex){
	j = galleryIndex;
	i = photoIndex;
	ele[0].innerHTML = "<img src=\"" + gallery.albums[j].photos[i].photo + "\" style=\"display:none;\"/>";
	thumbs.removeClass("active").eq(i).addClass("active");
	$("#imageContainer img").fadeIn(500,function()
		{
			ele[0].style.background = "url(" + gallery.albums[j].photos[i].photo + ")";

	});
	if(i < 10){
		items.animate({left: (gallery.thumbWidth * i) * -1}, 500);
	}

}

gallery.initialize = function(){
	var albumList = [];
	for (var album in gallery.albums){
		albumList.push("<option value=\"" + album + "\">" + gallery.albums[album].albumTitle + " (" + gallery.albums[album].photos.length + ")</option>");
	}
	$('#selectAlbumContainer').html("<select id=\"selectAlbum\" onchange=\"gallery.loadAlbum(this.value);\">" + albumList.join("") + "</select>");
	$('#selectAlbum').styledSelect();
	gallery.loadAlbum();
}

gallery.loadAlbum = function(galleryIndex){
	i = 0;
	if (galleryIndex === undefined){
		j = 0;
	}else{
		j = galleryIndex;
	}
	ele[0].style.background = "url(" + gallery.albums[j].photos[i].photo + ")";
	ele[0].innerHTML = "";
	var imgs = [];
	for ( var img in gallery.albums[j].photos)
	{
	   	if (img == 0){
			imgs.push("<div class=\"active\"><img title=\""+ gallery.albums[j].photos[img].photoTitle +"\" src=\"" + gallery.albums[j].photos[img].photo + "\"/></div>");
	   	}else{
			imgs.push("<div><img title=\""+ gallery.albums[j].photos[img].photoTitle +"\" src=\"" + gallery.albums[j].photos[img].photo + "\"/></div>");
		}
	   
	}
	scroller.html("<div class=\"items\">" + imgs.join("") + "</div>");
	thumbs = $(".items div");
	items = $('.items')
	gallery.scrollerItemClickInit();
}
ele.click(function(){
    ele[0].style.background = "url(" + gallery.albums[j].photos[i].photo + ")";
	i++;
	if (i === gallery.albums[0].photos.length){
    	i=0;
	}
	gallery.swapPhoto(j,i);
});
gallery.scrollerItemClickInit = function(){
	thumbs.click(function(){
		gallery.swapPhoto(j, $(this).index());
	});
};
$(document).ready(function(){
	gallery.initialize();
});
