function loadThumbPost(divPost) {
	var imgPreloader = new Image();

	imgPreloader.onload=function(){
		var objLoading = divPost.getElement('div.postThumb').getElement('div,imgLoading');
		
		var objPostImage = document.createElement("img");
		objPostImage.setAttribute('class','postThumbImage');
		divPost.getElement('div.postThumb').replaceChild(objPostImage, objLoading);
		objPostImage.set('src',imgPreloader.src);
		objPostImage.setStyle('height',150);
		
		divPost.setStyle('width',imgPreloader.width*(150/imgPreloader.height)-1);
	}
	anchors = divPost.getElements('div.postGallery a');
	if (anchors.length > 0) imgPreloader.src = anchors[0].getAttribute('href');
}

window.addEvent('domready', function(){
	var contents = $$('div.divContentOuter');
	var _item;
	
	for (var i = 0; i < contents.length; i++) {	
		_item = contents[i];
		_item.addEvent('click', function() {
			var morph = new Fx.Morph(this.get('id'));
			var scroll = new Fx.Scroll($(document.body), {
				  wait: false,
				  duration: 500,
				  offset: {'x': -200, 'y': -50},
				  transition: Fx.Transitions.Quad.easeInOut
			});
			var h = this.getStyle('height').toInt();
			if (h == 150) {
				var innerWidth = 0;
				if (window.innerWidth) {
					innerWidth=window.innerWidth
				} else {
					innerWidth=document.body.clientWidth
				}
				this.getElement('div.postThumb').setStyle('display','none');
				var maxWidth = (innerWidth * 0.8) - 160 - 180 - 35;
				morph.start({width: maxWidth+'px', height: '400px'});
				scroll.toElement(this);
			} else {
				_this = this;
				
				morph.start({width: 150, height: 150}).chain(function() { 
											_this.getElement('div.postThumb').setStyle('display','block');
											var origWidth = _this.getElement('div.postThumb').getElement('img.postThumbImage').getWidth() - 1;
											_this.setStyle('width', origWidth);
										});
			}
		});
		
		_item.addEvents({
			mouseenter: function() {
				this.getElement('div.postThumb').getElement('div.postTitle').tween('opacity', 0, 0.5);				  
			},
			mouseleave: function() {
				this.getElement('div.postThumb').getElement('div.postTitle').tween('opacity', 0.5, 0);				  
			}
		});

		loadThumbPost(_item);
	};
});
