
/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch( slideTo ) {
var $active = $('#slideshow IMG.active');

if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

var $next = $active.next().length ? $active.next():
$('#slideshow IMG:first');

$active.addClass('last-active');

// added “slideTo” variable to allow transition to a selected slide
// defaults to null, but if it’s >= 0, it will use this index for “$next”
var slideTo = ( slideTo+1 )? slideTo : null;
if ( slideTo != null ) $next = $('#slideshow IMG').eq(slideTo);

$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});

switchdivs();
}

function switchdivs(variable){
		splash1 = $("#splash1").attr("class");
		if(splash1 == "active"){
			$("#slide1").addClass(splash1);
		} else {
		$("#slide1").removeClass('active');	
		}
		
		splash2 = $("#splash2").attr("class");
		if(splash2 == "active"){
			$("#slide2").addClass(splash2);
		} else {
		$("#slide2").removeClass('active');	
		}
		
		splash3 = $("#splash3").attr("class");
		if(splash3 == "active"){
			$("#slide3").addClass(splash3);
		} else {
		$("#slide3").removeClass('active');	
		}
		
		splash4 = $("#splash4").attr("class");
		if(splash4 == "active"){
			$("#slide4").addClass(splash4);
		} else {
		$("#slide4").removeClass('active');	
		}
		
		$('#pausebutton').attr('title','pause');
}




$(document).ready(function(){

//update FIS after 10 seconds
//$.timer(10000, function (timer) {
 	//loadfis("arrive");
 	
//check search enter 	
// });

if ($.browser.mozilla) {
$("#searchinput").keypress(checkForEnter);
} else {
$("#searchinput").keydown(checkForEnter);
}


// hide all images except first to avoid initial flicker
$("#slideshow IMG").css({opacity: 0.0});
$("#slideshow IMG:first").css({opacity: 1.0});


// use setInterval to traverse list
var playSlideshow = setInterval( "slideSwitch()", 5000 );
// create buttons to move to specific slide

$("#pausebutton").click(function(){
	fireevent();
});

function checkForEnter(event) {
  if (event.keyCode == 13) {

 		document.islesearch.submit();
  } 
}


function fireevent(method){
				
		if(method == null){
			method = $('#pausebutton').attr("title");
			}
			
	if (method == "pause"){
			$('#pausebutton').attr('title','play');
			image = "<img src='images/btns/play.png'/>";
			$('#pausebutton').html(image)
			clearInterval(playSlideshow);
	}
	
	if (method == "play"){
		$('#pausebutton').attr('title','pause');
		image = "<img src='images/btns/pause.png'/>";
		$('#pausebutton').html(image)
		setTimeout( playSlideshow = setInterval( "slideSwitch()", 5000 ), 5000);
	}
}



var $slideButtons = $("#slide-buttons div.slide-button");
$slideButtons.click(function(){
// stop the slideshow, to keep it from trying to overlap our transition
clearInterval(playSlideshow);
// call the function using the index of the clicked button
//alert($slideButtons.index(this));
slideSwitch( $slideButtons.index(this) );
// restart the slideshow
setTimeout( playSlideshow = setInterval( "slideSwitch()", 5000 ), 5000);
});



//load calendar
				$('.date-pick').datepicker({
					dateFormat: 'dd/mm/yy',
					inline: true
				});

//end of calendar



//show schedules
loadfis("arrive");

$(".readmorelink").toggle(function() {
$(this).text("Read less");
}, function() {
$(this).text("Read more");
});


});

 jQuery.timer = function (interval, callback)
 {
	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };
 
 
 function loadfis(type){
 				var type = type;
 				var tab = $('#' + type + "_tab");
 				var host = $('#host').val();
			var urlprocess = host + "/process/fis.php";
			var parameters = "method=" + type;
   $.ajax({
   type: "GET",
   url: urlprocess,
   data: parameters,
   ajaxSend: $('#loadingschedule').show(),
   success: function(msg){
     $('#updateliveflights').html(msg);
     $('#loadingschedule').hide();
     	if(type == "arrive"){
     		$('#arrivals_tab').css("border-bottom","2px solid #c0143c");
     		$('#departure_tab').css("border-bottom","0px solid #c0143c");
     		$('#arrivalsliced').show();
     		$('#departsliced').hide();
     	} else {	
     		$('#arrivals_tab').css("border-bottom","0px solid #c0143c");
     		$('#departure_tab').css("border-bottom","2px solid #c0143c");
     		$('#arrivalsliced').hide();
     		$('#departsliced').show();
     	}
   //  alert(type);
     
	 }
 	});	
 }