	function darkBarPosition(){
		var pos = $('a.homeLogo img').position();
	
		$('.mainDarkBar, .caption').css({
			'position': 'absolute',
			'left': pos.left - 25
		});
	}

	function sliderControlPosition(){
	var posControl = $('a.homeLogo img').position();
	
		$('.slideControl').css({
			'position': 'absolute',
            'top':'390px',
			'left': posControl.left + 70
		});
	}

	function bgPosition(){
	var posBg = $('a.homeLogo img').position();
	
		$('#gallery div.slides img').css({
			'position': 'relative',
			'left': posBg.left - 1240
		});
	}
		
	var slideCounter = 1;
	var slideTotal=0;
	var playing=true;
	var slideDuration=10000;
	function gallery(slideNum) {
		
		//if no IMGs have the show class, grab the first image
		if(!$('div.slides').hasClass('show')){
			var current = $('#gallery div.slides:first');
		}else{
			var current = $('#gallery div.slides.show');
		}
	
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		if( typeof(slideNum)==="undefined" ){
			if(slideCounter>=slideTotal){
				var next=$('#gallery div.slides:first');
				slideCounter=1;
			}else{
				var next=current.next();
				slideCounter++;
			}
		}else{
			slideCounter=slideNum;
			var next=$('#slide'+slideCounter);
		}
		
		//Get next image caption
		var caption = next.find('div').html(); 
		
		//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, function(){													
				$('.slideControl ul li').removeClass('slideSelected');
				$('.slideMarker'+slideCounter).addClass('slideSelected');
				return false;
			});

		//Hide the current image
		current.animate({opacity: 0.0}, 1000, function(){$(this).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: 1.0},100 ).animate({height: '600px'},500 );
		
		//Display the content
		$('#gallery .captionContent').html(caption);
		
	}
	
	function slideShow() {
		//Set the opacity of all images to 0
		$('#gallery div.slides').css({opacity: 0.0});
		
		//Get the first image and display it (set it to full opacity)
		$('#gallery div.slides:first').css({opacity: 1.0});
		
		//Set the caption background to semi-transparent
		$('#gallery .caption').css({opacity: 1.0});
	
		//Get the caption of the first image and display it
		$('#gallery .captionContent').html($('#gallery div.slides:first').find('div').html())
			.animate({opacity: 1.0}, 400);
			
		var run = setInterval('gallery()',slideDuration);
		
		//stop button
		$('#btn-pause').click(function () {
			clearInterval(run);
			$(this).hide();
			$('#btn-play').show();
			playing=false;
			return false;
		});
		
		//play button
		$('#btn-play').click(function () {
			gallery();
			run = setInterval('gallery()',slideDuration);
			$(this).hide();
			$('#btn-pause').show();
			playing=true;
			return false;
		});
		
		
		$('#gallery div.slideControl li').not('#playPause').click(function(){
			id=$(this).attr('id');
			
			//parseInt only works when strings begin with integers.  Since this would be an invalid id, we have to parse ints with regex
			var txt=id;
			var re1='.*?';	// Non-greedy match on filler
			var re2='(\\d+)';	// Integer Number 1
			var p = new RegExp(re1+re2,["i"]);
			var m = p.exec(txt);
			if (m != null){
			  id=m[1];
			} 
			
			
			if(!$('#slide'+id).hasClass('show')){
				if(playing===true){
					clearInterval(run);
					gallery(id);
					run = setInterval('gallery()',slideDuration);
				}else{ 
					gallery(id);
				}
			}
			return false;
		});
		
	}
	
	$(document).ready(function(){	
		$('div.slideControl').show();
		
		darkBarPosition();
		sliderControlPosition();
		bgPosition();
		setTimeout(sliderControlPosition,2000);
		setTimeout(darkBarPosition,2000);
				
		$(window).resize(function() {
			darkBarPosition();
			sliderControlPosition();
			bgPosition();
		});	
		
		
		$('div.slideControl li').hover(function(){
			$(this).addClass('hover');
			}, function(){
				$(this).removeClass('hover');
			});
			
		$('#gallery div.slides').each(function(i){
			slideTotal++;
			slideNum= 'slide'+(i+1);
			$(this).attr('id', slideNum);
		});
		
		$('#gallery div.slideControl li').not('#playPause').each(function(i){
			slideNum= 'control'+(i+1);
			$(this).attr('id', slideNum);
		});
	
		//Execute the slideShow
		slideShow();
		
		$('#btn-play').hide();
		
		$('#btn-pause').css('opacity',1);
		$('#btn-play').css('opacity',1);
		
		if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		  // search for selectors you want to add hover behavior to
		  //$('#btn-play').css('left',10);
		}
	});
