$(document).ready(function() {
	
	/* Homepage slideshow */
	
			var imgWrapper = $('#hero .inner .image div');
			// only show the first image, hide the rest
			imgWrapper.hide().filter(':first').show();
			
			var txtWrapper = $('#hero .inner .right p.intro');
			// only show the first text, hide the rest
			txtWrapper.hide().filter(':first').show();
			
			var creditWrapper = $('#hero .inner .right p.featuredescr');
			// only show the first text, hide the rest
			creditWrapper.hide().filter(':first').show();

			$('ul#featurelist li a').click(function () {

				// check if this item doesn't have class "current"
				// if it has class "current" it must not execute the script again
				if (this.className.indexOf('current') == -1){
						$('ul#featurelist li a').removeClass('current');
						$(this).addClass('current');
						imgWrapper.hide();
						imgWrapper.filter(this.hash).fadeIn(500);
						newTxt = '#intro'+($('ul#featurelist li a.current').attr('href')).substr(6,1)
						newCredit = '#credit'+($('ul#featurelist li a.current').attr('href')).substr(6,1)
						$('#hero .inner .right p.intro').hide();
						$('#hero .inner .right p.featuredescr').hide();
						$(newTxt).fadeIn(500)
						$(newCredit).fadeIn(500)
					
				
					clearTimeout(t)
					t = setTimeout ( "slideshow()", 10000 );
				}
				return false;
			});

			t = setTimeout ( "slideshow()", 10000 );

			$('.intro').hover(function() {
			  pause= true;
			}, function() {
			 pause = false;
			});

			/* End homepage slideshow */
		});
		

		
		/* Functions */
		var pause = false;
		function slideshow() {
			
			if (!pause) {	
			
			if ($('ul#featurelist li a.current').parent().next().length != 0) {
			$('ul#featurelist li a.current').parent().next().children('a').addClass('loading')
			}
			else {
			$('ul#featurelist li a.current').parent().siblings(":first").children('a').addClass('loading')
			}
			$('ul#featurelist li a.current').removeClass('current')
			$('ul#featurelist li a.loading').attr('class', 'current')
			//alert($('ul#featurelist li a.current').hash)
			newImg = $('ul#featurelist li a.current').attr('href')
			newTxt = '#intro'+($('ul#featurelist li a.current').attr('href')).substr(6,1)
			newCredit = '#credit'+($('ul#featurelist li a.current').attr('href')).substr(6,1)
			
	
			
				$('#hero .inner .image div').fadeOut(300)
				$('#hero .inner .right p.intro').fadeOut(300)
				$('#hero .inner .right p.featuredescr').fadeOut(300)
				$(newImg).fadeIn(300)
				$(newTxt).fadeIn(300)
				$(newCredit).fadeIn(300)
				t = setTimeout ( "slideshow()", 7000 );
			
				} else {

						t = setTimeout ( "slideshow()", 2000 );
				}
				
			}


