// JavaScript Document



		  /*
		page.tr.pauseNavigation = true;
		$("div.navigation").each(function() {
		$(this).children().each( function(idx) {
			if ($(this).is("a"))
				$(this).click(function() { page.tr.showItem(idx); return false; })
			});
		});
		*/
		
// var is_focused;
// var tmp_current = 0;
// $(window).focus(function() {	
	// if( is_focused == undefined ){ is_focused = true; };
	// if( is_focused != true ) { 
	  // page.tr = $(".area").fadeTransition({pauseTime: 1000, transitionTime: 1000, ignore: "#introslide", delayStart: 1000, pauseNavigation: false }); 

	// }
	// is_focused = true;
	
	
// });

// $(window).blur(function() {
	  // page.tr = $(".area").fadeTransition({pauseTime: 1000, transitionTime: 1000, ignore: "#introslide", delayStart: 1000, pauseNavigation: true }); 
	// is_focused = false;
// });	
	
var is_focused;
var tmp_current = 0;
(function ($) {
$.fn.fadeTransition = function(options) {
  var options = $.extend({pauseTime: 12000, transitionTime: 6000, ignore: null, delayStart: 500, pauseNavigation: false}, options);
  var transitionObject;
	
	  Trans = function(obj) {
		var timer = null;
		var current = tmp_current;
		var els = (options.ignore)?$("> *:not(" + options.ignore + ")", obj):$("> *", obj);
		$(obj).css("position", "relative");
		els.css("display", "none").css("left", "0").css("top", "0").css("position", "absolute");
		
		if (options.delayStart > 0) {
		  setTimeout(showFirst, options.delayStart);
		}
		else
		  showFirst();

		function showFirst() {
		  if (options.ignore) {	
			
			$(options.ignore, obj).fadeOut(options.transitionTime, function() {
			});	
			$(els[current]).fadeIn(options.transitionTime, function() {
			});				
			
			
		  }
		  else {
			$(els[current]).css("display", "block");
		  }
		}
	  
	$(window).focus(function() {		
		//if(options.pauseNavigation == true) {
			//setInterval( "this.forceNext()", 1000 );
			//setInterval("alert('Hello!')", 1000)
			//this.forceNext()
		//}
		//alert(options.pauseNavigation)
		//alert(options.pauseNavigation)
		if(options.pauseNavigation == true) {
			options.pauseNavigation = false;
		}
		
	});

	$(window).blur(function() {	
		options.pauseNavigation = true;
		//alert(options.pauseNavigation)
	});	
	
	var isActive;

		
	is_focused = true;
	function transition(next) {
		if (!options.pauseNavigation) {
			$(els[current]).fadeOut(options.transitionTime);		
			$(els[next]).fadeIn(options.transitionTime, function() {
				current = next;
				cue();
			});					
		}
	};

	function cue() {
	  if ($("> *", obj).length < 2) return false;
	  if (timer) clearTimeout(timer);
		timer = setTimeout(function() { transition((current + 1) % els.length | 0)} , options.pauseTime);
	  
	};
	
	this.showItem = function(item) {
	  if (timer) clearTimeout(timer);
	  transition(item);
	};

		cue();
  }

  this.showItem = function(item) {
	transitionObject.showItem(item);
  };

  return this.each(function() {
	transitionObject = new Trans(this);
  });
}

})(jQuery);

var page = {
	tr: null,
	init: function() {
	  page.tr = $(".area").fadeTransition({pauseTime: 5000, transitionTime: 3000, ignore: "#introslide", delayStart: 2000});
	  $("div.navigation").each(function() {
		$(this).children().each( function(idx) {
		  if ($(this).is("a"))
			$(this).click(function() { page.tr.showItem(idx); return false; })
		});
	  });
	  
	},	
	show: function(idx) {
	  if (page.tr.timer) clearTimeout(page.tr.timer);
	  page.tr.showItem(idx);
	}
};

$(document).ready(page.init);    

	
		

