$('document').ready(function() {

   //Part to be initialized ---------------------------------------------------

   var firstImage_id = 1;                               //First image number
   //var lastImage_id;                                //Last image number
   var right_arrow = "#content_wrapper #arrow_right";   //path of the right arrow
   var left_arrow = "#content_wrapper #arrow_left";     //path of the left arrow
   var slideContainer_id = "#home_banner_";             //path of the image container minus id number only

   //End of part to be initialized --------------------------------------------


   //Show 1st image, hide others
   for(var i=firstImage_id+1; i<=lastImage_id; i++){
       $(slideContainer_id+i).css('display', 'none');
   }

   //Show arrows with delay
   $(left_arrow).animate({ left : '0px', easing: 'easeOutQuint' }, 500);
   $(right_arrow).animate({ right : '0px', easing: 'easeOutQuint' }, 500);
   
   //Roll over effect on #left_arrow
   $('#arrow_left').each(function() {
		$(this).hover(function() {
			$(this).stop().animate({ left : '-14px', opacity: 0.8, easing: 'easeOutQuint' }, 300);
		},
	   function() {
			$(this).stop().animate({ left : '0px', opacity: 1.0, easing: 'easeOutQuint' }, 300);
	   });
	});
	
	//Roll over effect on #right_arrow
   $('#arrow_right').each(function() {
		$(this).hover(function() {
			$(this).stop().animate({ right : '-14px', opacity: 0.8, easing: 'easeOutQuint' }, 300);
		},
	   function() {
			$(this).stop().animate({ right : '0px', opacity: 1.0, easing: 'easeOutQuint' }, 300);
	   });
	});
   

   //Initialize
   var autoSlide = "";
   var currentPicture = 1;

   function nextSlide(transSpeed) {
       
       if (transSpeed != 100) {
           transSpeed = 2000;
       }

       var nextPicture = currentPicture;
       if(nextPicture <= lastImage_id-1) {
       nextPicture = nextPicture +1;
       $(slideContainer_id+currentPicture).fadeOut(transSpeed);

       $(slideContainer_id+nextPicture).fadeIn(transSpeed);
       currentPicture = nextPicture;
       }
       else {
           $(slideContainer_id+currentPicture).fadeOut(transSpeed);

           $(slideContainer_id+1).fadeIn(transSpeed);
           currentPicture = 1;
       }
   }

   function prevSlide(transSpeed) {
       
       if (transSpeed != 100) {
           transSpeed = 2000;
       }
       
       var prevPicture = currentPicture;
       if(prevPicture >= firstImage_id+1) {
           prevPicture = prevPicture -1;
           $(slideContainer_id+currentPicture).fadeOut(transSpeed);
           $(slideContainer_id+prevPicture).fadeIn(transSpeed);
           currentPicture = prevPicture;
       }
       else {
           $(slideContainer_id+currentPicture).fadeOut(transSpeed);
           $(slideContainer_id+lastImage_id).fadeIn(transSpeed);
           currentPicture = lastImage_id;
       }
   }

   //Set autoSlide
   window.clearInterval(autoSlide);
   autoSlide = window.setInterval(nextSlide, 6000);
   
   //Set actions on click
   $(right_arrow).click(function() {
       window.clearInterval(autoSlide);
       nextSlide(100);
       autoSlide = window.setInterval(nextSlide, 6000);
   });
   
   $(left_arrow).click(function() {
       window.clearInterval(autoSlide);
       prevSlide(100);
       autoSlide = window.setInterval(nextSlide, 6000);
    });
});

