function newShareMargin(obj){
			
		var entryH = ( obj.parent('.commentSection').parent('.entryExtras').siblings('.entry').outerHeight(true) );
				
		var entryExtrasH = ( obj.parent('.commentSection').parent('.entryExtras').outerHeight(true) );
				
		if ( ( entryExtrasH + 46 ) < entryH ) {
				
			var shareMargin = ( ( ( entryH - entryExtrasH ) - 46 ) );
			
			obj.parent('.commentSection').siblings('.share').css({marginTop:shareMargin});
				
		} else {
			
			obj.parent('.commentSection').siblings('.share').css({marginTop:0});
				
		}
		
		$('.share.hidden').css({'display':'block','opacity':0}).animate({opacity:1}).removeClass('hidden');
}

function arrowClick(){
	$('.post.blogText p .arrow').click(function() {
		var obj = $('.post.blogText');
		if (!obj.hasClass('closed')){
		obj.addClass('closed');
		$('.post.blogText p').html('Ingrid is a <span style="color: rgb(87, 179, 228);">social scientist, international research consultant</span> and  <span style="color: rgb(87, 179, 228);">social justice</span> and <span style="color: rgb(87, 179, 228);">gender equality specialist...</span><div class="arrow"></div>');
		$.cookie('blogText', 'closed');
		} else {
			$('.post.blogText p').html('Ingrid is a <span style="color: rgb(87, 179, 228);">social scientist, international research consultant</span> and  <span style="color: rgb(87, 179, 228);">social justice</span> and <span style="color: rgb(87, 179, 228);">gender equality specialist.</span> She worked in <span style="color: rgb(87, 179, 228);">corporate</span> and <span style="color: rgb(87, 179, 228);">education sectors</span> for 10 years (including her stint as a Tokyo based  casino hostess and professional mandarin peeler before arriving in  international sector via MSF in 2001. <span style="color: rgb(87, 179, 228);">She instantly felt like she&rsquo;d come  home.</span><div class="arrow"></div>');
			obj.removeClass('closed');
			$.cookie('blogText', null);
		}
		arrowClick();
	});
}

$(document).ready(function() {
	
	$('.share').css({opacity:0}).addClass('hidden');
			
	$('.information').hide();
	
	$('.respond').hide();
	
	$('ol.commentlist').hide();
	
	var shareLinksH = $('.share ul.socialNetworks').height();
	
	$('.share ul.socialNetworks li:last-child').addClass('last');
	
	$('.share ul.socialNetworks').hide();
	
	$('.post p:last-child').addClass('last');
	
	$('ol.commentlist li:last-child').addClass('last');

	$('.content h1').css({'display':'inline'});
	
	$('.heading').slice(5).addClass('closed');
	
	$('.heading').slice(5).next('.entryWrapper').hide();
	
	$('.box').each(function(index) {
		
		var boxHeight = $(this).children('.content').height();
		
		var coverHeight = $(this).children('.content').height();
		
		var coverWidth = $(this).children('.content').width();
	
		$(this).css({height:boxHeight});	
	
		$(this).children('.content').prepend('<div class="cover"></div>');
	
		$(this).children('.content').children('.cover').css({'height':coverHeight,'width':coverWidth});
  	
	});
	
	$('.content').css({'position':'absolute','float':'none'});
	
	$('.pictogram').css({'position':'absolute','float':'none'});

	$('.startHeading').css({'position':'absolute','margin':'0 0 0 200px','float':'none'});
	
	$('#container.wrap').masonry({
		columnWidth: 480, 
		itemSelector: '.box' 
	});
	
	$(".box").bind("mouseenter",function(){
		var obj = $(this);
		if(!obj.hasClass('hover')){
			obj.addClass('hover');	
		}
	}).bind("mouseleave",function(){
		var obj = $(this);
		if(obj.hasClass('hover')){
			obj.removeClass('hover');
		}
	});
	
	$('.box:not(.heading)').click(function() {
		var obj = $(this);
		if(!obj.hasClass('active')){
			obj.animate({
				opacity: 1
			  }, {
				duration: 200
			});
			
			jQuery.each(jQuery.browser, function(i) {
				if(!$.browser.msie){
					$('.box').removeClass('active');
					obj.addClass('active');	
					$('.box:not(.active,.heading)').animate({
						opacity: 0.4
					  }, {
						duration: 200
					});
				}
			});

		} else {
			$('.box').removeClass('active');
			$('.box').animate({
				opacity: 1
			  }, {
				duration: 200
			});
		}
	});
	
	$('.box.heading.blue').click(function() {
		var myFile = document.location.toString();
		if (myFile.match('#')) { // the URL contains an anchor
  			var myAnchor = myFile.split('#')[0];
			window.location = myAnchor + '#projects';
		} else {
			window.location = myFile + '#projects';
		}
		$('.box').css({opacity: 1});
		$('.box').removeClass('active');
	});
	
	//cookies need to be debugged 
	
	if ($.cookie('blogText') == 'closed'){
		var obj = $('.post.blogText');
		obj.addClass('closed');
		$('.post.blogText p').html('Ingrid is a <span style="color: rgb(87, 179, 228);">social scientist, international research consultant</span> and  <span style="color: rgb(87, 179, 228);">social justice</span> and <span style="color: rgb(87, 179, 228);">gender equality specialist...</span><div class="arrow"></div>');
		arrowClick();
	} else {
		$('.post.blogText p').append('<div class="arrow"></div>');
	}
	
	$('.post .heading').append('<div class="arrow"></div>');
	
	$('.post.blogText p .arrow').click(function() {
		var obj = $('.post.blogText');
		if (!obj.hasClass('closed')){
		obj.addClass('closed');
		$('.post.blogText p').html('Ingrid is a <span style="color: rgb(87, 179, 228);">social scientist, international research consultant</span> and  <span style="color: rgb(87, 179, 228);">social justice</span> and <span style="color: rgb(87, 179, 228);">gender equality specialist...</span><div class="arrow"></div>');
		$.cookie('blogText', 'closed');
		} else {
			$('.post.blogText p').html('Ingrid is a <span style="color: rgb(87, 179, 228);">social scientist, international research consultant</span> and  <span style="color: rgb(87, 179, 228);">social justice</span> and <span style="color: rgb(87, 179, 228);">gender equality specialist.</span> She worked in <span style="color: rgb(87, 179, 228);">corporate</span> and <span style="color: rgb(87, 179, 228);">education sectors</span> for 10 years (including her stint as a Tokyo based  casino hostess and professional mandarin peeler before arriving in  international sector via MSF in 2001. <span style="color: rgb(87, 179, 228);">She instantly felt like she&rsquo;d come  home.</span><div class="arrow"></div>');
			obj.removeClass('closed');
			$.cookie('blogText', null);
		}
		arrowClick();
	});
			
	$('.country').click(function() {
		var obj = $(this);
		if(!obj.hasClass('active')){
			obj.children('.information').slideToggle();
			obj.addClass('active');	
		} else {
			obj.children('.information').slideToggle();
			obj.removeClass('active');
		}
	});	
	
	$('.share').each(function(index) {
			
		var entryH = ( $(this).parent('.entryExtras').siblings('.entry').height() );
			
		var entryExtrasH = ( $(this).parent('.entryExtras').height() );
			
		if ( entryExtrasH < entryH ) {
			
			var shareMargin = ( ( ( entryH - entryExtrasH ) - 16 ) );
		
			$(this).css({marginTop:shareMargin});
			
		}
		
		$('.share.hidden').animate({opacity:1}).removeClass('hidden');
		
	});
	
	$('h2.leaveComment').click(function() {
		if ( ( $(this).siblings('h2.readComments').is(':visible') ) && ($(this).parent('.commentSection').siblings('.share').outerHeight(true) < 31) ) {
			$(this).next('.respond').slideToggle('slow', function() {
				//
			});	
		} else if ( ( $(this).parent('.commentSection').siblings('.share').outerHeight(true) > 29 ) ) {
			$(this).parent('.commentSection').siblings('.share').hide().addClass('hidden');
			$(this).next('.respond').slideToggle('slow', function() {
				newShareMargin($(this))
			});
		} else {
			$(this).next('.respond').slideToggle('slow', function() {
				//
			});	
		}
	});
	
	$('h2.readComments').click(function() {
		if ( $(this).parent('.commentSection').siblings('.share').outerHeight(true) > 58 ) {
			$(this).parent('.commentSection').siblings('.share').hide().addClass('hidden');
			$(this).next('ol.commentlist').slideToggle('slow', function() {
				newShareMargin($(this))
			});
		} else {
			$(this).next('ol.commentlist').slideToggle('slow', function() {
				//
			});	
		}
	});
	
	$('.post .heading').click(function() {
		var obj = $(this);
		if(!obj.hasClass('closed')){
			obj.addClass('closed');	
		} else {
			obj.removeClass('closed');	
		}
		obj.next('.entryWrapper').slideToggle();
	});
		
	$('.share h2').click(function() {
		var obj = $(this);
		if(!obj.hasClass('open')){
			obj.addClass('open');
			var slidingMarginTop = ( ( ( ($(this).parent('.share').outerHeight( true )) - ($(this).height()) ) - shareLinksH ) + 10 );
			if ( slidingMarginTop < 0 ) { slidingMarginTop = 0 };
			$(this).parent('.share').animate({marginTop: slidingMarginTop});
		} else {
			var entryH = ( $(this).parent('.share').parent('.entryExtras').siblings('.entry').height() );
			var commentSectionH = ( $(this).parent('.share').siblings('.commentSection').height() );			
			var shareMargin = ( ( ( entryH - commentSectionH ) - ( ($(this).height()) + 15) ) );
			
			if ( shareMargin < 0 ) { shareMargin = 0 };			
			$(this).parent('.share').animate({marginTop:shareMargin});			
			obj.removeClass('open');			
		}
		obj.prev('ul').slideToggle();
	});
		
	$('a.about').click(function() {$('.box.about').click();});
	$('a.expertise').click(function() {$('.box.expertise').click();});
	$('a.services-solutions').click(function() {$('.box.services-solutions').click();});
	$('a.process').click(function() {$('.box.process').click();});
	$('a.clients').click(function() {$('.box.clients').click();});
	$('a.collaborators').click(function() {$('.box.collaborators').click();});
	$('a.projects').click(function() {$('.box.heading.blue').click();});
	
	$('li.blog a').click(function() {
		$.prompt("Working on something great! Please pop back soon.");				  
	});
	
});

