$.fn.prepStart = function (options){
  var defaults = {
    visibility: 'visible',
    opacity: 0.0,
    zIndex:1000,
    'filter':'alpha(opacity=0)'
  };
  return this.stop(true).css($.extend(defaults,options));
}

$.fn.prepEnd = function (options){
  var defaults = {
    opacity: 1.0,
    zIndex:100,
    'filter':'alpha(opacity=100)'
  };
  return this.stop(true).css($.extend(defaults,options));
}


Fuel.PageController.add_page_transition(1, function(callback){
	$layer1.prepStart().animate({opacity: 1.0, top: 0}, 500, "easeInOutQuint", function(){
	  $(this).css({'filter':'none'});
	  callback();
	});
	
}, function(callback){
	$layer1.prepEnd().animate({opacity: 0.0, top: -200 }, 500, "easeInOutQuint", function(){
	  $(this).css({visibility:'hidden'});
	  callback()
	});
}, "#1c4d89");


Fuel.PageController.add_page_transition(3, function(callback){
	$core.prepStart().animate({opacity: 1.0}, 500, "easeInOutQuint", function(){
	  $(this).css({'filter':'none'});
	  callback();
	});
}, function(callback){
	$core.prepEnd().animate({opacity: 0.0 }, 500, "easeInOutQuint", function(){
	  $(this).css({visibility:'hidden'});
	  callback()
	});
}, "#c17508");





// DOM Ready
jQuery(function($){			

  // $layer1 = $("#layer1").css({
  //  opacity: 0.0, display:"block", top: -200
  // });
	
	$layer1 = $("#layer1").css({display: 'block', visibility: 'hidden', top: -200});
	$core = $("#core").css({display: 'block', visibility: 'hidden'});
	$news = $("#news").css({display: 'block', visibility: 'hidden'});
	$press = $("#press").css({display: 'block', visibility: 'hidden'});
	$engage = $("#engage").css({display: 'block', visibility: 'hidden'});
	

	
	$("#goal div.inline-link").each(function(){
		var $this = $(this),
				$popup = $this.find('.popup');
				
				$popup.css({right: -425}).hide();
				
				$this.bind('mouseover', function(e){
					if(e.target !== this) return;
					$popup.show().stop(true).animate({ opacity: 1.0, right: -414}, 200)
				}).bind('mouseout',function(e){
					if(e.target !== this) return;
					$popup.animate({ opacity: 0.0, right: -425}, 200, function(){
						$(this).hide();
					})							
				});
	});
	
		$("#core div.inline-link").each(function(){
		var $this = $(this),
				$popup = $this.find('.popup');
				
				$popup.css({right: -425}).hide();
				
				$this.bind('mouseover', function(e){
					if(e.target !== this) return;
					$popup.show().stop(true).animate({ opacity: 1.0, left: -414}, 200)
				}).bind('mouseout',function(e){
					if(e.target !== this) return;
					$popup.animate({ opacity: 0.0, left: -425}, 200, function(){
						$(this).hide();
					})							
				});
	});
	
$("#core2 div.inline-link").each(function(){
		var $this = $(this),
				$popup = $this.find('.popup');
				
				$popup.css({right: -425}).hide();
				
				$this.bind('mouseover', function(e){
					if(e.target !== this) return;
					$popup.show().stop(true).animate({ opacity: 1.0, left: -414}, 200)
				}).bind('mouseout',function(e){
					if(e.target !== this) return;
					$popup.animate({ opacity: 0.0, left: -425}, 200, function(){
						$(this).hide();
					})							
				});
	});	
	
	$.History.bind(function(fragment){
		
		var page = fragment.split('/');
		if(page.length > 1){
			var p = 0;
			switch(page[1]){
				case 'web_solutions':
				p = 1;
				break;
				case 'companies':
				p = 2;
				break;
				case 'pc_solutions':
				p = 3;
				break;
		
			}
			if(p > 0){
				Fuel.PageController.changePage( p );
				$("#show-nav").trigger('mouseover');
			}
		}
	})
})
