
		
	

jQuery(document).load(function() {
	jQuery('.wrap').masonry();
});



jQuery(window).resize(function() {
	jQuery('.wrap').masonry();
});





jQuery('document').ready( function() {
	//console.log('ready.');




//jQuery(document).load(function() {
//	jQuery('.wrap').masonry();

if (jQuery('#curtain').length > 0) {

//	console.log('window width: ', jQuery(window).width());

//	console.log('pW width: ', jQuery('.postWrapper').width());
	
/*	
	var widest_img = 0;
		
	jQuery('.postWrapper img').each( function() {
		if (jQuery(this).width() > widest_img) {
			widest_img = jQuery(this).width();
		}
	});
	
	if (widest_img < (jQuery(window).width()/3)) {
		//console.log('ur widest_img is puny');
		widest_img = (jQuery(window).width()/3);
	} else if (widest_img > (jQuery(window).width()/2)) {
		//console.log('ur widest_img is huge');
		widest_img = (jQuery(window).width()/2);
	}

*/


// breadcrumbs
if (jQuery('.current_page_item').length > 0) {
	var current_page_item_title = jQuery('.current_page_item').children('a').text();
	jQuery('.current_page_item').children('a').html('&middot;'+' '+current_page_item_title);
}

if (jQuery('.current_page_parent').length > 0) {
	var current_page_parent_title = jQuery('.current_page_parent').children('a').text();
	jQuery('.current_page_parent').children('a').html('&middot;'+' '+current_page_parent_title);
}



if (jQuery('#pagination').html()) {
	jQuery('ul#nav').after('<ul id="headerpagination">' + jQuery('#pagination').html() + "</ul>");
}
	

	// rezise images if they're too big OR window's too small
	var possible_new_img_width = jQuery(window).width();
//	console.log('possible_new_img_width: ', possible_new_img_width);
	if (possible_new_img_width <= 850 && possible_new_img_width > 640) {
//		console.log('1st');
		var new_img_width = ((jQuery(window).width()-42)/3);
	} else if (possible_new_img_width <= 640 && possible_new_img_width > 430) {
//		console.log('2nd');
		var new_img_width = ((jQuery(window).width()-32)/2);
	} else if (possible_new_img_width <= 430) {
//		console.log('3rd');
		var new_img_width = 200;
	} else {
//		console.log('4th');
		var new_img_width = ((jQuery(window).width()-52)/4);
	}
	
	new_img_width = 324;
	
	var new_img_height;
	jQuery('ol#posts img').each( function() {
			if (jQuery(this).width() > new_img_width) {
				new_img_height = ((new_img_width / jQuery(this).width()) * jQuery(this).height());
				jQuery(this).css({'width':new_img_width,'height':new_img_height});
			}
	});
	jQuery('li.postWrapper').css({'width':(new_img_width+10), 'height':'217px'});


/*
	jQuery('.post').each( function() {
//		var imgcount = 0;
//		jQuery(this).children('.post').each( function() {
		var imgcount = jQuery(this).find('a').length;
//			imgcount++;
//		});
		if (imgcount > 1) {
			jQuery(this).siblings('.postTitle').children('.imgcounter').text('1 of '+imgcount);
		}
	});
*/


/*

	jQuery('.postWrapper').css({'width':widest_img});
	jQuery('.commentsWrapper, .commentsWrapper textarea').css({'width':widest_img});
	
	//console.log('window width: ', jQuery(window).width());

	//console.log('new pW width: ', jQuery('.postWrapper').width());	
	
	jQuery('.postWrapper').css({'margin-left':((((jQuery(window).width())/2)-(jQuery('.postWrapper').width()/2)))});
	
	if (jQuery('.commentsWrapper').length > 0) {
		jQuery('.commentsWrapper').css({'margin-left':((((jQuery(window).width())/2)-(jQuery('.postWrapper').width()/2)))});
	}
	

	//hover photo fade - maybe animate this?
	jQuery('div.post * img').hover(
		function(){jQuery(this).css({'opacity': '0.5'})},
		function(){jQuery(this).css({'opacity': '1'})}
	);
	
*/

/*
	jQuery('img').each( function() {
		jQuery(this).after("<br/>");
	});
*/	
	




//console.log(jQuery('#categories-block li').height(), jQuery('#links-block li').height());
jQuery('#categories-block strong').css({'height':jQuery('#categories-block li').height()});
jQuery('#links-block strong').css({'height':jQuery('#links-block li').height()});


	// just for the vars
	var new_height = 250;
	var slideshowpos = ((jQuery(window).height()/2)-(new_height/2));
	
	if (slideshowpos < 50) {
		slideshowpos = 50;
	}

	// layout
	// if is_single()
	if (jQuery('.singlePostWrapper').length > 0) {
	var greatest_width = 0;
		if (jQuery('.singlePostWrapper').find('img, embed').length > 0) {
			jQuery('.singlePostWrapper').find('img, embed').each( function() {
				if (jQuery(this).width() > greatest_width) {
					greatest_width = jQuery(this).width();
				}
			});
			if (greatest_width > jQuery(window).width()) {
				greatest_width = (jQuery(window).width()/2);
				jQuery('.singlePostWrapper').find('img, embed').each( function() {
					if (jQuery(this).width() > greatest_width) {
						var great_new_height = ((greatest_width / jQuery(this).width()) * jQuery(this).height());
						jQuery(this).css({'width':greatest_width,'height':great_new_height});
					}
				});
			}
		} else {
			if (jQuery(window).width() < 400) {
				greatest_width = jQuery(window).width();
			} else if ((jQuery(window).width() >= 400) && (jQuery(window).width() < 1200)) {
				greatest_width = (jQuery(window).width()/2);
			} else if (jQuery(window).width() >= 1200) {
				greatest_width = (jQuery(window).width()/3);
			}
		}
		jQuery('.singlePost').css({'width':greatest_width});
		jQuery('.singlePost, .commentsWrapper').css({'margin-left':((jQuery(window).width()/2)-((greatest_width)/2))});
		if (jQuery('.singlePostTitle span').width() < jQuery(window).width()) {
			jQuery('.singlePostTitle span').css({'margin-left':((jQuery(window).width()/2)-(jQuery('.singlePostTitle span').width()/2))});
		}
	}



		jQuery('.wrap').masonry({ columnWidth: new_img_width });


	jQuery('span#loading_gif').hide();
	
	
	
jQuery('#curtain').css({'display':'none'});
//console.log('curtain is up');

}





	jQuery('div.post * img').mouseenter( function() {
		jQuery(this).css({'opacity':'0.5'});
		jQuery(this).parents('.post').siblings('.postTitle').attr({'height':(jQuery(this).height()-20),'width':(jQuery(this).width()-20)});
		jQuery(this).parents('.post').siblings('.postTitle').show();
	});
	jQuery('div.post * img').mouseleave(	function() {
		jQuery(this).parents('.post').siblings('.postTitle').hide();
		jQuery(this).css({'opacity': '1'});
	});
	





/*


	//scroll perfect	
		var destination = jQuery('div.post * img:first');
		var hovering_next = 0;
		var hovering_previous = 0;
		var destinationfirstimg = jQuery('ol#posts * img:first').width() + 10;
		var scrollpreviouspos;
		var scrollnextpos;
		
//		jQuery('div#buttons #previous').css({'opacity':'0.25'});
		
		function scrollpreviouscheck() {
			if ((destination).parent().parent().parent('li.postWrapper').prev().prev().prev().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').prev().prev().prev().children().children().children('img');
				scrollprevious();
			} else if ((destination).parent().parent().parent('li.postWrapper').prev().prev().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').prev().prev().children().children().children('img');
				scrollprevious();
			} else if ((destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img');
				scrollprevious();
			} else {
				destination = destination;
			}
		}
		
		function scrollnextcheck() {	
			if ((destination).parent().parent().parent('li.postWrapper').next().next().next().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').next().next().next().children().children().children('img');
				scrollnext();
			} else if ((destination).parent().parent().parent('li.postWrapper').next().next().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').next().next().children().children().children('img');
				scrollnext();
			} else if ((destination).parent().parent().parent('li.postWrapper').next().children().children().children('img').length > 0) {
				destination = (destination).parent().parent().parent('li.postWrapper').next().children().children().children('img');
				scrollnext();
			} else {
				destination = destination;
			}
		}
		
		function scrollprevious() {						
							jQuery('.slideshow').scrollTo(destination, 350, {easing:'linear'});
							scrollpreviouspos = parseInt(jQuery('ol#posts').css('width')) - parseInt(jQuery('div.slideshow').scrollLeft());
								if (scrollpreviouspos <= parseInt(jQuery('div.slideshow').css('width'))) {
									jQuery('div#buttons #next').css({'opacity':'0.25'});
									jQuery('div#buttons #previous').css({'opacity':'1'});
								} else if (parseInt(jQuery('div.slideshow').scrollLeft()) <= destinationfirstimg) { 
									jQuery('div#buttons #previous').css({'opacity':'0.25'});
									jQuery('div#buttons #next').css({'opacity':'1'});								
								} else {
									jQuery('div#buttons #previous').css({'opacity':'1'});
									jQuery('div#buttons #next').css({'opacity':'1'});
								}
		}

		function scrollnext() {			
						jQuery('.slideshow').scrollTo(destination, 350, {easing:'linear'});
						scrollnextpos = parseInt(jQuery('ol#posts').css('width')) - parseInt(jQuery('div.slideshow').scrollLeft());
								if (scrollnextpos <= parseInt(jQuery('div.slideshow').css('width'))) {
									jQuery('div#buttons #next').css({'opacity':'0.25'});
									jQuery('div#buttons #previous').css({'opacity':'1'});
								} else {
									jQuery('div#buttons #previous').css({'opacity':'1'});
									jQuery('div#buttons #next').css({'opacity':'1'});
								}
		}
		


//MOUSE WHEEL SCROLL

				jQuery('.slideshow').mousewheel(function(event, delta) {
						if (delta > 0) {

						if ((destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img').length > 0) {
							destination = (destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img');
							jQuery('.slideshow').scrollTo(destination, 50, {easing:'linear'});
							scrollpreviouspos = parseInt(jQuery('ol#posts').css('width')) - parseInt(jQuery('div.slideshow').scrollLeft());
								if (scrollpreviouspos <= parseInt(jQuery('div.slideshow').css('width'))) {
									jQuery('div#buttons #next').css({'opacity':'0.25'});
									jQuery('div#buttons #previous').css({'opacity':'1'});
								} else if (destination.attr('src') == jQuery('ol#posts * img:first').attr('src')) { 
									jQuery('div#buttons #previous').css({'opacity':'0.25'});
									jQuery('div#buttons #next').css({'opacity':'1'});
								} else {
									jQuery('div#buttons #previous').css({'opacity':'1'});
									jQuery('div#buttons #next').css({'opacity':'1'});
								}
						} else {
							destination = destination;
						}

						} else if (delta < 0) {
						
						if ((destination).parent().parent().parent('li.postWrapper').next().children().children().children('img').length > 0) {
							destination = (destination).parent().parent().parent('li.postWrapper').next().children().children().children('img');
						jQuery('.slideshow').scrollTo(destination, 50, {easing:'linear'});
							scrollnextpos = parseInt(jQuery('ol#posts').css('width')) - parseInt(jQuery('div.slideshow').scrollLeft());
								if (destination.attr('src') == jQuery('ol#posts * img:last').attr('src')) {
									jQuery('div#buttons #next').css({'opacity':'0.25'});
									jQuery('div#buttons #previous').css({'opacity':'1'});
								} else {
									jQuery('div#buttons #previous').css({'opacity':'1'});
									jQuery('div#buttons #next').css({'opacity':'1'});
								}
						} else {
							destination = destination;
						}
	  		
						}

						event.stopPropagation();
						event.preventDefault();
					});



	
		jQuery('#buttons a#previous').mousedown(function(){
			scrollpreviouscheck();
		});

		jQuery('#buttons a#next').mousedown(function(){
			scrollnextcheck();
		});		




*/

		jQuery('a#shadowbox_nav_moreinfo').attr({'href':jQuery(post_in_question).find('.permalink_span').text()});
		jQuery('a#shadowbox_nav_moreinfo').text('VIEW POST');
		jQuery('a#shadowbox_nav_moreinfo').show();
	
	var img_in_question;
	
	var post_in_question;
	
	var poppedup = 0;
	
		function dealwithcaption() {
			jQuery('div.popup_main').hide();	
			
			jQuery('a#shadowbox_nav_moreinfo').css({'width':'6em', 'margin-top':'0.15em'});

		jQuery('a#shadowbox_nav_moreinfo').attr({'href':jQuery(post_in_question).find('.permalink_span').text()});
		jQuery('a#shadowbox_nav_moreinfo').text('VIEW POST');
				jQuery('a#shadowbox_nav_moreinfo').show();		
//		console.log('img class: ',imgclass);
				if (imgclass == "mov") {
					jQuery('div.popup_main').html((img_in_question).parent().next('.caption').html()+"<a id=\"closeinfo\" title=\"Close Info\">"+jQuery('span#closeinfo_standby').html()+"</a>");
//		console.log('oh, I see');
				} else {
//		console.log('attr title: ', (img_in_question).parent().attr('title'));
					jQuery('div.popup_main').html("<h1>"+(img_in_question).parent().attr('title')+"</h1>\n"+(img_in_question).parent().next('.caption').html()+"<a id=\"closeinfo\" title=\"Close Info\">"+jQuery('span#closeinfo_standby').html()+"</a>");
				}
//				moreinfobutton();						

			return false;
		}


		
	
  
/*    
    function moreinfobutton() {
		jQuery('a#shadowbox_nav_moreinfo').click( function() {
//console.log('popup htmls: ', jQuery('div.popup_main').html());
			if (imgclass == "mov") {
				if (poppedup == 1) {
    				jQuery('div.popup_main').hide();
    				poppedup = 0;
    				jQuery('#shadowbox_body_inner').show();
    			} else if (poppedup == 0) {
    				jQuery('div.popup_main').css({'top':jQuery('#shadowbox').position().top+50, 'left':jQuery('#shadowbox').position().left+50, 'width':(jQuery('#shadowbox').width()-110), 'height':(jQuery('#shadowbox').height()-110)});
    				jQuery('#shadowbox_body_inner').hide();
					jQuery('div.popup_main').show();
					poppedup = 1;			
				}
			} else {
    			if (poppedup == 1) {
    				jQuery('div.popup_main').hide();
    				poppedup = 0;
    			} else if (poppedup == 0) {
 	   				jQuery('div.popup_main').css({'top':jQuery('#shadowbox').position().top+50, 'left':jQuery('#shadowbox').position().left+50, 'width':(jQuery('#shadowbox').width()-110), 'height':(jQuery('#shadowbox').height()-110)});
					jQuery('div.popup_main').show();
					poppedup = 1;			
    			} else {
    			} 
    		}
	    });
	    return false;
	}
*/

var imgclass;
	
//pop-up caption pops up, buttons disappear
jQuery('div.post * img').click(function() {				
		img_in_question = jQuery(this);
		post_in_question = jQuery(this).parents('.postWrapper');
//	console.log(img_in_question);
		imgclass = (img_in_question).attr("class");
//		console.log('img class', imgclass);

			jQuery('#shadowbox_title').hide();

		dealwithcaption();
		jQuery('#shadowbox_nav').css({'top':(slideshowpos+new_height+15)});
		jQuery('div#buttons').css({'display':'none'});		
		    	
		    		
	//navigate previous	and main 'slider' scrolls
		jQuery('a#shadowbox_nav_previous').click( function() { 
			jQuery('#shadowbox_body_inner').show();
				if ((img_in_question).parent('a').prev('a').children('img').length > 0) {
					img_in_question = (img_in_question).parent('a').prev('a').children('img');				
				} else if ((img_in_question).parent('a').prev('.caption').prev('a').children('img').length > 0) {
					img_in_question = (img_in_question).parent('a').prev('.caption').prev('a').children('img');
//		console.log(img_in_question);
					imgclass = (img_in_question).attr("class");
//		console.log('img class', imgclass);
					if (imgclass == "img") {
						jQuery('#shadowbox_title').hide();
					}
					poppedup = 0;		
					jQuery('div.popup_main').hide();
					jQuery('a#shadowbox_nav_moreinfo').unbind('click');
					dealwithcaption();

				}
				return false;
    	});
    	   	
    	   	
	//navigate next	and main 'slider' scrolls
		jQuery('a#shadowbox_nav_next').click( function() { 
			jQuery('#shadowbox_body_inner').show();
				if ((img_in_question).parent('a').next('a').children('img').length > 0) {
					img_in_question = (img_in_question).parent('a').next('a').children('img');				
				} else if ((img_in_question).parent('a').next('.caption').next('a').children('img').length > 0) {
					img_in_question = (img_in_question).parent('a').next('.caption').next('a').children('img');
//		console.log(img_in_question);
					imgclass = (img_in_question).attr("class");
//		console.log('img class', imgclass);
					if (imgclass == "img") {
						jQuery('#shadowbox_title').hide();
					}
					poppedup = 0;
					jQuery('div.popup_main').hide();
					jQuery('a#shadowbox_nav_moreinfo').unbind('click');
					dealwithcaption();

				}
				return false;
    	});   	



// KEYBOARD FUN

jQuery(document).keydown(function(e) {
	switch(e.keyCode) { 
    	// User pressed left arrow
        case 37:
			jQuery('a#shadowbox_nav_previous').click();
        break;
        // User pressed right arrow
        case 39:
            jQuery('a#shadowbox_nav_next').click();
        break;
	}
	return false;
});



	// 'CLOSE INFO' BUTTON CLOSES INFO, DUH!
			jQuery('a#closeinfo img').livequery ('click', function() {
			if (jQuery('#shadowbox_body').children().children('img').length == 0) {
    				jQuery('div.popup_main').hide();
    				poppedup = 0;
    				jQuery('#shadowbox_body_inner').show();
			} else {
    				jQuery('div.popup_main').hide();
    				poppedup = 0;
    		}
	    	});

	


					
	// CLOSE: HIDE CAPTION AND BUTTON, SHOW REGULAR BUTTONS	
		jQuery('a#shadowbox_nav_close, div#shadowbox_overlay').click( function() { 
			poppedup = 0;
			jQuery('#shadowbox_body_inner').show();
			jQuery('div.popup_main').hide();
			jQuery('a#shadowbox_nav_moreinfo').hide();
//			jQuery('div#buttons').css({'display':'block'});
			jQuery('a#shadowbox_nav_moreinfo').unbind('click');
			jQuery('a#shadowbox_nav_close, div#shadowbox_overlay').unbind('click');
			jQuery('a#shadowbox_nav_previous').unbind('click');
			jQuery('a#shadowbox_nav_next').unbind('click');
			jQuery(document).unbind('keydown');
		    return false;
    	});
});


/*
// SHADOWBOX MODE NEXT/PREV IMG SCROLLS MAIN DISPLAY

//	jQuery('a#shadowbox_nav_previous').livequery('click', function() { 
	function shadowboxmodescrollprevious() {
//		console.log('destination: ', destination);
		if ((destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img').length > 0) {
			destination = (destination).parent().parent().parent('li.postWrapper').prev().children().children().children('img');
			scrollprevious();
		} else {
			destination = destination;
		}
		return false;
	}	
//	});

//	jQuery('a#shadowbox_nav_next').livequery('click', function() { 
	function shadowboxmodescrollnext() {
//		console.log('destination: ', destination);
		if ((destination).parent().parent().parent('li.postWrapper').next().children().children().children('img').length > 0) {
			destination = (destination).parent().parent().parent('li.postWrapper').next().children().children().children('img');
			scrollnext();
		} else {
			destination = destination;
		}
		return false;
	}
//	});
*/



// IN SHADOWBOX MODE
// CLICK IMG TO VIEW NEXT 
// OR CLICK MOV TO HIDE POP-UP CAPTIONS AND PLAY MOV


jQuery('#shadowbox_body').livequery('click', function() {
	if (jQuery(this).children().children('img').length > 0) {
		jQuery('a#shadowbox_nav_next').click();
	} else if (poppedup == 1) {
 		jQuery('div.popup_main').hide();
  		poppedup = 0;
    	jQuery('#shadowbox_body_inner').show();
	}
});





// dev output
	//console.log('total_width: ', total_width);


});
