/**
 * Rotating Functions 
 * http://www.alohatechsupport.net/webdesignmaui/maui-web-site-design/easy_jquery_auto_image_rotator.html
 */

function theRotator() {
	$('div#rotator ul li').css({opacity: 0.0});
	$('div#rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()', 3000);
}
 
function rotate() {	
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

$(window).scroll(function() {
   	var t = $(window).scrollTop();
	$("#tour-info").css("top", (t>245) ? (t-245) + "px" : "0px");
});

$(document).ready(function() { 
		/* Highlight */
		var pathname = window.location.pathname;
		pathname = pathname.split("/");
		pathname = pathname[pathname.length-1];
		/* Flash Header */
		
		// Pathname control
		
		switch(pathname) {
			case 'incajungle4dias.html':
				pathname = 'santateresa_river_rafting.html';
			break;
			
			case 'rio_urubambatropical.html':
				pathname = 'urubamba_river_1d.html';
			break;
			
			case 'tambopatarafting9dias.html':
				pathname = 'huchuyqosqo.html';
			break;
			
			case '':			
			case 'cusco_adventuretour10d.htmll':
			case 'inca-trail-availability.html':
			case 'our_guides.html':
			case 'testimonials.html':
			case 'links.html':
			case 'booking_form.php':
			case 'contact-us.php':
			case 'reserve.php':
			case 'huchuyqosqo_machupicchu.html':
			case 'peru_adventure_15d.html':
			case 'about_us.html':
			case 'inca_jungle_3d.html':
			case 'inca_jungle_int4d.html':
			case 'cusco_adventuretour_int10d.html':
			case 'perutour10days.html':
			case 'vacations_peru_int15d.html':
			case 'holidays_peru_intro15d.html':
			case 'holidays_peru_15d.html':
			case 'cuscobike_marasmoray.html':
			case 'laresbike3d.html':
			case 'peru_travel_information.html':
				pathname = 'index.html';
			break;
		}
		
		// Hardcoding for rotator
		if(pathname != 'index.html') {
			$('<ul></ul>')
				.append($('<li></li>').addClass('show')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/01.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/02.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/03.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
			.appendTo('#rotator');
		}else{
			$('<ul></ul>')
				.append($('<li></li>').addClass('show')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/01.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/02.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/03.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/04.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
				.append($('<li></li>')
					.append($('<img />')
						.attr({src: '/extras/headers/' + pathname + '/05.jpg', width: 560, height: 150, alt: 'River Explorers - Peru Adventure'})
							)
						)
			.appendTo('#rotator');
		}
		
		theRotator();
		
		/*$('#swf').flash({
				swf: '/extras/flash/' + pathname + '.swf'
				,width:560
				,height:150
				,wmode:'transparent'
		});*/
		
		/* Lightbox */
		$('a.lightbox').lightBox();
	
	/* Inca Trail */
	var loading = '<img src="/extras/images/ajax-loader.gif" alt="Loading" />';
	$('#viewav').bind("click", function() {
		$('#itresults').empty();								 
		$('#itresults').append(loading);
		m = $('#dateav').val().split("-")[0];
		a = $('#dateav').val().split("-")[1];
		l = $('#lang').val();
		$.ajax({
			type: "GET",
			url: "/itresults.php",
			data: "mes="+m+"&ano="+a+"&lang="+l,
			success: function(msg){
			$('#itresults').empty();
			$('#itresults').append(msg);
		}
		});
	});
	
	/* Collapsable */
	// Menus Colapsables
	$('.col-title').bind('click', function() {
		$(this).next().slideToggle();
	});
		
}); //document.ready
