$(document).ready(function() {		
	
	//Execute the slideShow, set 4 seconds for each images
	slideShow(4500);
});

function slideShow(speed) {

	//append or add the MAIN IMAGE list for browsers with scripting	
	//$('ul#mainSlideshow') .append('<li><a href="#"><img src="../images/admin/banner2.gif" width="680" height="152" alt="North West Residential Support Services Inc Helping people create homes" /></a></li><li><a href="#"><img src="../images/admin/banner3.gif" width="680" height="152" alt="POO NO3" /></a></li>');
	//Set the birds opacity to 0
	$('.birds').css({display: 'block'});
	$('.birds').css({opacity: 0,top:32,left:0});
	$('.intro').css({display: 'block'});
	$('.night').css({display: 'block',top:0, left:0});
	$('.slide1').css({left:70});
	$('.slide2').css({left:-70});
	$('.slide3').css({opacity:0});
	$('.slide4').css({opacity:0});

//mouseOver functions for main buttons to turn lights on... java used here to replace sudo hover class as it doesn't work with mobile devices.
 $("a.links").mouseover(function() {
	$('#linkPic').css({display:'block'});
  }).mouseout(function(){
    $('#linkPic').css({display:'none'});
  });
 $("a.home").mouseover(function() {
	$('#homePic').css({display:'block'});
  }).mouseout(function(){
    $('#homePic').css({display:'none'});
  });
 $("a.contact").mouseover(function() {
	$('#contactPic').css({display:'block'});
  }).mouseout(function(){
    $('#contactPic').css({display:'none'});
  });
	
	
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
		
	//Display the caption NOTE I changed this to 0 because I didn't want the caption to show it was 0.7
	$('#slideshow-caption').css({opacity: 0, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li: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().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//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}, 4500);
	
	$('.birds') .animate ({opacity:1,top:-62,left:-62 }, 6000, 'swing').animate ({opacity:0,top:-72,left:-72 }, 30).animate ({opacity:0,top:32,left:100 },6000).animate ({opacity:1,top:-62,left:162 }, 6000).animate ({opacity:0,top:-72,left:-72 }, 30).animate ({opacity:0,top:32,left:0 }, 6000 );

	//run the intro animation then slide it from view.
	$('.slideA').animate({opacity:0},500).animate({opacity:0},1500).animate({opacity:0},3000).animate({opacity:0, top:-300},2000);;
	$('.slide1').animate({opacity:1,left:0},1000).animate({opacity:1},1000).animate({opacity:1},3000).animate({opacity:0, top:-300},2000);;
	$('.slide2').animate({opacity:1, left:0},1000).animate({opacity:1},1000).animate({opacity:1},3000).animate({opacity:0, top:-300},2000);;
	$('.slide3').animate({opacity:0},1000).animate({opacity:1},1000).animate({opacity:1},3000).animate({opacity:0, top:-300},2000);;
	$('.slide4').animate({opacity:0},1000).animate({opacity:1},1000).animate({opacity:1},3000).animate({opacity:0, top:-300},2000);
	$('.slide5').animate({opacity:1},500).animate({opacity:1},1500).animate({opacity:1},3000).animate({opacity:0, top:-300},2000);
	//make the night image fade in and out simulating day and night
	$('.night').animate({opacity:1},9000).animate({opacity:0},9000).animate({opacity:0},18000);
	 
	 
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption').animate({bottom:-70}, 300, function () {
			//Display the content
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);				
			$('#slideshow-caption').animate({bottom:0}, 500);	
	});	
	
	//Hide the current image
	current.animate({opacity: 0.0}, 4500).removeClass('show');

}



//<div class="floatingpanel">
         //       <p><img src="../images/admin/lights3.gif" width="680" height="152" alt="Link Lights"/></p>
         //   </div>
 //Code for the pop-up annimation
 //$(".moreinfo").each(function(){
//		var t;
	//	var isanimated = false;
	//	var isvisible = false;
	//	var popup = $(".floatingpanel",this);
	//$(this).mouseover(function(){
	//		if (t) clearTimeout(t);
	//		if (!isvisible && !isanimated){
	//			isanimated = true;
	//			popup.css({opacity:0,display:"block",marginTop:0}).animate({marginTop:-62,opacity:1},0, function(){isanimated=false;isvisible=true;});
				
	//		} else {
	//			return;
//			}
	//	}).mouseout(function(){
	//		if (t) clearTimeout(t);
	//	if (!isanimated && isvisible){
//				t = setTimeout(function(){isanimated=true;
//										popup.animate({marginTop:-10,opacity:0},400, function(){popup.css({display:"none"});isvisible=false;isanimated=false;});}, 200);
//			} else {
//				return;
		//	}
	//	});
	
	 //fix the ipad and iphone etc hover effect for mainNav
	 //ipad and iphone fix
//if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    
		//		$('.iphone').remove();
//
        //we just need to attach a click event listener to provoke iPhone/iPod/iPad's hover event
        //strange
//}

	//});	
							 

