// JavaScript Document
$(document).ready (function (){
$('.tf_content p').hide();
$('#content1 p').show();
// Slider 
$('.dispensor').click(function (){
	$('.panel').slideToggle(1000);
});

	$('#petra').ready(function () {
 				  // tell your animation to stop after the page is loaded
  			 $('#loader').hide();
  			 
		 });

	$('#petraThumb').click( function(){
		
		backGround('#petra', '#content1', '#petraThumb');
		

	
	});
		$('#deadseaThumb').click( function(){
			backGround('#deadsea', '#content2', '#deadseaThumb');
		

	
	});
	$('#wadirumThumb').click( function(){
		backGround('#wadirum', '#content3', '#wadirumThumb');
	
	});
	$('#jerashThumb').click( function(){
		backGround('#jerash', '#content4', '#jerashThumb');
	
	});

	rotate = function() {

	    $(".allthumbs div").removeClass('selected'); //Remove all active class
	    $active.addClass('selected'); //Add active class (the $active is declared in the rotateSwitch function)

	    
	    if ($activeId == 'petraThumb') {
	        backGround('#petra', '#content1', '#petraThumb');
	        return false;


	    }
	    if ($activeId == 'deadseaThumb') {
	        backGround('#deadsea', '#content2', '#deadseaThumb');
	        return false;
	    }
	    if ($activeId == 'wadirumThumb') {
	        backGround('#wadirum', '#content3', '#wadirumThumb');
	        return false;
	    }

	    if ($activeId == 'jerashThumb') {
	        backGround('#jerash', '#content4', '#jerashThumb');
	        return false;
	    }


	};
	//Rotation  and Timing Event
	rotateSwitch = function() {
	    play = setInterval(function() { //Set timer - this will repeat itself every 7 seconds
	        $active = $('.allthumbs div.selected').next(); //Move to the next paging
	        $activeId = $active.attr('id');
	        if ($active.length === 0) { //If paging reaches the end...
	            $active = $('.allthumbs div:first'); //go back to first
	            $activeId = $active.attr('id');
	        }
	        rotate(); //Trigger the paging and slider function
	    }, 7000); //Timer speed in milliseconds (7 seconds)
	};

	rotateSwitch(); //Run function on launch



var backGround = function(imageId,contentId,thumbId){ // Show the Images
$('#loader').show();
$('.imageThumb').removeClass('selected');
$(thumbId).addClass('selected');
$(imageId).ready(function () {
 				  // tell your animation to stop after the image is ready
  			 $('.background').hide();
  			 $('.tf_content p').hide();
  			 $(contentId + ' p').show();
  			 $(imageId).fadeIn();
  			 $('#loader').hide();
  			
		 });

};
});
		


