
		var active = null;
		var nav;
		var post;
		var cont;
		var loader;
		var id;
		var imagesDiv;
		var defHeadWidth = 480;
		var ie; 
		var timer;
		var image1;
		var nLen;
		var saveHeight = 0;
		var saveWidth = 0;
		var tempH = 0;
		var aPostImages = new Array();
		
		$(document).ready(function() {
		
			ie = $.browser.msie; 
			pLen = $('.post').length;
			for(var i=0; i<pLen; i++){
				$('.post:eq('+i+')').delay(i * 40).fadeIn();
			}
			/*$('.navheader').mouseover(function() {
				$(this).parent().find('.navcol').animate({height: '35px'},100, function() {
						$(this).animate({height: '0px'},100);
					});
			});*/
			$('.navheader').click(function() {
				if(active != $(this).parent() && active != null){
					active.find('.postcontent').slideUp('fast', function() {
						$(this).addClass('hidden');
					});
					var w = randomWidth();
					active.find('.navheader').animate({width: w});
					active.find('.navheader').removeClass('active');
				}
				
				nav = $(this);
				post = $(this).closest('.post');
				cont = post.find('.postcontent');
				id = post.attr('id');
				imagesDiv = post.find('.postcontent .images');
				aPostImages = new Array();
				loader = $(this).find('.loader');

				if(cont.hasClass('hidden')){
					if( post.find('.postcontent .images img:eq(0)').attr('src') == undefined ){
						loader.removeClass('hidden');			
						nLen = allPics[id].length;
						saveHeight = 0;
						saveWidth = 0;
						tempH = 0;
						for(i=0;i<nLen;i++){
							image1 = $('<img />').attr('src',  'http://www.mackieworld.com/'+allPics[id][i]);
							aPostImages.push(image1);
							if(i==nLen-1){
								image1.load(function(){
												imagesDiv.append( $(this) );
												if(ie==true){
													tempH = image1.height(); 
													saveWidth = image1.width();
												}else{
													tempH = this.height; 
													saveWidth = this.width;
												}
												if(tempH>saveHeight){
													saveHeight = tempH;
												}
												contentReady(saveWidth, saveHeight, nLen )
											});
							}else{
								image1.load(function(){
												imagesDiv.append( $(this) );
												if(ie==true){
													tempH = image1.height(); 
												}else{
													tempH = this.height; 
												}
												if(tempH>saveHeight){
													saveHeight = tempH;
												}
											});
							}
						}
					}else{
						openPost();
					}
					active = $(this).parent();
					$(this).addClass('active');

				}else{
					cont.slideUp('fast', function() {
						$(this).addClass('hidden');
					});
					active = null;
					var w = randomWidth();
					$(this).animate({width: w});
					$(this).removeClass('active');
				}
			});
			

			
			function contentReady(w, h, num)
			{
				if(w==0){w = 500;}
				var wi = (w+15)*num;
				if(phone()){
					wi = 480;
					h = h*num;
				}
				if(pad()){
					wi = 768;
					h = (h+5)*num;
				}
				var cssObj = {
					'width' : wi,
					'height' : '100%'
				}
				imagesDiv.css(cssObj);
				openPost();
			}
			
			function openPost()
			{
				nav.animate({
					width: imagesDiv.css("width")
				  }, 500, function() {
						cont.slideDown('fast');
						if(!isScrolledIntoView(nav)){
							$(window).scrollTop(nav.offset().top - 10);
						}
						cont.removeClass('hidden');
				});
				loader.addClass('hidden');
			}
			
			function randomWidth()
			{
				if(phone()){
					return defHeadWidth;/* + Math.round(Math.random()*140);*/
				}else if(pad()){
					return defHeadWidth + Math.round(Math.random()*165);
				}else{
					return defHeadWidth + Math.round(Math.random()*400);
				}
			}
			function phone()
			{
				if(
				 navigator.userAgent.match(/Android/i) ||
				 navigator.userAgent.match(/webOS/i) ||
				 navigator.userAgent.match(/iPhone/i) ||
				 navigator.userAgent.match(/iPod/i)
				){
					return true;
				}else{
					return false;
				}
			}
			function pad()
			{
				if(navigator.userAgent.match(/iPad/i)){
					return true;
				}else{
					return false;
				}
			}
			function isScrolledIntoView(elem)
			{
				var docViewTop = $(window).scrollTop();
				var docViewBottom = docViewTop + $(window).height();

				var elemTop = $(elem).offset().top;
				var elemBottom = elemTop + $(elem).height();
				
				
				return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
			}


			if(phone()){
				$('.navheader').css({'width' : defHeadWidth});
				setTimeout(function() { window.scrollTo(0, 1) }, 100);
			}
			
			
		});

