$(document).ready(function() {

var i=0;
var window_height = $(window).height();

/*



			 __    __     __     __   __     __     __    __     ______     __        
			/\ "-./  \   /\ \   /\ "-.\ \   /\ \   /\ "-./  \   /\  __ \   /\ \       
			\ \ \-./\ \  \ \ \  \ \ \-.  \  \ \ \  \ \ \-./\ \  \ \  __ \  \ \ \____  
			 \ \_\ \ \_\  \ \_\  \ \_\\"\_\  \ \_\  \ \_\ \ \_\  \ \_\ \_\  \ \_____\ 
			  \/_/  \/_/   \/_/   \/_/ \/_/   \/_/   \/_/  \/_/   \/_/\/_/   \/_____/ 
                                                                          

                                         &                                                                          

 ______     ______     ______     __  __     __   __     ______     ______     __         __        
/\  == \   /\  __ \   /\  ___\   /\ \/ /    /\ "-.\ \   /\  == \   /\  __ \   /\ \       /\ \       
\ \  __<   \ \ \/\ \  \ \ \____  \ \  _"-.  \ \ \-.  \  \ \  __<   \ \ \/\ \  \ \ \____  \ \ \____  
 \ \_\ \_\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\\"\_\  \ \_\ \_\  \ \_____\  \ \_____\  \ \_____\ 
  \/_/ /_/   \/_____/   \/_____/   \/_/\/_/   \/_/ \/_/   \/_/ /_/   \/_____/   \/_____/   \/_____/ 
                                                                                                                                                                                                                                       




*/



 




//////////////////////////////////////////////////////////////////////////////////////
//
// THE SIDEBAR IS GOING TO BE NICE
//

hidden_position = ($('#secondaryContent').width() + 20 - 30)*-1;
$('#secondaryContent').height(window_height-40-90);
$('#secondaryContent').css({'top':'76px'}); 

if ($('#homepage').length > 0) {} else {
$('#secondaryContent').css({'left':hidden_position}); // to start with
}
$('#secondaryContent').hover(
	function(){
		$(this).stop().animate({ 
        left: "0"
        }, 500);
	},
 	function(){
		$(this).stop().animate({ 
        left: hidden_position
        }, 500);
 	}
);


//////////////////////////////////////////////////////////////////////////////////////
//
// IMAGE GALLERY: browse by clicking on buttons
// TAKEN FROM CF
//
// will need to adapt the DOM and do some tests
// 	(!) we are using images only in the first paragraph to setup a gallery of pictures:		 < prev. next. >

$('div.postWrapper div.post div.ids_container p:first').children('.ids_wrap1').each(function() {

			//	$(this).show();
			
				this_imgs = $(this).children('.ids_wrap2').children('.ids_wrap3').children('img');
			
				original_height = $(this_imgs).attr('height'); //();
				original_width = $(this_imgs).attr('width'); //();
							
				var new_width = 300;
				var new_height= new_width / original_width * original_height;
			
				$(this_imgs).attr("width", new_width);
				$(this_imgs).attr("height", new_height);	
				
			//PREP BIG IMGS FOR SLIDESHOW
				if (i == 0) {
				} else if (i == 1) {
					$(this).css({"display": "none"});
					$(this).siblings('div#buttons').css({"display": "block"});
				} else {
					$(this).css({"display": "none"});
				}
				i = (i+1);
			});


$('div.postWrapper div.post p:first').children('img').each(function() {

			//	$(this).show();
			
				this_imgs = $(this);
			
				original_height = $(this_imgs).attr('height'); //();
				original_width = $(this_imgs).attr('width'); //();
							
				var new_width = 300;
				var new_height= new_width / original_width * original_height;
			
				$(this_imgs).attr("width", new_width);
				$(this_imgs).attr("height", new_height);	
				
			//PREP BIG IMGS FOR SLIDESHOW
				if (i == 0) {
				} else if (i == 1) {
					$(this).css({"display": "none"});
					$(this).siblings('div#buttons').css({"display": "block"});
				} else {
					$(this).css({"display": "none"});
				}
				i = (i+1);
			});


// 
// IMAGE GALLERY
// handling the interactivity: previous/next images
//
var slide_id;

if ($('.post p:first img').length > 1) {
		$('#buttons').show();

} else {
	$('#buttons').hide();
}


$('a#next').click( function() {

	slide_id = parseInt($(this).parent().attr("title"));
	

	
	if ($(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id+1).length > 0) {
		$(this).siblings('a#previous').css({'opacity':'1'});
		$(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id).hide();
		slide_id = (slide_id+1);
		$(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id).show();
		$(this).parent().attr({"title":slide_id});		
			if ($(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id+1).length > 0) {
			} else {
				$(this).css({'opacity':'0.25'})
			}	
	} else {}
	
	return false;
});

$('a#previous').click( function() {
	slide_id = parseInt($(this).parent().attr("title"));
	if ($(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id-1).length > 0) {
		$(this).siblings('a#next').css({'opacity':'1'});
		$(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id).hide();
		slide_id = (slide_id-1);
		$(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id).show();
		$(this).parent().attr({"title":slide_id});		
			if ($(this).parent().siblings('.post').children('p:first').children('img').eq(slide_id-1).length > 0) {
			} else {
				$(this).css({'opacity':'0.25'})
			}
	} else {}
	
	return false;
	
});
			
			
//////////////////////////////////////////////////////////////////////////////////////
//
// AUTOMATING THE DOUBLE COLUMNS
//
// double columns are acting on top of all th rest



// $(".postWrapper .post").columnize({ columns: 2 });


//////////////////////////////////////////////////////////////////////////////////////
//
// Title to go on the LEFT column
//
// gallery-row

// page which have gallery of images inserted: title goes to the left automatically
if ($('.gallery-row').length > 0 ) {

	
	
	$('h1.postTitle').css({
		'position':'absolute',
		'top':'0',
		'left':'30px'
	});

	$('.gallery').clone(true).insertBefore('.postWrapper');
	$('div.postWrapper div.post div.gallery').remove();

	$(".postWrapper .post").columnize({ columns: 2 });
} else {
//	$(".postWrapper .post").columnize({ columns: 2 });

}

// page with heavy text content			
if ($('.textual').length > 0) {
	$(".postWrapper .post").columnize({ columns: 2 });
} else {}

//
// Moving some pieces around: Accompanying projects
//

$('#accomp_projects').css({
	'position':'absolute',
	'left':'40px',
	'bottom':'10px'
});

$('h1.postTitle').css({
	'position':'absolute',
	'top':'0px',
	'left':'30px'
});


$('#postit').css({
	'position':'absolute',
	'left':'45px',
	'top': parseInt($('h1.postTitle').css('top'))+$('.postWrapper h1.postTitle').height()+10+'px'
});









}); // END OF MAIN.JS
