var winW;
var winH;
var navW;
var contentsH;
var tempX;
var endX;
var hType;
var logoW = 731;
var headerH = 240;
var home=true;
var direct=false;


// change styles for header if small monitor
function useSmallHeader(){
	hType = "small";
	headerH = 225;
	$('#mainHeader').css({'height':'157px'});
	$('#logo').css({'width':'600px'});
	$('#twitterBar').css('left',607);
	$('#logoimg').css({'margin-left': '7px','margin-top': '7px','width':'590px','height':'144px'});
	$('#logoimg').show();
	$('#vspacer').css('left','600px');
	$('#contents').css('top','170px');
	if(!ie){
		$('#container_nav').css({'left':'665px','margin-top': '-60px'});
	} else {
		$('#container_nav_IE').css({'left':'625px','bottom':'13px'});
	}
	
	if(home){
		//remove icons
		$('div[id^="icon"]').each(function(){
			$(this).css('right','-60px');
		});
	}
}
function useBigHeader(){
	hType = "big";
	headerH = 240;
	$('#mainHeader').css('height','170px');
	$('#logo').css('width','724px');
	$('#twitterBar').css('left',731);
	$('#logoimg').css({'margin-left': '20px','margin-top': '0px','width':'684px','height':'167px'});
	if(!ie){
		$('#container_nav').css({'left':'791px','margin-top': '-50px'});
	} else {
		$('#container_nav_IE').css({'left':'752px','bottom':'0px'});
	}
	$('#vspacer').css('left','724px');
	$('#contents').css('top','185px');
	
	//replace icons
	if(home){
		$('div[id^="icon"]').each(function(){
			$(this).css('right','12px');
		});
	}
}
if(screen.width<1050){
	useSmallHeader()
} else {
	if(ie){
		$('#container_nav').css({'left':'731px','margin-top': '-50px'});
	}
}

winW = $(window).width()-30;
winH = $(window).height()-30;
$('#frame').css({'width':winW,'height':winH});


$(window).resize(function(){
	// resize white border to fill screen
	winW = $(window).width()-30;
	winH = $(window).height()-30;
	$('#frame').css({'width':winW,'height':winH});
	
	// setup Twitter bar
	twH = winW - ($('#logo').width()+7);
	if(twH>300){
	$('#twitterBar').css('width',twH);
	$('#twitter_update_list').css('width',twH-165);
	
		if(twH<450){
			$('#twitter_update_list').css('width',twH-80);
			$('#fbook').css('visibility','hidden');
		} else {
			$('#fbook').css('visibility','visible');
		}
	
	}
	if($('#twitter_update_list').height() <18){
		$('#twitter_update_list').css('margin-top','9px');
	} else {
		$('#twitter_update_list').css('margin-top','3px');
	}
	
	// set height of contents area
	contentsH = $(window).height()-headerH;
	$('#contents').css('height',contentsH)
	
	// set width of filler block
	tempX = $('#module_connect').offset().left+$('#module_connect').width();
	endX = winW-tempX+15;
	$('#module_filler').css('width',endX);	
	
	if(home){
		// rearrange homepage based on window width
		setModules();
	} else {
		checkHeader();
	}
	
	// update scrollbar heights
	if(hasScroll){
		updateScrollBars();
	}
})






// position all modules and set initial widths

var i = 0;
var n;
var modX;

// space homepage according to window size
var modWidths = Array();
var modWidthsSm = Array(315,218,230,265,310);
var modWidthsXSm = Array(270,180,190,210,270);
var modWidthsLg = Array(340,253,262,280,310); 
var modWidthsXLg = Array(360,273,282,300,330);

//var modWidths = Array(130,153,82,170,457) // for testing
//alert($(window).width());

function setModules(){
	n = 0;
	modX = 15;
	modWidths = modWidthsLg;
	if($(window).width()<1280 && $(window).width()>1170){
		modWidths = modWidthsSm; 
	}
	if($(window).width()<=1170){
		modWidths = modWidthsXSm; 
		useSmallHeader()
	} 
	if($(window).width()>=1600){
		modWidths = modWidthsXLg; 
	} 
	if($(window).width()>1170 && hType == "small"){
		useBigHeader();
	}
	
	$('[id^="module"]').each(function(){
		modW = modWidths[n];
		if(n>0){
			modX += (modWidths[n-1])+7;
		}
		$(this).css({'left':modX,'width':modW});
		n++;
	});
	
	//for blog, resize viewport
	//$('#scrollbar_thoughts > [class="viewport"]').css('width',modWidths[0]);

}
setModules();

function checkHeader(){
	modWidths = modWidthsLg;
	if($(window).width()<1280 && $(window).width()>1170){
		modWidths = modWidthsSm; 
	}
	if($(window).width()<=1170){
		modWidths = modWidthsXSm; 
		useSmallHeader()
	} 
	if($(window).width()>=1600){
		modWidths = modWidthsXLg; 
	} 
	if($(window).width()>1170 && hType == "small"){
		useBigHeader();
	}
}





// set colors for call to action buttons
var modColors = Array('#00AEEF','#414042','#AE7AB5','#8DC63F','#FBB040');
i=0;

$('[class="modFooter"]').each(function(){
	$(this).css('background-color',modColors[i]);
	i++;
});












// ABOUT PAGE ****************************************************************************************************************

// setup skills
var skillsW = Array(100,90,100,70,80,50,60);
i=0;

$('[id^="skill"]').each(function(){
	$(this).css('width',skillsW[i]+'%');
	i++;
});

$('#expandBlog').mouseover(function(){
	$(this).stop().animate({'opacity':1}, 400)
});

$('#expandBlog').mouseout(function(){
	$(this).stop().animate({'opacity':.7}, 400)
});









// CONNECT PAGE ****************************************************************************************************************

// icons
randomLinks = Array('www.drawastickman.com','www.whitevinyldesign.com/solarbeat','www.jlern.com/images/campbell.gif','amitaytweeto.com/thequietplace','hyperboleandahalf.blogspot.com/2010/09/four-levels-of-social-entrapment.html','lucylou.livejournal.com/590766.html','www.logicalparadoxes.info','theageofreason.org/post/352081397/every-atom-in-your-body-came-from-a-star-that','www.jlern.com/archived');

$('#connect_icons > div[id^="connect"] a').each(function(){
	$(this).mouseover(function(){
	if(!ie){
		$(this).children('.circleroll').stop().animate({'opacity':1},400);
	}
	});
	
	$(this).mouseout(function(){
		$(this).children('.circleroll').stop().animate({'opacity':0},400);
	});

	$(this).click(function(){
	
	_gaq.push(['_trackPageview',$(this).parent().attr('id')]);
	
		if($(this).attr('href').substring(0,4) == 'mail'){
			location.href = $(this).attr('href');
		} else if($(this).attr('href').substring(0,1) == '#'){
			rand = Math.floor(Math.random()*randomLinks.length)
			window.open('http://'+randomLinks[rand]);
		} else {
			window.open($(this).attr('href'));
		}
		return false;
	});
});
	


// contact form functions

$('#formStatus').mouseover(function(){
	$(this).stop().animate({'background-color':'#FBB040'},400);
});

$('#formStatus').mouseout(function(){
	if(!sending){
		$(this).stop().animate({'background-color':'#BCBEC0'},400);
	}
});

$('#formStatus').click(function(e){
		validateForm();	
});


// contact form submission

$('#contactForm').submit(function (){
	validateForm();	
	return false;
});

var presets = Array('Your Name','your.name@website.com','I love your website!');
var m;
var sending = false;

$('[data-rel="field"]').each(function(){
	$(this).focus(function(){
		m = $(this).attr('data-num');
		
		if($(this).val() == presets[$(this).attr('data-num')]){
			$(this).val("");
		}
		if($('#thanks').css('display') != 'none'){
			$('#thanks').fadeOut('slow');
			$('[data-rel="field"]').each(function(){
				if($(this).attr('data-num') != m){
					$(this).css('color','#DEDEDE');
					$(this).val(presets[$(this).attr('data-num')]);
				}
			});
		}
		$(this).css('color','#A7A9AC');
	});
	
	$(this).blur(function(){
		if($(this).val() == ""){
			$(this).val(presets[$(this).attr('data-num')]);
			$(this).css('color','#DEDEDE');
		}
	});
});

function validateForm(){
	var vNum = 0;
	m=0;
	$('[data-rel="field"]').each(function(){
		if($(this).val() == ""){
			vNum++;
			alert("Please fill in all fields.");
			return false; 
		}
		if($(this).val() == presets[m]){
			vNum++;
			alert("Please fill in all fields.");
			return false; 
		}
		m++;
	});
	if(vNum==0){
		sendForm();
	}
}

function sendForm(){
	sending = true;
	var name = $('#name').val();
	var email = $('#email').val();
	var comments = $('#comments').val();
		
	$('#thanks').hide();
	$('#sending').fadeIn('fast');

	$('#name').animate({'opacity':.5},400);
	$('#email').animate({'opacity':.5},400);
	$('#comments').animate({'opacity':.5},400);
		
	$.ajax({
		url: 'scripts/form.php',
		type: 'POST',
		data: 'name=' + name + '&email=' + email + '&comments=' + comments,
		
		success: function(result){			
			$('#sending').delay(800).fadeOut('slow',function(){
				$('#thanks').fadeIn('slow');
				$('#formStatus').stop().animate({'background-color':'#BCBEC0'},400);
				$('#name').animate({'opacity':1},400);
				$('#email').animate({'opacity':1},400);
				$('#comments').animate({'opacity':1},400);
				
				$('[data-rel="field"]').each(function(){
					$(this).val("");	
				});
					
				sending = false;	
			});
		}
	});
		
	return false;
}








// NAVIGATION ****************************************************************************************************************

var pageNames = Array('thoughts','work','about','honors','connect','filler');
var rollWidths = Array(125,85,95,105,115);
var idNum;
var rollW;

// rollovers for global nav in header

$('div[id^="navtext"]').each(function(){

	$(this).mouseover(function(){
		idNum = $(this).attr('data-num');
		navOn(idNum);
	});
	
	$(this).mouseout(function(){
	if(idNum != active){
		idNum = $(this).attr('data-num');
		navOut(idNum);
	}
	});
	
	$(this).click(function(){
		idNum = $(this).attr('data-num');
		requestPage(idNum);
	});
	
})

// rollovers for modules

$('[id^="module"]').each(function(){
	// turn off children for homepage so only button is clickable
	$(this).children().css('pointer-events','none')

	$(this).mouseover(function(){
		idNum = $(this).attr('data-num');
		modOn(idNum);
	});
	
	$(this).mouseout(function(){
		idNum = $(this).attr('data-num');
		if(idNum != active){
			modOut(idNum);
		}
	});
	
	$(this).click(function(){
	if(idNum != active){
		idNum = $(this).attr('data-num');
		requestPage(idNum);
	}
	});
});

// roll on and off functions

function navOn(num){
	$('#navtext_'+pageNames[num]).stop().animate({color: modColors[num]}, 'fast');
	$('#navroll_'+pageNames[num]).stop().animate({width:rollWidths[num]}, 600, 'easeOutExpo');
}

function navOut(num){
	$('#navtext_'+pageNames[num]).stop().animate({color: '#ffffff'}, 'fast');
	$('#navroll_'+pageNames[num]).stop().animate({width:'0'}, 400, 'easeOutExpo');
}

function modOn(num){
	$('#module_'+pageNames[num]+' > div[class="modHeader"]').stop().animate({'background-color': modColors[num]}, 400);
	$('#module_'+pageNames[num]+' > div[id^="contents"]').stop().animate({'color': '#808285'}, 400);
	
	// slide up call to action in footer
	$('#cta_'+pageNames[num]+' > div:first-child').stop().animate({'top':-30},200, 'easeOutExpo');
	$('#cta_'+pageNames[num]+' > div:last-child').stop().animate({'top':-11},400, 'easeOutExpo');
}

function modOut(num){
	$('#module_'+pageNames[num]+' > div[class="modHeader"]').stop().animate({'background-color': '#A7A9AC'}, 400);
	$('#module_'+pageNames[num]+' > div[id^="contents"]').stop().animate({'color': '#A7A9AC'}, 400);
	
	// slide up call to action in footer
	$('#cta_'+pageNames[num]+' > div:first-child').stop().animate({'top':7},400, 'easeOutExpo');
	$('#cta_'+pageNames[num]+' > div:last-child').stop().animate({'top':30},200, 'easeOutExpo');
}









// PAGE TRANSITIONS ****************************************************************************************************************

var widths = Array('680','335','450','517','455');
var buf = 15;
var spacer = 7;
var collapseW = 105;
var activeX;
var active = -1;
var last = -1;
var del1 = 300;
var del2;
var tempXHolds = Array();

function requestPage(pageNum){

	active = pageNum;
	modOut(idNum); // be sure roll state turns off

	// check if going home
	if(pageNum == -1){
	
		// check if portfolio is open, close if so
		if(portStat == "open"){
			closePortfolio('home');
		} else {
			gotoHome();
		}
		
	// if going to new section
	} else {
	
		// check if portfolio is open, close
		if(portStat == "open"){		
			closePortfolio('tier');
		} else {
			gotoPage();
		}
	}
}

function gotoPage() { 

activeX = (active*(collapseW+spacer))+buf;
// if content is cut off, setup scrollbar
checkScroll();

//activate button in header nav
if(!ie){
$('#navtext_'+pageNames[active]).css('pointer-events','none');
if($('#navroll_'+pageNames[active]).width() <5){
	$('#navtext_'+pageNames[active]).delay(600).animate({color: modColors[active]}, 'fast');
	$('#navroll_'+pageNames[active]).delay(600).animate({width:rollWidths[active]}, 600, 'easeOutExpo');
}

// turn off last button in up state
$('#navtext_'+pageNames[last]).css('pointer-events','auto');
$('#navtext_'+pageNames[last]).delay(100).animate({color: '#ffffff'}, 'fast');
$('#navroll_'+pageNames[last]).animate({width:'0'}, 300, 'easeInExpo');
$('#expandBlog').animate({'opacity':0}, 400);
//
}

//IE fix for nav
if(ie){
if($('#IEnavroll_'+pageNames[active]).height() <5){
$('#IEnavroll_'+pageNames[active]).delay(600).animate({height:rollWidths[active]+5}, 600, 'easeOutExpo');
$('#IEnavrolltext_'+pageNames[active]).delay(700).animate({opacity: 1}, 'slow');
}
if(last!=-1){
$('#IEnavroll_'+pageNames[last]).animate({height:0}, 300, 'easeInExpo');
$('#IEnavrolltext_'+pageNames[last]).stop().animate({opacity: 0}, 100);
}
}


//turn auto pointer events back on / hide hotspot
$('#module_'+pageNames[active]).children().css('pointer-events','auto');
if(ie){
 $('#module_'+pageNames[active]+' > div[class="hotspot"]').css('display','none');
}



//set colors/icon for active module
$('#module_'+pageNames[active]).css('cursor','auto');
if($('#module_'+pageNames[active]+' > div[class="modHeader"]').css('background-color') != modColors[active]){
	$('#module_'+pageNames[active]+' > div[class="modHeader"]').animate({'background-color': modColors[active]}, 400);
	$('#module_'+pageNames[active]+' > div[id^="contents"]').animate({'color': '#808285'}, 400);
}

$('#icon_'+pageNames[active]+' > img:first-child').fadeOut(400);
$('#icon_'+pageNames[active]+' > img:last-child').fadeIn(400);

// turn off last module on state
if(!home){
	$('#module_'+pageNames[last]).children().css('pointer-events','none');
	if(ie){
		 $('#module_'+pageNames[last]+' > div[class="hotspot"]').css('display','block');
	}
	$('#module_'+pageNames[last]+' > div[class="modHeader"]').animate({'background-color': '#A7A9AC'}, 400);
	$('#module_'+pageNames[last]+' > div[id^="contents"]').animate({'color': '#A7A9AC'}, 400);
	$('#icon_'+pageNames[last]+' > img:first-child').fadeIn(400);
	$('#icon_'+pageNames[last]+' > img:last-child').fadeOut(400);
	$('#module_'+pageNames[last]).css('cursor','pointer');
}
//



// remove footer call to actions from home
if(home){
	$('[id^="module"]').each(function(){
		n = $(this).attr('data-num');
		$('#module_'+pageNames[n]+' > div[class="modFooter"]').animate({'bottom':'-37px'}, 400, 'easeInExpo'); // remove home footer
		$('#module_'+pageNames[n]+' > div:[class="bottomShadowMod"]').animate({'bottom':'0'}, 400, 'easeInExpo'); // move shadow down
	});
	
	
	// tweaks for once you leave homepage
	setTimeout(function(){
	
		// expand blog 
		//$('#scrollbar_thoughts > [class="viewport"]').css('width','680px');
		//$('#contents_thoughts').css('width','695px');
		
		// bring form and thumbs to top
		$('#module_connect').children('.bottomShadowMod').css('z-index',0);
		$('#module_work').children('.bottomShadowMod').css('z-index',0);
	},500);
} else {
}



// expand active module
fullW = parseInt(widths[active])+scrollW;
// set x location and width; change hash address once complete
$('#module_'+pageNames[active]).delay(del1).animate({'left':activeX,'width':fullW+'px'}, 600, 'easeInOutExpo');
$('#module_'+pageNames[active]+' > div[class="modHeader"] > div[id^="icon"]').delay(del1).animate({'right':'12px'}, 600, 'easeInOutExpo'); // slide icon back
$('#module_'+pageNames[active]+' > div[class="modHeader"] > div[class="header"]').delay(del1).animate({'left':'18px'}, 600, 'easeInOutExpo'); // show text
//



// collapse all other modules
$('[id^="module"]').each(function(){

n = $(this).attr('data-num');
if(n != active && n!=5){

	// collapse module
	$('#module_'+pageNames[n]+' > div[class="modHeader"] > div[class="header"]').delay(del1).animate({'left':'-220px'}, 600, 'easeInOutExpo'); // slide text over/hide
	$('#module_'+pageNames[n]+' > div[class="modHeader"] > div[id^="icon"]').delay(del1).animate({'right':'26px'}, 600, 'easeInOutExpo'); // slide icon over
	
	//move module into position
	
	if(n<active){
		// if before active
		tempX = buf+((collapseW+spacer)*n);
	} else{
		// if after active
		tempX = parseInt(fullW)+buf+((collapseW+spacer)*n)-collapseW;
	}
	
	tempXHolds[n] = tempX;
	$('#module_'+pageNames[n]).delay(del1).animate({'left':tempX+'px','width':'105px'}, 600, 'easeInOutExpo');
}

});

// set location for filler module
if(pageNames[active] == "connect"){
tempX = activeX+parseInt(fullW);
} else{
tempX = tempX+collapseW;
}
endX = $(window).width()-tempX-15;
tempXHolds[5] = tempX;
$('#module_filler').delay(del1).animate({'left':tempX+7,'width':endX}, 600, 'easeInOutExpo');

home = false;
last = active;
$('#logo').css('cursor','pointer');

// check hash first, if direct jump to project don't change
if(direct != true){
location.hash = "!/"+pageNames[active];
}
direct = false;

// reset contact form on enter and leave connect page
if($('#thanks').css('display') != 'none'){
	$('#thanks').fadeOut('slow');
}
$('[data-rel="field"]').each(function(){
	$(this).css('color','#DEDEDE');
	if($('#thanks').css('display') != 'none'){
		$(this).val(presets[$(this).attr('data-num')]);
	}
	if(active == 4 && $(this).val() != presets[$(this).attr('data-num')]){
		$(this).css('color','#A7A9AC');
	}
});

// bring on expand blog button
if(pageNames[active] == "thoughts"){
	$('#expandBlog').delay(del1+100).animate({'opacity':.7}, 400);
}

}

// END go to a page from homepage ****************************************












// TRANSITION HOME ****************************************************************************************************************

$('#logo').css('cursor','auto');

$('#logo').mouseover(function(){
	if(!home){
		$(this).stop().animate({'background-color':'#FFE98A'},'fast');
	}
});

$('#logo').mouseout(function(){
	if(!home){
		$(this).stop().animate({'background-color':'#FFE06A'},'fast');
	}
});

$('#logo').click(function(){
	if(!home){
		$(this).animate({'background-color':'#FFE06A'},'fast');
		requestPage(-1);
	}
});



function gotoHome(){

location.hash = '';
home = true;
$('#logo').css('cursor','auto');

// return active module to off state
$('#module_'+pageNames[last]).children().css('pointer-events','none');
if(ie){
	$('#module_'+pageNames[last]+' > div[class="hotspot"]').css('display','block');
}
$('#module_'+pageNames[last]+' > div[class="modHeader"]').animate({'background-color': '#A7A9AC'}, 400);
$('#module_'+pageNames[last]+' > div[id^="contents"]').animate({'color': '#A7A9AC'}, 400);
$('#icon_'+pageNames[last]+' > img:first-child').fadeIn(400);
$('#icon_'+pageNames[last]+' > img:last-child').fadeOut(400);
$('#module_'+pageNames[last]).css('cursor','pointer');
$('#expandBlog').animate({'opacity':0}, 400);

if(!ie){
	$('#navtext_'+pageNames[last]).css('pointer-events','auto');
	$('#navtext_'+pageNames[last]).animate({color: '#ffffff'}, 'fast');
	$('#navroll_'+pageNames[last]).animate({width:'0'}, 300, 'easeInExpo');
} else {
	$('#IEnavroll_'+pageNames[last]).animate({height:0}, 300, 'easeInExpo');
	$('#IEnavrolltext_'+pageNames[last]).animate({opacity: 0}, 100);

}

/*// shrink blog back to fit
setTimeout(function(){
$('#scrollbar_thoughts > [class="viewport"]').css('width',modWidths[0]);
$('#contents_thoughts').css('width',modWidths[0]);
$('#sbar_thoughts').css('right','-17px');
},300); */

// expand all modules
modX = 15;
$('[id^="module"]').each(function(){
	n = $(this).attr('data-num');

	// expand module
	$('#module_'+pageNames[n]+' > div[class="modHeader"] > div[class="header"]').animate({'left':'18px'}, 600, 'easeInOutExpo'); // slide text over/hide
	
	// slide icon over if on normal sized monitor; otherwise hide icon
	if($(window).width()>1170){
	$('#module_'+pageNames[n]+' > div[class="modHeader"] > div[id^="icon"]').animate({'right':'12px'}, 600, 'easeInOutExpo'); 
	} else {
	$('#module_'+pageNames[n]+' > div[class="modHeader"] > div[id^="icon"]').animate({'right':'-60px'}, 600, 'easeInOutExpo'); 
	}
	
	//move module into position	
	if(n>0){
		modX += (modWidths[n-1])+7;
	}
	
	if(pageNames[n] == "filler"){
		tempX = $('#module_connect').offset().left+$('#module_connect').width();
		endX = winW-tempX+15;
		$('#module_'+pageNames[n]).animate({'left':modX+'px','width':endX+'px'}, 600, 'easeInOutExpo');
	} else {
		$('#module_'+pageNames[n]).animate({'left':modX+'px','width':modWidths[n]+'px'}, 600, 'easeInOutExpo');
	}
});

last = -1;

// reset contact form
$('#connect_form').css('z-index',1);
if($('#thanks').css('display') != 'none'){
	$('#thanks').fadeOut('slow');
}
$('[data-rel="field"]').each(function(){
	$(this).css('color','#DEDEDE');
	if($('#thanks').css('display') != 'none'){
		$(this).val(presets[$(this).attr('data-num')]);
	}
});
}











// HONORS PAGE ****************************************************************************************************************

$('div[data-link]').each(function(){
	$(this).mouseover(function(){
		$(this).stop().animate({'background-color':'#FFFDCF'},'slow');
	})
	$(this).mouseout(function(){
		$(this).stop().animate({'background-color':'#FFFFFF'},'slow');
	})
	$(this).click(function(){
		window.open($(this).attr('data-link'));
	});
});











// SCROLLBAR FUNCTIONS ****************************************************************************************************************

var tempH;
var scrollbodyH;
var scrollW = 0;
var hasScroll = false;

function checkScroll(){
	// reset scrollbar
	scrollW = 0;
	hasScroll = false;
	$('#sbar_'+pageNames[active]).css('right','-17px');
	contentsH = $(window).height()-headerH;
	
	// calculate if area needs scrolling
	tempH = contentsH - 88;
	scrollbodyH = $('#scrollbar_' + pageNames[active] + ' > [class="viewport"] > [class="scrollbody"]').height();
	
	// if scrollable, add scrollbar in
	//alert(scrollbodyH+" / "+tempH)
	if(scrollbodyH >= tempH){
		if(active != 1){
			scrollW = 15; // add extra space for scrollbar if needed
			if(pageNames[active] == "connect"){
				$('#contents_connect').css('width','470px');
			}
		}
		setTimeout(function(){
		$('#scrollbar_'+pageNames[active]+' > [class="viewport"]').css({'width':widths[active]-(15-scrollW),'height':tempH});
		$('#scrollbar_'+pageNames[active]).tinyscrollbar();
		hasScroll = true;
		$('#sbar_'+pageNames[active]).animate({'right':'0px'}, 800, 'easeInOutExpo');
		},600);
	} else {
		$('#scrollbar_'+pageNames[active]).tinyscrollbar();
		hasScroll = true;
	}
}

// adjust scrollbars when page is resized

function updateScrollBars(){

	tempH = contentsH - 88;
	scrollbodyH = $('#scrollbar_' + pageNames[active] + ' > [class="viewport"] > [class="scrollbody"]').height();
	barX = $('#sbar_'+pageNames[active]).css('right');	

	$('div[id^="scrollbar_"] > [class="viewport"]').css('height',tempH);
	$('#scrollbar_'+pageNames[active]).tinyscrollbar_update('relative');

	// if scrollbar not needed anymore, REMOVE SCROLLBAR
	if(scrollbodyH < (tempH+20) && parseInt(barX) == 0){
		//alert("remove")
		scrollW = 0;
		if(active==0){
			//scrollW = -15;
		}
		$('#sbar_'+pageNames[active]).stop().animate({'right':'-17px'}, 900, 'easeOutExpo');
		$('#module_'+pageNames[active]).stop().animate({'width':(parseInt(widths[active])+scrollW)+'px'}, 900, 'easeInOutExpo'); 
		
		//move modules into position	
		$('[id^="module"]').each(function(){
			n = $(this).attr('data-num');
			if(n > active){				
				tempX = $('#module_'+pageNames[n]).position().left-15;
				endX = winW-tempX+15;
				if(n==5){ 
					$('#module_'+pageNames[n]).stop().animate({'left':tempX+'px','width':endX}, 900, 'easeInOutExpo');
				} else {
					$('#module_'+pageNames[n]).stop().animate({'left':tempX+'px'}, 900, 'easeInOutExpo');
				}
			}
		});
	}
	
	
	// if scrollbar gone and needed, ADD SCROLLBAR
	if(scrollbodyH > (tempH+20) && parseInt(barX) == -17){
		//alert("add")
		scrollW = 15;
		if(active==0){
			//scrollW = 0;
		}
		$('#sbar_'+pageNames[active]).stop().animate({'right':'0px'}, 900, 'easeOutExpo');
		$('#module_'+pageNames[active]).stop().animate({'width':(parseInt(widths[active])+scrollW)+'px'}, 900, 'easeInOutExpo');
		
		if(pageNames[active] == "connect"){
			$('#contents_connect').css('width','470px');
		}
		
		//move modules into position	
		$('[id^="module"]').each(function(){
			n = $(this).attr('data-num');
			if(n > active){				
				tempX = tempXHolds[n]+15;
				endX = winW-tempX+15;
				if(n==5){ 
					$('#module_'+pageNames[n]).stop().animate({'left':(tempX+7)+'px','width':endX}, 900, 'easeInOutExpo');
				} else {
					$('#module_'+pageNames[n]).stop().animate({'left':tempX+'px','width':'105px'}, 900, 'easeInOutExpo');
				}
			}
		}); 
	}
}

//scrollbar fix for IE
if(ie){
	$('[id^="scrollbar"]').addClass('scrollIE');
}









/* WORK SECTION ----------------------------------------------------------------------------*/

var portW = 711;
var portStat = "closed";
var clientID;
var clientNum;
var activeProject = -1;
var projH = 396;

function setupThumbs(){
$('div[id^="thumb_"]').each(function(){
	$(this).mouseover(function(){
		num = $(this).attr('data-num');
		$('#thumbC_'+ids[num]).children('.thumbOver').stop().animate({'opacity':1}, 600);
		$('#thumbC_'+ids[num]).children('.rollTitle').children('.rollTitle_wrapper').stop().animate({'top':0}, 400, 'easeOutExpo');
	});
	$(this).mouseout(function(){
		num = $(this).attr('data-num');
		$('#thumbC_'+ids[num]).children('.thumbOver').stop().animate({'opacity':0}, 600);
		$('#thumbC_'+ids[num]).children('.rollTitle').children('.rollTitle_wrapper').stop().animate({'top':30}, 400, 'easeInOutExpo');
	});
	$(this).click(function(){
		clientID = $(this).attr('id').split('_')[1];
		clientNum = $(this).attr('data-num');
		
		if(activeProject != clientNum){
		if(portStat == "closed"){
			openPortfolio(clientNum);
		} else {
			changeProject(clientNum);
		}
		}
	});
});
}

function openPortfolio(proj){
// set address bar with project
location.hash = "!/"+pageNames[active]+"/"+clientID;

portStat = "open";
activeProject = parseInt(proj);
//alert('open portfolio')

// populate portfolio viewer
$('#projectTitle1').text(projectTitles[activeProject]);
$('#projectRole1').text(projectRoles[activeProject]);
$('#projectLink1').attr('href',projectLinks[activeProject]);

// add images w/ loaders
loadImage('#portImage11','images/work/'+clientID+'1.jpg');
loadImage('#portImage12','images/work/'+clientID+'2.jpg');
loadImage('#portImage13','images/work/'+clientID+'3.jpg');

// move modules over
$('[id^="module"]').each(function(){

n = $(this).attr('data-num');
if(n > 1){
	tempX = portW+parseInt(fullW)+buf+((collapseW+spacer)*n)-collapseW;
	$('#module_'+pageNames[n]).animate({'left':tempX+'px'}, 600, 'easeInOutExpo');
}

});

// reset portfolio containers
pContainer = 1;
$('#portfolio').css('display','inline');
$('#portfolioContainer1').css('left','-704px');
$('#portfolioContainer2').css('left','704px'); // restore 2nd portfolio module to not show

// reset dot thumbs
$('#dot'+pContainer+'1').css('opacity',0);
$('#dot'+pContainer+'2').css('opacity',1);
$('#dot'+pContainer+'3').css('opacity',1);

// prep slideshow
prepSlideshow();

// slide out portfolio module
$('#portfolioContainer1').animate({'left':'0px'}, 600, 'easeInOutExpo');

}


function closePortfolio(toPage){
portStat = "closed";
activeProject = -1;
clearInterval(slides);
slideStat = "off";
modOut(idNum);

// move modules over
$('[id^="module"]').each(function(){

n = $(this).attr('data-num');
if(n > 1){
	tempX = parseInt(fullW)+buf+((collapseW+spacer)*n)-collapseW;
	$('#module_'+pageNames[n]).animate({'left':tempX+'px'}, 600, 'easeInOutExpo');
}

});

// slide out portfolio module
$('#portfolioContainer'+pContainer).animate({'left':'-704px'}, 600, 'easeInOutExpo', function(){
	$('#portfolio').css('display','none');
	if(toPage == "home"){
		gotoHome();
	} else {
		gotoPage();
	}
});

}

function directclosePortfolio(toPage){
portStat = "closed";
activeProject = -1;
clearInterval(slides);
slideStat = "off";

// move modules over
$('[id^="module"]').each(function(){

n = $(this).attr('data-num');
if(n > 1){
	tempX = parseInt(fullW)+buf+((collapseW+spacer)*n)-collapseW;
	$('#module_'+pageNames[n]).animate({'left':tempX+'px'}, 600, 'easeInOutExpo');
}

});

// slide out portfolio module
$('#portfolioContainer'+pContainer).animate({'left':'-704px'}, 600, 'easeInOutExpo', function(){
	$('#portfolio').css('display','none');
	});
}



// changing projects by sliding new module over

var pContainer = 1;

function changeProject(proj){
	// set address bar with project
	location.hash = "!/"+pageNames[active]+"/"+clientID;
	
	activeProject = parseInt(proj);
	clearInterval(slides);
	slideStat = "off";
	//alert('change portfolio')
	
	if(pContainer == 1){
		// slide containers
		$('#portfolioContainer1').animate({'left':'-704px'}, 600, 'easeInOutExpo');
		$('#portfolioContainer2').css('left','704px');
		$('#portfolioContainer2').animate({'left':'0px'}, 600, 'easeInOutExpo', function(){prepSlideshow()});
		pContainer = 2;
	} else {
		// slide containers
		$('#portfolioContainer2').animate({'left':'-704px'}, 600, 'easeInOutExpo');
		$('#portfolioContainer1').css('left','704px');
		$('#portfolioContainer1').animate({'left':'0px'}, 600, 'easeInOutExpo', function(){prepSlideshow()});
		pContainer = 1;
	}
	
	// populate portfolio viewer
	$('#projectTitle'+pContainer).text(projectTitles[activeProject]);
	$('#projectRole'+pContainer).text(projectRoles[activeProject]);
	$('#projectLink'+pContainer).attr('href',projectLinks[activeProject]);
	
	// add images w/ loaders
	loadImage('#portImage'+pContainer+'1','images/work/'+clientID+'1.jpg');
	loadImage('#portImage'+pContainer+'2','images/work/'+clientID+'2.jpg');
	loadImage('#portImage'+pContainer+'3','images/work/'+clientID+'3.jpg');
	
	// reset dot thumbs
	$('#dot'+pContainer+'1').css('opacity',0);
	$('#dot'+pContainer+'2').css('opacity',1);
	$('#dot'+pContainer+'3').css('opacity',1);
}


// mouseover for launch button

$('[class="launcher"]').mouseover(function(){
	$(this).stop().animate({'background-color':'#000000'},'slow');
});

$('[class="launcher"]').mouseout(function(){
	$(this).stop().animate({'background-color':'#414042'},'slow');
});

$('[class="launcher"]').click(function(){
	window.open($('#projectLink'+pContainer).attr('href'));
	return false;
});


// image slideshow for projects

var slideNum = 1;
var slideStat = "off";

function prepSlideshow(){
slideNum = 1;

$('[id^="portImage"]').each(function(){
	num = parseInt($(this).attr('data-num'));
	if(num==0){
		tempH = 0;
	} else {
		tempH = projH;
	}
	$(this).css('top',tempH+'px');
});

if(slideStat == "on"){
	clearInterval(slides);
}
goSlideshow();

}



function goSlideshow(){
slideStat = "on";

	slides = setInterval(function(){
		$('#portImage'+pContainer+slideNum).animate({'top':'-396px'}, 600, 'easeInOutExpo');
		$('#dot'+pContainer+slideNum).animate({'opacity':1}, 400);
		
		slideNum++;
		if(slideNum == 4){
			slideNum = 1;
		}
		$('#portImage'+pContainer+slideNum).css('top','396px');
		$('#portImage'+pContainer+slideNum).animate({'top':'0px'}, 600, 'easeInOutExpo');
		$('#dot'+pContainer+slideNum).animate({'opacity':0}, 400);
		
	}, 3000);
}

// button actions for dots

$('[class="imageDot"]').each(function(){
	$(this).click(function(){
	
	if(slideStat == "on"){
		clearInterval(slides);
		slideStat = "off";
	}
		
	$('#portImage'+pContainer+slideNum).animate({'top':'-396px'}, 600, 'easeInOutExpo');
	$('#dot'+pContainer+slideNum).animate({'opacity':1}, 400);
		
	slideNum = $(this).attr('data-num');
		
	$('#portImage'+pContainer+slideNum).css('top','396px');
	$('#portImage'+pContainer+slideNum).animate({'top':'0px'}, 600, 'easeInOutExpo');
	$('#dot'+pContainer+slideNum).animate({'opacity':0}, 400);
		
	});
});




// image loading

function loadImage(target, imgsrc){
	$(target).children().remove();
	var image = new Image();
	$(target).addClass('loading');
	
	$(image).load(function (){
		$(image).hide();
		$(target).removeClass('loading').append(image);
		$(image).fadeIn('slow');
	}).attr('src',imgsrc);
}

function loadImageDel(target, imgsrc){
	var image = new Image();
	
	$(image).load(function (){
	setTimeout(function(){
		$(image).hide();
		$(target).removeClass('loading').append(image);
		$(image).fadeIn('slow');
	}, 300);
	}).attr('src',imgsrc);
}





// load XML data for portfolio

var ids = new Array();
var projectTitles = new Array();
var projectRoles = new Array();
var projectLinks = new Array();
var activePort = "none";
var thumbsLoaded = false;

$.ajax({
	type: "GET",
	url: "xml/jlernWork.xml",
	dataType: "xml",
	success: xmlParser
});
 
function xmlParser(xml) {
i=0;
    $(xml).find("project").each(function () {
    	ids[i] = $(this).attr("id");
		projectTitles[i] = $(this).find("title").text();
		projectRoles[i] = $(this).find("role").text();
		projectLinks[i] = $(this).find("link").text();
		i++;
    });
    
    buildThumbs();
}




// build out thumbnails for work

function buildThumbs(){

	for(i=0;i<ids.length;i++){
	$('#container_thumbs').append('<div id="thumb_' + ids[i] + '" data-num="' + i + '"><div class="thumbWrapper"><div id="thumbC_' + ids[i] + '" class="loading"><img src="images/work/thumbs/' + ids[i] + '_over.jpg" class="thumbOver" alt="' + ids[i] + '"><div class="rollTitle"><div class="rollTitle_wrapper"><div class="rollTitleBG"></div><div class="rollTitleTxt">' + projectTitles[i] + '<div class="rollPlus">+</div></div></div></div></div></div><div class="thumbshad"></div></div>');
	}
	
	thumbsLoaded = true;
	setupThumbs();
}






// for url address hashing
var titleTxt = "JLern Design";

$(window).hashchange(function(){

// redirct if not a valid page
tempAd = location.hash.split("/")[1];
if(location.hash == ""){
	tempAd = "#";
}
validPage = false;
for(i=0;i<pageNames.length;i++){
	if(tempAd == pageNames[i]){
		validPage = true;
	}
}
if(tempAd == "#"){
	validPage = true;
}

if(!validPage){
	location.href = "http://www.jlern.com/404";
} else {
	_gaq.push(['_trackPageview',location.hash]);
}

	// if there is a hash address
	if(location.hash.length>1) {
		tempAd = location.hash.split("/");
		activeName = tempAd[1];
		$(document).attr('title', titleTxt+" { "+activeName+" }");

		// check if portfolio
		if(activeName.substr(0,4) == "work"){
			activePort = "none";
			if(tempAd.length>2){
				activePort = tempAd[2];
			} 
			active = 1;
			
			int = setInterval(function(){
				if(thumbsLoaded){
					clearInterval(int);
					setWorkAddress();
				}
			}, 50);
		
		// not portfolio, go directly to page	
		} else {
			active = $('#module_'+activeName).attr('data-num');
			if(active != last ){
				requestPage(active);
			}	
		} 
		
	// if no hash, go home	
	} else {
		$(document).attr('title', titleTxt+" | Where Designer & Programmer Play Nice Together");
		active = -1;
		if(active != last){
			requestPage(active);
		}
	}
});



function setWorkAddress(){

// if no project selected
if(activePort == "none"){

	if(portStat == "closed"){
		if(active != last){
			requestPage(1);
		}
	} else {
    	directclosePortfolio();
    }
    
    
// if project selected in url
} else {

    // if direct jump from home, open work section first, then portfolio
    if(home){
    	direct = true;
    	requestPage(1);
    	setTimeout(function(){
    		portNum = $('#thumb_' + activePort).attr('data-num');
    		clientID = $('#thumb_' + activePort).attr('id').split('_')[1];
    		openPortfolio(portNum);
    	}, 900);
    	
    }
    
    
    // if tier and portfolio is closed, open first
	else if(portStat == "closed"){
    
    	// if work is closed, go to work first
    	if($('#module_work').width()<335){
    		direct = true;
    		requestPage(1);
    		setTimeout(function(){
    			portNum = $('#thumb_' + activePort).attr('data-num');
    			clientID = $('#thumb_' + activePort).attr('id').split('_')[1];
   				openPortfolio(portNum);
   			}, 900);
   		} else {
   		
   			// if work is open
   			portNum = $('#thumb_' + activePort).attr('data-num');
			openPortfolio(portNum);
		}

	} else {		
	
    		// if portfolio already open, change project
    		portNum = $('#thumb_' + activePort).attr('data-num');
    		clientID = $('#thumb_' + activePort).attr('id').split('_')[1];
    		if(portNum != activeProject){
    			changeProject(portNum);
    		}
	}				
}
}




// special nav for IE to compensate for no rotation

$('div[id^="navIE"]').each(function(){

	$(this).mouseover(function(){
		idNum = $(this).attr('data-num');
		navOnIE(idNum);
	});
	
	$(this).mouseout(function(){
	if(idNum != active){
		idNum = $(this).attr('data-num');
		navOutIE(idNum);
	}
	});
	
	$(this).click(function(){
		idNum = $(this).attr('data-num');
		requestPage(idNum);
	});
	
})

function navOnIE(num){
	$('#IEnavroll_'+pageNames[num]).stop().animate({height:rollWidths[num]+5}, 600, 'easeOutExpo');
	tempPg = '#IEnavrolltext_'+pageNames[num];
	ieint = setTimeout(function(){
		$(tempPg).stop().animate({opacity: 1}, 'slow');
	}, 100);
}

function navOutIE(num){
	clearTimeout(ieint);
	$('#IEnavrolltext_'+pageNames[num]).stop().animate({opacity: 0}, 100);
	$('#IEnavroll_'+pageNames[num]).stop().animate({height:'0'}, 400, 'easeOutExpo');
}










// get blogs from database

var blogTitles = [];
var blogDates = [];
var blogTexts = [];
var months = Array('January','February','March','April','May','June','July','August','September','October','November','December');

$.post('scripts/getBlogs.php', function(data) {
	parseTypes = data.split('::');
	blogTitles = parseTypes[0].split('^');
	blogDates = parseTypes[1].split('^');
	blogTexts = parseTypes[2].split('^');
	blogTotals = parseTypes[3].split('^');
	
	buildBlog();
});

function buildBlog(){
newBlog = "";

	for(i=0;i<blogTitles.length;i++){

	// format date
	tempDate = blogDates[i].substring(4,6);
	formattedDate = months[tempDate-1] + " " + blogDates[i].substring(6,8) + ", " + blogDates[i].substring(0,4);
		
		
		// last article does not have white bar below it
		if(i==blogTitles.length-1){
			newBlog += '<article class="lastAr" id="article' + i + '">';
		} else {
			newBlog += '<article id="article' + i + '">';
		}
		
		// blog body contents
		newBlog += '<header>';
		newBlog += '<h2>' + blogTitles[i] + '</h2>';
		newBlog += '<time datetime="' + blogDates[i] + '" pubdate>' + formattedDate + '</time>';
		newBlog += '</header>';
		newBlog += '<p>' + blogTexts[i] + '</p>';
		
		// comment form
		newBlog += '<div class="commentDivider"></div>';
		newBlog += '<div class="commentsLink"><a href="javascript:void(0)" id="showComments' + i + '">COMMENTS (0)</a></div>';
		newBlog += '<div class="comments">';
		newBlog += '<div class="commentThanks">Thank you. Your comments are awaiting moderation.</div>';
		newBlog += '<div class="addComments">';
		newBlog += '<div class="addComOverlay"><div style="float:left"><div class="commentDummyTx"></div><div class="commentDummyTx"></div><div class="commentDummyTx"></div></div><div style="float:right; margin-left:5px;"><div class="commentDummyAr"></div></div><div class="comLoader"><img src="images/bluecog.gif" alt="loader"></div></div>';
		
		newBlog += '<form action="scripts/addcomment.php" method="post" id="commentForm' + i + '" data-num="' + i + '">';
		newBlog += '<div class="blogformLeft">';
		newBlog += '<input type="text" id="comName' + i + '" data-rel="comfield' + i + '" data-num="0" value="Name">';
		newBlog += '<input type="text" id="comEmail' + i + '" data-rel="comfield' + i + '" data-num="1" value="Email">';	
		newBlog += '<input type="text" id="comWebsite' + i + '" data-rel="comfield' + i + '" data-num="2" value="Website"></div>';
		newBlog += '<div class="blogformRight">';
		newBlog += '<textarea id="comComments' + i + '" data-rel="comfield' + i + '" data-num="3">Comments</textarea>';
		newBlog += '<input type="submit" value="submit"></div></form></div>';
		
		// comments
		newBlog += '<div id="showComs' + i + '" class="showCom"></div>';
		
		// end
		newBlog += '</div></article>';
	}
	
	$('#blogContainer').html(newBlog);
	
	setTimeout(function(){
		$('#module_thoughts > div[class="modloading"]').animate({'opacity':0},'fast',function(){
			setupBlog();
			getComments(0);
			$('#article0 > [class="comments"]').css('display','block');
			$(this).css('display','none');
			
			if(hasScroll){
				updateScrollBars();
			} else {
				checkScroll();
			}
		});
	}, 500);
}









// blog comments

function setupBlog(){

$('form[id^="commentForm"]').submit(function (){
	formNum = $(this).attr('data-num');
	validateComForm();
	return false;
});


$('[data-rel^="comfield"]').each(function(){
	$(this).focus(function(){
		m = $(this).attr('data-num');
		
		if($(this).val() == compresets[$(this).attr('data-num')]){
			$(this).val("");
		}
	});
	
	$(this).blur(function(){
		if($(this).val() == ""){
			$(this).val(compresets[$(this).attr('data-num')]);
		}
	});
});


$('[id^="showComments"]').each(function(){
	$(this).click(function(){
		num = $(this).attr('id').split("Comments")[1];
		
		if($('#showComs'+num).text() == ""){
			getComments(num);
		}
		
		$('#article'+num+' > [class="comments"]').slideToggle(600, 'easeInOutExpo', function(){
			updateScrollBars();
		});
	});
})

commentTotals();

}

var compresets = Array('Name','Email','Website','Comments');
var errormsg = Array('Please fill out your name.','Please fill out your email - it will not show in the post.','','Please fill out your comments.');
var m;
var sending = false;

function validateComForm(){
	vNum = 0;
	m=0;
	$('[data-rel="comfield' + formNum + '"]').each(function(){
		if($(this).val() == "" && $(this).attr('data-num') != '2'){
			vNum++;
			alert(errormsg[$(this).attr('data-num')]);
			return false; 
		}
		if($(this).val() == compresets[m] && $(this).attr('data-num') != '2'){
			vNum++;
			alert(errormsg[$(this).attr('data-num')]);
			return false; 
		}
		m++;
	});
	if(vNum==0){
		sendComForm();
	}
}

function sendComForm(){

	sending = true;
	var title = blogTitles[formNum];
	var name = $('#com'+compresets[0]+formNum).val();
	var email = $('#com'+compresets[1]+formNum).val();
	var website = $('#com'+compresets[2]+formNum).val();
	var comments = $('#com'+compresets[3]+formNum).val();
			
	commentLoc = '#article'+formNum+' > [class="comments"] > [class="addComments"]';
	commentCog = commentLoc + ' > [class="comLoader"]';
	commentCover = commentLoc + ' > [class="addComOverlay"]';
	$(commentCover).fadeIn('fast');
	
	$.ajax({
		url: 'scripts/addcomment.php',
		type: 'POST',
		data: 'title=' + title + '&name=' + name + '&email=' + email + '&website=' + website + '&comments=' + comments,
		
		success: function(result){			
			$(commentCover).delay(800).fadeOut('slow',function(){
				$(commentLoc).slideUp(600, 'easeInOutExpo');
				
				setTimeout(function(){
					$('#article'+formNum+' > [class="comments"] > [class="commentThanks"]').slideDown(600, 'easeOutExpo', function(){
							resetComments();
							updateScrollBars();
						});
				},600);
					
				sending = false;	
			});
		}
	});
		
	return false;
}

function resetComments(){
	$('[data-rel="comfield"]').each(function(){
		num = $(this).attr('data-num');
		$(this).val(compresets[num]);	
	});
}




// get comments from database
var commentsBuilt = false;

function getComments(id){
activeBlog = id;

$.ajax({
		url: 'scripts/getComments.php',
		type: 'POST',
		data: 'title=' + blogTitles[id],
		
		success: function(result){
			parseTypes = result.split(';');
			commentNames = parseTypes[0].split('^');
			commentDates = parseTypes[1].split('^');
			commentWebsites = parseTypes[2].split('^');
			commentTexts = parseTypes[3].split('^');
			
			if(commentsBuilt == false){
				buildComments();
				commentsBuilt = true;
			}
		}
	});
}

function buildComments(){
newComments = "";

	for(i=0;i<commentTexts.length;i++){
	
		// format date
		tempDate = commentDates[i].substring(4,6);
		formattedDate = months[tempDate-1] + " " + commentDates[i].substring(6,8) + ", " + commentDates[i].substring(0,4);
		
		newComments += '<div>';
		newComments += '<header class="showComHeader">';
		
		// check if there is a website link
		if(commentWebsites[i] == "none"){
			newComments += '<h1>' + commentNames[i] + '</h1>';
		} else {
		
			tempWeb = commentWebsites[i];
			if(tempWeb.substring(0,4) != "http"){
				tempWeb = "http://" + commentWebsites[i];
			}
			newComments += '<h1><a href="' + tempWeb + '" target="blank">' + commentNames[i] + '</a></h1>';
		}
		
		newComments += '<h2>' + formattedDate + '</h2>';
		newComments += '</header>';
		newComments += '<div class="commentBody">' + commentTexts[i] + '</div>';
		newComments += '</div>';
	}
	$('#showComs'+activeBlog).append(newComments);
	updateScrollBars();
}

function commentTotals(){
	for(i=0;i<blogTitles.length;i++){
		$('#showComments'+i).text('COMMENTS (' + blogTotals[i] +')');
	}
}









// *********************************************************************************************************************
// *********************************************************************************************************************




// execute once all images have loaded



$(document).ready(function(){
	if(location.hash != ""){
		$(window).hashchange();
		$(window).resize();
	} else {
		$(window).resize();
	}
});

$(window).load(function(){
	tLoad = setInterval(function(){
	
	if(thumbsLoaded){
		clearInterval(tLoad)
		for(i=0;i<ids.length;i++){	
			loadImageDel('div[id="thumbC_' + ids[i] + '"]', 'images/work/thumbs/' + ids[i] + '.jpg');
		}
	}
	
	},100);

	$('#icon_'+pageNames[active]+' > img:first-child').fadeOut(400);
	$('div[class="modloading"]').each(function(){
		if($(this).parent().attr('data-num') != 0){
			$(this).animate({'opacity':0},'fast',function(){
				$(this).css('display','none');
			});
		}
	})
});

// chek for twitter feed
twitInt = setInterval(function(){
	if($('#twitter_update_list').text().length>2){
	
		clearInterval(twitInt)
		
		// setup Twitter bar
		twH = winW - ($('#logo').width()+7);
		if(twH>300){
		$('#twitterBar').css('width',twH);
		$('#twitter_update_list').css('width',twH-165);
		
			if(twH<450){
				$('#twitter_update_list').css('width',twH-80);
				$('#fbook').css('visibility','hidden');
			}
		
		}
		if($('#twitter_update_list').height() <18){
			$('#twitter_update_list').css('margin-top','9px');
		} else {
			$('#twitter_update_list').css('margin-top','3px');
		}
	}
},50)
