$(document).ready(function() {
	
	$("#js-error").remove();
	
	/*
	$('#topheadline .animate').delay(1200).animate( {marginLeft: '60px'}, 400);
	$('#topheadline .fadein').delay((1500)).fadeIn(400);
	*/
	
	
	$('.image').delay(900).animate({opacity: '1'}, 'slow');
	
	$('.logo-1').delay(200).animate({opacity: '0.3'}, 'normal');
	$('.logo-6').delay(400).animate({opacity: '0.3'}, 'normal');
	$('.logo-2').delay(600).animate({opacity: '0.3'}, 'normal');
	$('.logo-7').delay(800).animate({opacity: '0.3'}, 'normal');
	$('.logo-3').delay(1000).animate({opacity: '0.3'}, 'normal');
	$('.logo-8').delay(1200).animate({opacity: '0.3'}, 'normal');
	$('.logo-4').delay(1400).animate({opacity: '0.3'}, 'normal');
	$('.logo-9').delay(1600).animate({opacity: '0.3'}, 'normal');
	$('.logo-5').delay(1800).animate({opacity: '0.3'}, 'normal');
	$('.logo-10').delay(2000).animate({opacity: '0.3'}, 'normal');
	
	
	$('.logos img').hover(function() {
		$(this).stop().animate({opacity: '1'}, 'fast');
	}, function() {
 		$(this).stop().animate({opacity: '0.3'}, 'normal');
	});
	
	/*
	$('.service').hover(function() {
		$(this).children("img.hover").stop().fadeIn(100);
	}, function() {
		$(this).children("img.hover").stop().fadeOut(1000);
	});	
	*/
	
	
	$('.service').hover(function() {
		$(this).children("img.hover").stop().animate({opacity: '1'}, 'fast');
	}, function() {
 		$(this).children("img.hover").stop().animate({opacity: '0'}, 'normal');
	});
	
	
	
	
	$('#teaser #slider').fadeIn(1200);		
	
	$("body").removeClass("loading").addClass("loaded");
	
	$('a.bigbutton').click(function() {
		$(this).fadeOut();
		$('#afterload').fadeIn();
		$('#more').hide();
		$('#more').load("more-projects.html");
		$('#more').delay(300).fadeIn(800);

		setTimeout(function() {
			$("a.imagegroup").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'padding'		: 	0,
				'speedIn'		:	300, 
				'speedOut'		:	300, 
				'overlayShow'	:	true,
				'overlayColor'	:	'#000',
				'overlayOpacity':	0.5
			});				
		}, 500);
		
		setTimeout(function() {$("#work #more").preloader();}, 400);
		return false;
	});
	
	/* Get FB Likes 
	$.getJSON('http://graph.facebook.com/goshape?callback=?', function(json) {
		$('span#likebox').append(json.total);
	});*/
	
	/* Get FB Likes  */
    function GetSingleFaceBookCount(url) {
    	$.getJSON("ht" + "tps://api.facebook.com/method/fql.query?format=json&query=SELECT total_count FROM link_stat WHERE url='http://go-shape.com'&callback=?", function(data) {
   			$('span#likebox').append(data[0].total_count);
  	  });
    }
	$('span#likebox').append(GetSingleFaceBookCount);
	
	/* Get FB Likes  */
    function GetSingleFaceBookCountAdd(url) {
    	$.getJSON("ht" + "tps://api.facebook.com/method/fql.query?format=json&query=SELECT total_count FROM link_stat WHERE url='http://go-shape.com'&callback=?", function(data) {
   			$('span#likeboxadd').append(data[0].total_count + 1);
  	  });
    }
	$('span#likeboxadd').append(GetSingleFaceBookCountAdd);	

	/* Animation Social */
	FB.Event.subscribe('edge.create', function(response) {
  		$('.liker').fadeOut();
  		$('h3.default').fadeOut();
  		$('h3.thanks').delay(400).fadeIn();
	});

	// When JS is active
	$('a.open-contact').attr('href', '#');
	
	// Contact Opener
	$('a.open-contact').click(function() {
		$('#contact').slideDown();  // open contact
		$('a.close').delay(600).fadeIn('normal'); // fadeIn close btn
	});	

	// Contact Closer
	$('a.close').click(function() { 
		$(this).fadeOut('fast'); // fadeOut close btn
		$('#contact').delay(300).slideUp(); //close
		$('#progress').fadeOut('slow'); // fadeOut overlay
	});	
	
	// Form Validation
    var options = { 
    	target: '#progress', 
    	success:  showResponse
    }
    $("#contact_form").validate({
    	submitHandler: function(form) {
    		$(form).ajaxSubmit(options); 
    	}
    });		
});
function showResponse() {
    $('#progress').fadeIn();
}
$(function() {
    function scroll(direction) {
        var scroll, i,
                positions = [],
                here = $(window).scrollTop(),
                collection = $('.post');
        collection.each(function() {
            positions.push(parseInt($(this).offset()['top'],10));
        });
        for(i = 0; i < positions.length; i++) {
            if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
            if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i-1); break; }
        }
        if (scroll) {
            $.scrollTo(scroll, {
                duration: 750       
            });
        }
        return false;
    }
    $(".next,.prev").click(function() {        
        return scroll($(this).attr('class'));        
    });
    $(".scrolltoanchor").click(function() {
        $.scrollTo($($(this).attr("href")), {
            duration: 750
        });
        return false;
    });
});
