
	$(function() {
	
		/**
		  Fading Images on main page
		*/
		var topImagesdelay = 8000;
		var topImagesCurrent = 0;
		var topImages = [
							{ image: '/images/frontpage/1.jpg',  description: 'Many aspects of life influence me as an artist.' },
							{ image: '/images/frontpage/2.jpg',  description: 'Living in Japan, my concept of art was forever changed.' },
							{ image: '/images/frontpage/3.jpg',  description: 'I learned that less is often more and simple is beautiful.' },
							{ image: '/images/frontpage/4.jpg',  description: 'I want my artwork to calm my mind, body or soul.' },
							{ image: '/images/frontpage/5.jpg',  description: '... to remind me of Earth\'s most inspiring treasures ...' },
							{ image: '/images/frontpage/6.jpg',  description: '... and to amuse my spirit.' },
							{ image: '/images/frontpage/7.jpg',  description: 'What do I love most about art?..' },
							{ image: '/images/frontpage/8.jpg',  description: '... It can give any space its own personality...' },
							{ image: '/images/frontpage/9.jpg',  description: '... it can set the mood in a room, just as much as music ...' },
							{ image: '/images/frontpage/10.jpg',  description: '... and it can take my mind into an unknown world.' }
						];
									
		$.preloadImages(topImages);
	
		// Create top image slider
		var topImage = document.createElement('div');
		topImage.setAttribute('id', 'top_image');
		topImage.className = 'clearfix';
		
		var topImageimg = document.createElement('img');
		topImageimg.setAttribute('src', '/images/frontpage/1.jpg');
		topImageimg.setAttribute('height', 300);
		
		var captionDiv = document.createElement('div');
		captionDiv.className = 'caption';
		
		var captionText = document.createElement('div');
		captionText.className = 'text';
		captionText.innerHTML = topImages[0].description;
		
		var captionBackground = document.createElement('div');
		captionBackground.className = 'background';
		
		captionDiv.appendChild(captionText);
		captionDiv.appendChild(captionBackground);
		
		topImage.appendChild(topImageimg);
		topImage.appendChild(captionDiv);
		
		$('div#body_container').prepend( topImage );
	
		var $topImage = $("div#top_image img");
		var $topImageCaptionBack = $("div#top_image div.caption div.background");
		var $topImageCaption = $("div#top_image div.caption div.text");
	
		setInterval( function() {
		  
			$topImageCaption.fadeOut("slow");
			$topImageCaptionBack.fadeOut("slow");
			
			$topImage.fadeOut("slow", function() {
				$topImage.attr('src', topImages[topImagesCurrent].image);
				$topImageCaption.html( topImages[topImagesCurrent].description );
			});
			
			
			
			$topImage.fadeIn("slow", function() {
				$topImageCaption.fadeIn('fast');
				$topImageCaptionBack.css({ "opacity": 0.6 }).fadeIn('slow');
			});
			
			if( topImages.length - 1 <= topImagesCurrent ) {
				topImagesCurrent = 0;
			} else {
				topImagesCurrent++;
			}
			
			//image = new Image;
			//image.src = topImages[topImagesCurrent].image;
			
			
			
		}, topImagesdelay);
	
		$("div.blogPosts div.blogPost").hover(
			function() {
				$(this).animate({ backgroundColor: '#d5e1e4', borderWidth: '1px', borderColor: '#99b7be'}, 500);
			}, function() {
				$(this).animate({ backgroundColor: '#FFFFFF', borderWidth: '0px', borderColor: '#FFFFFF'}, 500);
			}
		);
		
		var $collections = $('div.buyPageCollectionImageHolder');
		var currentPosition = Math.floor(Math.random()*$collections.length);
		var collectionCount = $collections.length;

		$('a.collectionPreviousButton').click( function() {
			currentPosition--;
			updateCollections();
		});
		$('a.collectionNextButton').click( function() {
			currentPosition++;
			updateCollections();
		});
		$('div.buyPageCollectionImageHolder').hide();
		
		function updateCollections() {

			$('div.buyPageCollectionImageHolder:visible').fadeOut(1000);
			$('div.buyPageCollectionImageHolder').eq(currentPosition).fadeIn(1000);
			if( currentPosition == 0 ) {
				$('a.collectionPreviousButton').fadeOut();
			} else {
				$('a.collectionPreviousButton').fadeIn();
			}
			if( currentPosition == collectionCount -1 ) {
				$('a.collectionNextButton').fadeOut();
			} else {
				$('a.collectionNextButton').fadeIn();
			}
			
		}		
		updateCollections();
	});
	
	
	
	
	jQuery.preloadImages = function(images) {
	  
		for(var i = 0; i<images.length; i++)
		{
			jQuery("<img>").attr("src", images[i].image);
		}
	}
	