var open;
var copen;
var iopen=false;
var popen=false;
var sopen=true;
var center = '50%';
var hide = '-80%';
$(document).ready(function() {

   
	$('#form1').validationEngine({
		ajaxSubmit: true,
		ajaxSubmitFile: 'ajaxSubmit.php',
		ajaxSubmitMessage: 'Thank you, We will contact you soon !',
		success: false,
		failure: function() {}
	});
	$('#t_icon').click(function() {
		if (open != true) {
			$('#tweets').animate({
				'right': '0px'
			}, 'slow', 'easeOutExpo', function() {
				$('#claim').animate({
					'right': '230px'
				}, 'slow', 'easeOutExpo');
			});
			open = true;
		} else {
			$('#tweets').animate({
				'right': '-220px'
			}, 'slow', 'easeInOutExpo', function() {
				$('#claim').animate({
					'right': '0px'
				}, 'slow', 'easeOutExpo');
			});
			open = false;
		}
	});
	$('#c_icon').click(function() {
		if (copen != true) {
			$('#form_div').animate({
				'top': '50%'
			}, 'slow', 'easeOutExpo');
			copen = true;
		} else {
			$('#form_div').animate({
				'top': '-100%'
			}, 'slow', 'easeInExpo');
			copen = false;
		}
	});
	
	
	function hideInfo (){
	$('#info_box').css({'top':'-300%'});
	
	}
	
	function hidePortfolio(){
	$('#portfolio').css({'top':'-300%'});
	}
	hideInfo();
	hidePortfolio();
	
	
	
	/*
	
	$('#i_icon').click(function() {
	
		
		if (iopen != true) {
			
			
			
			$('#info_box').animate({
				'top': '-200%'
			}, 'slow','easeInExpo', function() {
				$('.logo').animate({'top':'50%'},'slow', 'easeOutExpo')
			});
			$('#refresh').animate({'opacity':'1'},'easeInExpo');
			iopen = true;
			sopen = true;
		} else {
		
		$('#refresh').animate({'opacity':'0'},'easeInExpo');
		$('.logo').animate({'top':'200%'},'slow','easeInExpo',function(){$('#info_box').animate({'top':'50%'},'slow', 'easeOutExpo')});
	
			
			
			sopen = false;
			iopen = false;
			
		}
	});
	
	
	
	$('#p_icon').click(function() {
	
		$('#refresh').animate({'opacity':'0'},'easeInExpo');
		
		
		if (sopen==true && popen==true){
			$('.logo').animate({'top':'200%'},'slow','easeInExpo',function(){$('#portfolio').animate({'top':'50%'},'slow', 'easeOutExpo')});
			popen=false;
		} else if (iopen==false && popen==true){
		
		$('#info_box').animate({'top':'200%'},'slow','easeInExpo',function(){$('#portfolio').animate({'top':'50%'},'slow', 'easeOutExpo')});
			popen=false;
		
		}	
	
	});
	
		for (var i=0; i< aLength; i++){
		
			if (myContent[i] != '#info_box' ) {
		
				
				$(myContent[i]).animate({'top':'200%'},'slow','easeInExpo',function(){$('#info_box').animate({'top':'50%'},'slow', 'easeOutExpo')});
			}
			
		
		}
		$('#info_box').animate({'top':'50%'},'slow', 'easeOutExpo')

	
	*/
	
	$('#i_icon').click(function() {
		if(sopen==true){
		$('.logo').animate({'top':'200%'},'slow','easeInExpo',function(){$('#info_box').animate({'top':'50%'},'slow', 'easeOutExpo')} );
		
		iopen=true;
		sopen=false;
		popen=false;
		
		}
		if (popen==true){
		
		$('#portfolio').animate({'top':'200%'},'slow','easeInExpo',function(){$('#info_box').animate({'top':'50%'},'slow', 'easeOutExpo'), hidePortfolio();});
		
		
		iopen=true;
		popen=false;
		sopen=false;
		
		}
				
	});
	
	
	$('#p_icon').click(function() {
	
		if(sopen==true){
		$('.logo').animate({'top':'200%'},'slow','easeInExpo',function(){$('#portfolio').animate({'top':'50%'},'slow', 'easeOutExpo')});
		
		popen=true;
		sopen=false;
		iopen=false;
		
		}
		if (iopen==true){
		
		$('#info_box').animate({'top':'200%'},'slow','easeInExpo',function(){$('#portfolio').animate({'top':'50%'},'slow', 'easeOutExpo'), hideInfo();});
		
		
		popen=true;
		iopen=false;
		sopen=false;
		
		}
				
	});
	
function showHome(){
	$('.logo').delay(1500).animate({'top':center},1800,'easeInOutExpo',function(){ handHover(); $('#hand_start').delay(100).animate({'top':'-120%'},500,'easeInExpo');});

	$('.refresh').animate({'left':'0px'},'easeOutExpo')
	};

	function handHover(){
	
	// $('#hand_start').animate({'padding-left':'0px'});
	
	$('.hand_slider').rotate({animateTo: 1,duration: 500},'easeOutExpo');
	$('.finger_shadow').fadeTo(400,0.3)
	
	};
	
	showHome();
	
	
	
	$('#start_contact').click(function() {
		$('#form_div').animate({
			'top': '50%'
		}, 'slow', 'easeOutExpo');
		copen = true;
	});
	$('#tweets').jTweetsAnywhere({
		username: 'aimbush',
		count: 5,
		showTweetFeed: {
			paging: {
				mode: 'more'
			}
		}
	});
	$('.refresh').rotate({
		bind: {
			mouseover: function() {
				$(this).rotate({
					animateTo: 90,
					duration: 500
				})
			},
			mouseout: function() {
				$(this).rotate({
					animateTo: 0,
					duration: 500
				})
			}
		}
	});
	$('.refresh').bind('click', function() {
		var rotation = function() {
			$('#refresh').rotate({
				angle: 0,
				animateTo: 720,
				duration: 4000
			});
		}
		rotation();
		$.ajax({
			url: 'randomPic.php',
			type: 'GET',
			dataType: 'text',
			success: function(data) {
				$('#back_img').css('background-image', 'url("' + data + '")');
			}
		});
	});
});

