jQuery.fx.interval = 50;


$(document).ready(function() {
	

	var my_pane = $("html, body");
	var winWidth = $('#frame').width();
	$('.overlay').width(winWidth);
	$(".overlay").delay(2000).fadeOut(1000);
		
	(function parallaxObj($) {
		$.fn.parallax = function(options) {
			var $$ = $(this);
			offset = $$.offset();
			var defaults = {
				"start": 0,
				"stop": offset.top + $$.height(),
				"coeff": 0.95
			};
			var opts = $.extend(defaults, options);
			return this.each(function() {
				$(window).bind('scroll', function() {
	windowTop = $(window).scrollTop();
					if ((windowTop >= opts.start) && (windowTop <= opts.stop)) {
						newCoord = windowTop * opts.coeff;
						$$.css({
							"top": newCoord + "px",
	
							//"opacity": parseInt(newCoord) / 300
						});
							//$$.fadeTo(0, parseInt(newCoord) / 300);
					}
				});
			});
		};
		
	})(jQuery);
	

	$('.square_1').parallax({
		"coeff": 0.1
	});
	$('.square_2').parallax({
		"coeff": 0.15
	});
	$('.square_3').parallax({
		"coeff": 0.20
	});
	$('.shape_5_10').parallax({
		"coeff": 0.20
	});
	$('.shape_5_12').parallax({
		"coeff": 0.1
	});
	$('.shape_5_13').parallax({
		"coeff": -0.1
	});
	$('#cloud_1').parallax({
		"coeff": 0.3
	});
	$('#cloud_2').parallax({
		"coeff": 0.2
	});
	$('#cloud_3').parallax({
		"coeff": 0.1
	});
	$('#cloud_4').parallax({
		"coeff": -0.2
	});
	$('#cloud_5').parallax({
		"coeff": -0.2
	});
	$('#cloud_6').parallax({
		"coeff": -0.2
	});
	$('#cloud_7').parallax({
		"coeff": -0.2
	});
	$('.rain_1').parallax({
		"coeff": -0.4
	});
	$('.rain_2').parallax({
		"coeff": -0.2
	});
	$('.shape_6_1_1').parallax({
		"coeff": 0.1
	});
	$('.shape_6_3').parallax({
		"coeff": 0.2
	});
	$('.shape_6_4').parallax({
		"coeff": 0.15
	});
	$('.shape_7_6').parallax({
		"coeff": -0.1
	});
	$('.shape_7_7').parallax({
		"coeff": 0.1
	});

	
	
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {

} else {
	 $.waypoints.settings.scrollThrottle = 50;
	 $('#frame').waypoint(function(event, direction) {
		$('#nav').delay(400).toggleClass('floating', direction === "down").toggleClass('floating_h', 300, 'easeInOutCirc');
		$('.btn_1').delay(400).toggleClass("btn_1_floating", 300, 'easeInOutCirc');
		$('.btn_2').delay(400).toggleClass("btn_2_floating", 300, 'easeInOutCirc');
		$('.btn_3').delay(400).toggleClass("btn_3_floating", 300, 'easeInOutCirc');
		$('.btn_4').delay(400).toggleClass("btn_4_floating", 300, 'easeInOutCirc');
		event.stopPropagation();
	},{ offset: -325}); 
	
	
	var goTop = 0;
	var goBottom = 2208;
	
	
	$(window).scroll(function() {
		var documentTop = $(document).scrollTop();
		if(documentTop < 600){
		 	$('#arrows').filter(":not(:animated)").fadeOut(500, 'easeInOutCubic');
		} else {
			$('#arrows').filter(":not(:animated)").fadeIn(500, 'easeInOutCubic');
		}
		if(documentTop >= 750 && documentTop <= 2207){
			goTop = 0;
			goBottom = 2208;
		} else if(documentTop >= 2208 && documentTop <= 3580){
			goTop = 750;
			goBottom = 3581;	
		} else if(documentTop >= 3581 && documentTop <= 5179){
			goTop = 2208;
			goBottom = 5180;	
		} else if(documentTop >= 5180 && documentTop <= 7034){
			goTop = 3581;
			goBottom = 7035;
			$('.arrow_bottom').filter(":not(:animated)").fadeIn(500, 'easeInOutCubic');	
		} else if(documentTop >= 7035){
			goTop = 5180;
			$('.arrow_bottom').filter(":not(:animated)").fadeOut(500, 'easeInOutCubic');
		} 
	});
	
		
	

	
	
	
	
	
	
	$('.arrow_top').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: goTop
		}, 3000, 'easeInOutCubic');
	});
	$('.arrow_bottom').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: goBottom
		}, 3000, 'easeInOutCubic');
	});
	
}

	
	$("#twitter").getTwitter({
		userName: "guilhermembento",
		numTweets: 2,
		loaderText: "Carregando tweets...",
		slideIn: true,
		showHeading: true,
		headingText: "Tweets recentes da Vekttor",
		//showProfileLink: true
	});


	//Set slider container width	
  
	/*var $pArr = $('#slider_portfolio_web .box_panel');
	var pArrLen = $pArr.length;
	var pPerDiv = 6;
	for (var i = 0;i < pArrLen;i+=pPerDiv){
		$pArr.filter(':eq('+i+'),:lt('+(i+pPerDiv)+'):gt('+i+')').wrap('<li />');
	}*/
	
	while ($("#slider_portfolio_web > div[class^='box_panel']").size() >= 1)
 	 $("#slider_portfolio_web > div[class^='box_panel']:lt(6)").wrapAll("<li></li>")
	while ($("#slider_portfolio_sistemas > div[class^='box_panel']").size() >= 1)
 	 $("#slider_portfolio_sistemas > div[class^='box_panel']:lt(6)").wrapAll("<li></li>")
	while ($("#slider_portfolio_app > div[class^='box_panel']").size() >= 1)
 	 $("#slider_portfolio_app > div[class^='box_panel']:lt(6)").wrapAll("<li></li>")
	
	
	function SetSliderWidth() {
		var sum = 0;
		var sum2 = 0;
		var sum3 = 0;
		var sum4 = 0;
		$('#slider_services li').each(function() {
			sum += $('#frame').width();
		});
		$('#slider_services').width(sum);
		
		$('#slider_portfolio_web li').each(function() {
			sum2 += $('#frame').width();
		});
		$('#slider_portfolio_web').width(sum2);
		
		$('#slider_portfolio_sistemas li').each(function() {
			sum3 += $('#frame').width();
		});
		$('#slider_portfolio_sistemas').width(sum3);
		
		$('#slider_portfolio_app li').each(function() {
			sum4 += $('#frame').width();
		});
		$('#slider_portfolio_app').width(sum4);
		
		//alert(sum);
	}
	
	
	 
	SetSliderWidth();

		//When page loads...
		 //Hide all content
		//$("body .slider_2:not(:first)").delay(5000).fadeOut(2000);
		//$("body .slider_2:not(:first)").css({opacity: 0.0, visibility: "visible"}).animate({opacity: 0.0})

	function resizeWindow(e) {

		var newWindowHeight = $(window).height();
		var newWindowWidth = $('#frame').width();
		$('#slider_1').width(newWindowWidth);
		$('#anythingSlider_1').width(newWindowWidth);
		$('#anythingWindow_1').width(newWindowWidth);
		$('#slider_services li').width(newWindowWidth);
		$('#lbOverlay').width(newWindowWidth);
		

		SetSliderWidth();
		
	}

	$(window).bind("resize", resizeWindow);


	//Nav buttons functions
	/*$('a.top').click(function() {
		my_pane.animate({
			scrollTop: 0
		}, 2500, 'easeInOutCirc');
	});*/
	
	
	
	
	
	
	$('a.btn_1').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: 2208
		}, 4000, 'easeInOutCubic');
	});
	$('a.btn_2').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: 3581
		}, 4000, 'easeInOutCubic');
	});
	$('a.btn_3').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: 5180
		}, 4000, 'easeInOutCubic');
	});
	$('a.btn_4').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: 7035
		}, 4000, 'easeInOutCubic');
	});
	$('a.btn_team').click(function() {
		my_pane.filter(":not(:animated)").animate({
			scrollTop: 750
		}, 4000, 'easeInOutCubic');
	});

	/*$("#nav a").hover(function() {
		$(this).stop().animate({
			color: "#ED1F24"
		}, 400, 'easeInOutCirc');
	}, function() {
		$(this).stop().animate({
			color: "#000000"
		}, 400, 'easeInOutCirc');
	});*/


	
	$('#slider_services').anythingSlider({
		delay: 20000,
		resizeContents: false,
		startStopped: false,
		infiniteSlides: false,
	});
	$("#goto_web").click(function() {	
		$('#slider_services').anythingSlider(1, function(slider) {});
		return false;
	});
	$("#goto_sistemas").click(function() {
		$('#slider_services').anythingSlider(2, function(slider) {});
		return false;
	});
	$("#goto_app").click(function() {
		$('#slider_services').anythingSlider(3, function(slider) {});
		return false;
	});
	/*$(".services_cat a").hover(function(){
				$(this).stop().filter(":not(:animated)").animate({color: "#ED1C24"}, 300, 'easeInOutSine');
				}, function() {
					$(this).stop().filter(":not(:animated)").animate({color: "#ffffff"}, 300, 'easeInOutSine');
	});*/

	$('#slider_portfolio_web').anythingSlider({
		delay: 10000,
		resizeContents: false,
		startStopped: false,
		infiniteSlides: false,
	});
	$('#slider_portfolio_sistemas').anythingSlider({
		delay: 10000,
		resizeContents: false,
		startStopped: false,
		infiniteSlides: false,
	});
	$('#slider_portfolio_app').anythingSlider({
		delay: 10000,
		resizeContents: false,
		startStopped: false,
		infiniteSlides: false,
	});




/*$(".slider_2").hide();
	$("nav.portfolio_cat a:first").addClass("cur").show(); //Activate first tab
	$("#tab1").show();
	//On Click Event
	$("nav.portfolio_cat a").click(function() {
		$("nav.portfolio_cat a").removeClass("cur"); //Remove any "active" class
		$(this).addClass("cur"); //Add "active" class to selected tab
		$(".slider_2").hide(1000, 'easeInOutCirc'); //Hide all tab content
		
		var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show();
		return false;
	});
		
	$("#tab2").fadeOut(7000);
	$("#tab3").fadeOut(7000);
	$("nav.portfolio_cat a:first").addClass("cur");
	$("nav.portfolio_cat a").click(function() {
		$("nav.portfolio_cat a").removeClass("cur");
		$(this).addClass("cur");
		var activeTab = $(this).attr("href");
		$("#tab1").fadeOut(0);
		$("#tab2").fadeOut(0);
		$("#tab3").fadeOut(0);
		$(activeTab).delay(1000).fadeIn();
		return false;	
	});
	*/
	
	
	$(".slider_2").css({opacity: 0, visibility: 'hidden'});
	$("#tab1").css({opacity: 1, visibility: 'visible'});
	$("nav.portfolio_cat a:first").addClass("cur");
	$("nav.portfolio_cat a").click(function() {
		var activeTab = $(this).attr("href");
		$("nav.portfolio_cat a").removeClass("cur");
		$(this).addClass("cur");
		$(".slider_2").animate({opacity:0}, 1000, 'easeInOutSine').css({visibility: 'hidden'});
		$(activeTab).css({visibility: 'visible'}).animate({opacity:1}, 1000, 'easeInOutSine');
		return false;	
	});
	
	
	$(".back").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			left: 0
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			left: 10
		}, 150, 'easeInOutCirc');

	});
	
	$(".forward").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: 0
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: 10
		}, 150, 'easeInOutCirc');

	});
	
	$(".btn_enviar").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: -90
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: -80
		}, 150, 'easeInOutCirc');

	});
	
	$(".arrow_top").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			top: -10
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			top: 0
		}, 150, 'easeInOutCirc');

	});
	
	$(".arrow_bottom").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			bottom: -10
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			bottom: 0
		}, 150, 'easeInOutCirc');

	});

	$("#lbPrevLink").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			left: -100
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			left: -90
		}, 150, 'easeInOutCirc');

	});
	
	$("#lbNextLink").hover(function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: -100
		}, 150, 'easeInOutCirc');
	}, function() {
		$(this).stop().filter(":not(:animated)").animate({
			right: -90
		}, 150, 'easeInOutCirc');

	});



	$('.boxgrid').hover(function() {
		$(".cover", this).stop().animate({
			top: '0px'
		}, {
			queue: false,
			duration: 400
		}, 'easeInOutCirc');

	}, function() {
		$(".cover", this).stop().animate({
			top: '-400px'
		}, {
			queue: false,
			duration: 400
		}, 'easeInOutCirc');
	});

		
		

});


//$(".boxgrid img").desaturate();




