// JavaScript Document
$(document).ready(function() {     
  		
		var currentPage = 1;
		var pages = 6;
		var directory = "/product-tour/";
		
	  //select all the a tag with name equal to modal   
	  $('a[name=modal]').click(function(e) {   
		  //Cancel the link behavior   
		  e.preventDefault();   
		  //Get the A tag   
		  var id = $(this).attr('href');   
		 if(id == '#agencytour')
		 {
			 directory = "/agency-tour/";
			 pages = 8;
		 }
		   pages = $('.tourmenu-link-normal-back').length;
		   		   
		   for(var x = 1; x <= pages;x++)
		   {				
				$('.tourmenu-link-normal-back:eq(' + x + ')').attr('name', x + 1);   
		   }
		   
		   $('.tourmenu-link-normal-back:first').attr( 'class', 'tourmenu-link-selected-back');
		   $('#tour-back').hide(); 
    	   $("#tour-inner-center").load(directory + '1'); 
		  
		  //Get the screen height and width   
		  var maskHeight = $(document).height();   
		  var maskWidth = $(window).width();   
		 
		  //Set height and width to mask to fill up the whole screen   
		  $('#mask').css({'width':maskWidth,'height':maskHeight});   
			 
		  //transition effect        
		  $('#mask').fadeIn(1000);       
		  $('#mask').fadeTo("slow",0.8);     
		 
		  //Get the window height and width   
		  var winH = $(window).height();   
		  var winW = $(window).width();   
				   
		  //Set the popup window to center   
		  $('#tour').css('left', winW/2-$('#tour').width()/2);   
		 
		  //transition effect   
		  $('#tour').slideDown("slow");
		  $('#tour-menu').fadeIn(2000);
		  $('#tour-inner').fadeIn(2000);
		  $('#tour-footer').fadeIn(2000);
		 
	  });   
	  
		//Top menu
		$(".tourmenu-link-normal-back").click(function(){ 
	        currentPage = $(this).attr('name');
            
			$('#tour-next').show(); 				
			 $('#tour-back').show(); 				

			if(currentPage == '1' || currentPage == undefined) 
			{
				 $('#tour-back').hide(); 				

			}
			
			if(currentPage == pages) 
			{
				 $('#tour-next').hide(); 				
			}
			
			$('.tourmenu-link-selected-back').attr( 'class', 'tourmenu-link-normal-back');
    	 	$(this).attr( 'class', 'tourmenu-link-selected-back');
    	 	$("#tour-inner-center").load('/blank/?a='+$(this).attr('id')+''); 
		 }); 

	//if back button is clicked   
	  $('#tour-back').click(function (e) {   
		  //Cancel the link behavior   
		  e.preventDefault();   
		  currentPage--;


		   $('.tourmenu-link-selected-back').attr( 'class', 'tourmenu-link-normal-back');
		   for(var x = 0; x < pages;x++)
		   {
				if(x == currentPage-1) 
				{
					$('.tourmenu-link-normal-back:eq(' + x + ')').attr('class', 'tourmenu-link-selected-back');   
				}
			}
			
		  if(currentPage > 1)
		  {
			 $('#tour-next').show(); 
		  }
		  else
		  {
			 $('#tour-back').hide(); 
		  }
		  if(currentPage > 0)
		  {
		    $("#tour-inner-center").load(directory + currentPage+''); 			  			  
		  }
	
	});        

	  //if next button is clicked   
	  $('#tour-next').click(function (e) {   
		  //Cancel the link behavior   
		  e.preventDefault();   
		  currentPage++;
		  
		  $('.tourmenu-link-selected-back').attr( 'class', 'tourmenu-link-normal-back');
			for(var x = 0; x < pages;x++)
		    {
				if(x == currentPage-1) 
				{
					$('.tourmenu-link-normal-back:eq(' + x + ')').attr('class', 'tourmenu-link-selected-back');   
				}
			}
			
		  if(currentPage < pages)
		  {
			$('#tour-back').show(); 
		  }
		  else
		  {
			 $('#tour-next').hide(); 
		  }		  

		  if(currentPage <= pages)
		  {
			$("#tour-inner-center").load(directory + currentPage+''); 			  			  
		  }

	});        

	  //if next button is clicked   
	  $('#tour-take-tour').click(function (e) {   
		  
		 //Cancel the link behavior   
		  e.preventDefault();   
		  currentPage++;
		  
		  $('.tourmenu-link-selected-back').attr( 'class', 'tourmenu-link-normal-back');
			for(var x = 0; x < pages;x++)
		    {
				if(x == currentPage-1) 
				{
					$('.tourmenu-link-normal-back:eq(' + x + ')').attr('class', 'tourmenu-link-selected-back');   
				}
			}
			
		  if(currentPage < pages)
		  {
			$('#tour-back').show(); 
		  }
		  else
		  {
			 $('#tour-next').hide(); 
		  }		  

		  if(currentPage <= pages)
		  {
			$("#tour-inner-center").load(directory + currentPage+''); 			  			  
		  }		  
	  });        

		//if close button is clicked   
	  $('#tour-closer').click(function (e) {   
		  //Cancel the link behavior   
		  e.preventDefault();   
		  $('#tour-menu').hide();
		  $('#tour-inner').hide();
		  $('#tour-footer').hide();
		  $('#tour').slideUp("slow");
		  $('#mask').hide();   
	  });        
		 
	  //if mask is clicked   
	  $('#mask').click(function () {   
		  $('#tour').hide();   
		  $('#mask').hide();   
	  }); 
  
	  });   

