$('.content .middle').ready(function(){

///////////////////
//  Cufon Font   //
//////////////////

Cufon.replace('.leftPanel,h1,h2,.heading,.heading-white,.footer,.subheading,.menu li a,.subtitle,.white,.content .pageHeader,.priceTitle,#planDesc,.price,.saving', { fontFamily: 'Helvetica Neue'});
Cufon.replace('#proj1 .subheading,.greytext,.rightPanel,.row span,.nextDescRow', { fontFamily: 'Proxima Nova Lt'});


///////////////////
//  Navigation   //
//////////////////
$('ul.menu li,#tryitfree,ul.member li img,.getStarted img').animate({opacity: '.7'}, 'fast');
$("ul.menu li,#tryitfree,ul.member li img,.getStarted img").hover(
   function () {
        $(this).animate({opacity: '1'}, 'fast');
   },
   function () {
        $(this).animate({opacity: '.7'}, 'fast');
   }
);


/////////////////////////////////////
//  Open after load all contents   //
////////////////////////////////////
$('.content').waitForImagesLoad(function() {
 //resizeNextSlide();
 resizeContents();
 $(".content #proj1").fadeTo(1000,1);
 $(".share").show();
});

///////////////////////
//  Window resize   //
/////////////////////
$(window).resize(function () {
    resizeContents();
});


///////////////////////
//  Window scroll   //
/////////////////////
tiles = $(".content .middle")
$(window).scroll(function(d,h) {
    addscrollamount=350

    tiles.each(function(i) {
        a = $(this).offset().top + $(this).height();
        b = $(window).scrollTop() + ($(window).height()+addscrollamount);
        if (a < b) $(this).fadeTo(400,1);
    });
});

//////////////////////////////
//    Click picaholic is   //
////////////////////////////
$('.pic').click(function(){
    scrollPos=$(window).scrollTop();
     animateMe('down',scrollPos);
});




////////////////////////////////////////////////////
//  Resize contents according to window height   //
//////////////////////////////////////////////////
function resizeContents(){
    var winH = $(window).height();
    var winW = $(window).width();
    
 
    $('#proj2 .middle-contents').css('left', (winW-$('#proj2 .middle-contents').width())/2);

    var headerH=$('.header .nav').height()+55;

    $('.share').css('top', (((winH-headerH)-$('.share').height())/2)+headerH);
    $('.content .middle').height(winH);
        
        var centerDiv = $('.content .middle .middle-contents');
        if(winH>centerDiv.height()+135){
        centerDiv.css('marginTop', ((winH-centerDiv.height())/2)-80);
        }else{
            centerDiv.css('marginTop', 10);
            $('.content .middle').height(centerDiv.height()+120);
        }
}

/////////////////////////////
//  Picaholic services    //
///////////////////////////
$('.servicebox-hover').css({ opacity: 0 });

	$('.servicebox-hover').mouseenter(function() {
             $('.heading',$(this).parent()).hide();

		$(this).css({ opacity: 1 });
		 $('.white',this).animate({ lineHeight: '20px' }, 100);
	});

	$('.servicebox-hover').mouseleave(function() {
            $('.heading',$(this).parent()).show();
            $('.white',this).animate({ lineHeight: '23px' }, 0);
		$(this).animate({ opacity: 0 }, 300);

	});

////////////////////////////
//  Picaholic features   //
//////////////////////////

$(".features-list li img").hover(function(){
$(this).animate({opacity:1},200);
},function(){
    $(this).animate({opacity:0.2},300);
});


$("#features-list li img").hover(function(){
slideNo=parseInt($(this).parent().attr('id').replace(/slide/i,''))+3;
$('#slide'+slideNo).animate({marginTop:240},200);
$('.reveal',$(this).parent()).animate({marginTop:0},200);
},function(){
    slideNo=parseInt($(this).parent().attr('id').replace(/slide/i,''))+3;
    $('#slide'+slideNo).animate({marginTop:0},200);
$('.reveal',$(this).parent()).animate({marginTop:-228},200);
});


////////////////////////////////////
//  animation on click   //
//////////////////////////////////
function animateMe(position,scrollPos){
        nextSlide=$("#proj2");
        $('html, body').animate({scrollTop:nextSlide.position().top-90}, 'slow');

}


});





	 
	


$(document).ready(function() {

	$('.tryitfree').click(function() {
			$('#beta-overlay').show();
	});
	
	$('#close-beta-overlay').click(function() {
	
		$('#beta-overlay').hide();
	
		return false;
	});
	
	$('#btn-beta-signup').click(function() {
	
		if ($('#beta-email').val() == '')
		{
			alert('Please enter an email address');
			return false;
		}
		
		if ($('#beta-first-name').val() == '')
		{
			alert('Please enter your first name');
			return false;
		}			
	
		if ($('#beta-last-name').val() == '')
		{
			alert('Please enter your last name');
			return false;
		}			
		
		// Call the form, 
		$.ajax({
			url: 'http://admin.picaholic.com/api/form/beta-invite',
			data: { 
				email: $('#beta-email').val(),
				first_name: $('#beta-first-name').val(),
				last_name: $('#beta-last-name').val()
			},
			dataType: 'json',
			type: 'post',
			success: function (data) {
				// hide the form, show a thankyou message    
				$('#beta-form').empty()
								      .append('<p>Thankyou for submitting your details to the Picaholic Beta.</p>');
				
				$('#btn-beta-signup').hide();
			},
			error: function (err) {
				// $('#subscribe-email').addClass('error');
				$('#beta-form').empty()
								      .append('<p>There was an error sending your details to our server, please send an email to <a href="mailto:support@picaholic.com">support@picaholic.com</a> with your details.</p>');
				
				$('#btn-beta-signup').hide();
			}
		});
	
	});
	

});
