(function($) {
    
    jQuery.fn.getExperienceCount = function() {
        var startingDate = new Date(2011, 8, 1);
        var now = new Date();
        var incrementValue = 0.00595;
        var startYears = 150;   

        dateDiff = now - startingDate;
        hoursSinceStartingDate = dateDiff / (1000 * 60 * 60);
        additionalYears = incrementValue * hoursSinceStartingDate;

        return startYears + additionalYears;
    
    }
    
    jQuery.fn.setExperienceCounter = function() {        
        
        var experienceCounter;
        experienceCounter = $.fn.getExperienceCount().toFixed(6);
        $('#experienceCounter').html( experienceCounter );        
        
    }

})(jQuery);

$(document).ready( function() {
    
    $.fn.setExperienceCounter();
    $('<br>').insertAfter('#experienceCounter');
    
    $('#experienceCounter').everyTime( '50ms', function() {
        $.fn.setExperienceCounter();
    });
    
});



$.fn.extend({
    'softScroll': (function(){
		
        var $root = $('html, body');
		
        return function(){
            if(this.length < 1){
                return this;
            }
            var pos = this.offset(),
            $body = $root.map(function(i, el){
                if(el.scrollTop > 0){
                    return el;
                }
            });

            $body.animate({
                'scrollTop': (pos.top-100)
            }, 500);
			
            return this;
        };
    })()
});

$(function(){
    var global_active = false;
    $('.who-we-are').each(function(){
        $body = $('body')
        $(this).find('.wrapper').each(function(){
            var $section = $(this).parent(), active = false, $this = $(this);

            $this.css('cursor', 'pointer').append('<p class="more"><span class="button" role="button">View more info</span></p>').click(function(){
                if(!active && global_active){
                    return;
                }
                $('section.active').not($section).trigger('click');			
                active = !active;
				
                if(active){
                    $this.css({
                        position:'absolute', 
                        top: $this.position().top, 
                        left:$this.position().left
                    }).
                    animate({
                        left:143, 
                        width:668, 
                        height:400
                    }, 500);
                    $section.softScroll();
                }else{
                    $this.css({
                        position:'relative', 
                        top:0, 
                        left:0, 
                        width:217, 
                        height:299
                    });
                }
                $section.toggleClass('active', active);
                $(this).find('span').text(active ? 'Close' : 'View more info');
                $body.toggleClass('blackout', active);
                global_active = active;
            });
        });
    });
	
    $('input[placeholder], textarea[placeholder]').each(function(){
        var $this = $(this), placeholder = $this.attr('placeholder');
		
        if($this.val() == placeholder){
            $this.val('');
        }
		
        $this
        .blur(function(){
            if($this.val() == ''){
                $this.val(placeholder).addClass('placeholder');
            }
        })
        .focus(function(){
            if($this.val() == placeholder){
                $this.val('').removeClass('placeholder');
            }
        })
        .trigger('blur');

        /*$('#main-navigation li').hover(function(){	
            $(this).toggleClass('hover');
        });*/
    });
});

