$(function(){

// Top Navigation - Yee shall becometh visible post scrolling

$('body#homepage #topnav').css({opacity: '0', visibility: 'hidden'});

// Home - Play it Safe Umbrella

$("#safe .text").hover(
 function()
 {
  $('#safe .icon').stop().animate({rotate: '-10deg', marginTop: '-1px', marginLeft: '-5px'}, 500, 'easeIn', function(){
	  $('#safe .icon').animate({rotate: '-100deg', marginTop: '120px', marginLeft: '-5px'}, 800, function(){
		  $('#safe .icon').animate({rotate: '280deg', marginTop: '-180px', marginLeft: '0px'}, 1);
		  $('#safe .icon').animate({rotate: '0deg', marginTop: '0px', marginLeft: '0'}, 1000);
	  });
 });
 },
 function()
 {
  $('#safe .icon').stop().animate({rotate: '0deg', marginTop: '0px', marginLeft: '0'});
 }
);

// Page Break to 404
$('#safe .text').click(
	function(){
		$('.or1').animate({opacity: '0'}, 200, 'easeIn', function(){
		$('.or2').animate({rotate: '20deg', marginTop: '50px', opacity: '0'}, 100, 'easeIn', function(){
		$('#fun').animate({opacity: '0'}, 10);
		$('#fun').animate({opacity: '1'}, 10);
		$('#fun').animate({opacity: '0'}, 10);
		$('#fun').animate({opacity: '1'}, 80);
		$('#fun').animate({opacity: '0'}, 10);
		$('#fun').animate({opacity: '1'}, 200);
		$('#fun').animate({rotate: '-20deg', marginTop: '50px', opacity: '0'}, 100, 'easeIn', function(){
		$('#getintouch').animate({marginTop: '10px', opacity: '0'}, 100, 'easeIn', function(){
		$('.centerit').animate({opacity: '0'}, 100, 'easeIn', function(){
		$('.bodyCont').animate({opacity: '0'}, 100, 'easeIn');
		$('body').css({backgroundImage: 'none'}).animate({backgroundColor: '#000'}, 1000, function(){
		window.location = ('http://culturepilot.com/safe');
		});
		});
		});
		});
		});
		});
	});




// Home - Have Some Funnnnn Lightning

$("#fun .text").hover(
 function()
 {
 
  $('#fun .icon').stop(true).animate({rotate: '8deg', top: '5px'}, 500).stop(true).animate({rotate: '0deg', left: '700px', top: '400px'}, 500, function(){
	$('#fun .icon').css({rotate: '0deg', left: '-100px', top: '-180px'});
	  $('#fun .icon').animate({left: '200px', top: '0px'}, 200).animate({opacity: '0'}, 10).animate({opacity: '1'}, 10).animate({opacity: '0'}, 10).animate({opacity: '1'}, 80).animate({opacity: '0'}, 10).animate({opacity: '1'}, 200);
  })

 },
 function()
 {
  $('#fun .icon').stop().animate({rotate: '0deg', left: '200px', top: '0px'});
 }
);

$('#fun .text').click(
function(){
	window.location = ('http://culturepilot.com/funnnnn');
});

// Get in Touch

$("#getintouch .text").hover(
 function()
 {
  $('#getintouch .icon').stop().animate({rotate: '-100deg', marginLeft:'500px', marginTop: '-300px'}, 
  800, function(){
  $('#getintouch .icon').animate({rotate: '100deg', marginLeft: '-500px', marginTop: '300px'}, 1);
  $('#getintouch .icon').animate({rotate: '0deg', marginLeft: '200px', marginTop: '0px'}, 800);
  });
 
 },
 function()
 {
  $('#getintouch .icon').stop().animate({rotate: '0deg', marginLeft: '200px', marginTop: '0px'});
 }
);
$('#getintouch .text').click(
function(){
	window.location = ('http://culturepilot.com/contact');
	});

// Home Page Portfolio fade - Add class and fade in li.  Then fade out and remove class and add class to next one... etc.

$('#port').children('li').css({opacity: '0'});
$('#port li').first().addClass('onnn').css({opacity: '1'});

$(".message").hide();
$(".message").first().show();

var totalRecent = $('#homepage .recent li').size();
//console.log(totalRecent);
var switchCount = 0;
var timer;
var auto = true;


(function loop(){

if(auto){
		
		doIt();
		
		timer = setTimeout(loop,5000);
		
	}else{
		return;
		}

})();

function doIt(){
		switchCount= (totalRecent-1>switchCount)?switchCount+1: 0;
		$('#homepage .recent li').eq(switchCount).trigger('click');
		//switchEm();
}



/*
function switchEm(){

	if(auto){
		timer = setTimeout(doIt,5000);
	} else{
		return;
		}
}

function doIt(){
		switchCount= (totalRecent-1>switchCount)?switchCount+1: 0;
		$('#homepage .recent li').eq(switchCount).trigger('click');
		switchEm();
}

switchEm();
*/

// Home Page Portfolio Title Bar (needs some brain juice from Javier)

$(".recent").hover(function(){
clearTimeout(timer);
	auto = false;
},function(){
auto = true;
loop();
//switchEm();
});


$("#homeFrameOutter").hover(
 function(){
	clearTimeout(timer);
	auto = false;
	$('.onnn img').eq(0).hide();
	$('.titlebar').css({borderTopWidth:"12px"});
	$('.titlebar').stop().animate({rotate: '-7deg', marginTop: '-100px', opacity:"1"}, 200);
	},
function(){
	$('.onnn img').eq(0).show();		
	
	$('.titlebar').animate({borderTopWidth:"0px"}, function(){
		$('.titlebar').animate({rotate: '20deg', marginTop: '400px', opacity:"0"}, 100);

		});
	}
);

$("#homeFrameOutter").click(function(){

var url = $('.onnn a').attr("href");
window.location = url;

})


$("#homepage ul.recent li").hover(
 function()
 {
 
  $(this).children('a').children('.plus').css({visibility: 'visible'});
  $(this).children('a').css({fontSize: "14px"});
  $(this).css({marginBottom: '-1px'});
  $(this).children('a').stop().animate({marginLeft: '15px'}, 100);
 },
 function()
 {
 if( $(this).attr("class") !="marked"){
 $(this).children('a').children('.plus').css({visibility: 'hidden'});
 $(this).children('a').css({fontSize: "10px"});
 $(this).css({marginBottom: '0px'});
 $(this).children('a').stop().animate({marginLeft: '0px'}, 800);
 }
 }
);
		
	
$('#homepage .recent li').each(function(index){
$(this).click(
    function(event){
	switchCount=index;
	event.preventDefault();

		$('.onnn').animate({top: '-10px', opacity: '0'}, 200);
		$('#port').children('.onnn').removeClass('onnn');
		$("#port li").eq(index).addClass('onnn'); 
		
		$(".message").hide();		
		$(".message").eq(index).show();		
		$('.onnn').css({top: '10px'});
		$('.onnn').delay(200).animate({top: '0px', opacity: '1'}, 500);
		
		$("ul.recent li a").css({fontSize: "10px", color: '#8a8a8a'});
		$("ul.recent li a").animate({marginLeft: '0'}, 100);
		//$("ul.recent li").css({background: 'url()'});
		$("ul.recent li a").children('.plus').css({visibility: 'hidden'});
		$(".marked").removeClass("marked"); 
		$("ul.recent li").eq(index).addClass('marked'); 
		
		$(this).children('a').children('.plus').css({visibility: 'visible'});
		$(this).children('a').css({fontSize: "14px", color: '#fff'});
		//$(this).css({marginBottom: '-1px',  background: 'url(http://culturepilot.com/img/recent-li-bg.png) 0 -20px no-repeat' });
		//$(this).attr("style","marginBottom: '-1px',  background: 'url(http://culturepilot.com/img/recent-li-bg.png) 0 -20px no-repeat'");
		//$("ul.recent li").eq(index).attr("style","marginBottom: '-1px',  background: 'url(http://culturepilot.com/img/recent-li-bg.png) 4px 4px no-repeat'");
		$(this).children('a').animate({marginLeft: '15px'}, 100);
		//$(this).animate({backgroundPosition: '4px 4px'}, 100);
		//$("ul.recent li").eq(index).animate({backgroundPosition: '4px 4px'}, 100);
	    });
})
	
	$('#homepage .recent li').eq(0).trigger('click');
	
// Local Bicycle

$('.header.community').hover(
	function(){
		$('.community .text').css({backgroundPosition: 'left bottom'});
		$('.community .icon').stop().animate({marginLeft: '100%'}, 600, function(){
		$('.community .icon').css({marginLeft: '-1000px'});
		$('.community .icon').animate({marginLeft: '0px'});
		});
	},
	function(){
		$('.community .text').css({backgroundPosition: 'left top'});
		$('.community .icon').stop().animate({marginLeft: '0px'});
	}
);

$('.header.community').click(
function(){

	window.location = ('http://culturepilot.com/community');
	
	});


// Abroad Jet

$('.header.goodcompany').hover(
	function(){
		$('.goodcompany .text').css({backgroundPosition: 'left bottom'});
		$('.goodcompany .icon').stop().animate({left: '240px', top: '100px'}, 400, 'easeIn', function(){
		$('.goodcompany .icon').css({left: '-440px', top: '-200px'});
		$('.goodcompany .icon').animate({left: '3px', top: '-20px'}, 1000, 'easeOut');
		});
	},
	function(){
		$('.goodcompany .text').css({backgroundPosition: 'left top'});
		$('.goodcompany .icon').stop().animate({left: '3px', top: '-20px'});
	}
);	

$('.header.goodcompany').click(
function(){

	window.location = ('http://culturepilot.com/goodcompany');
	
	});

});
		




