var jq = jQuery.noConflict();



jq(document).ready(function(){
	jq("p:last-child").css({ "margin-bottom": "0px"});	
	jq(".post:last-child").addClass("last");	
	jq('body').highlight('I Dig Denim');
	//addGlance();
	fixCaption();
	positionPost();
	dottedBoxWidth();
	slideshow();
	tagPagination();

	//$('.tt-flickr').lightBox({fixedNavigation:true});

});

function fixCaption() {
	jq(".wp-caption").each(function() { 
		jq(".wp-caption-text", this).css({ "margin-top": "-"+jq(".wp-caption-text", this).innerHeight()+"px"});
		jq(".wp-caption-text", this).css({ "opacity": 0.7});
	});
}

function dottedBoxWidth() {
	jq(".dotted").each(function() { 
		jq(this).width(jq(".content .right", this).children().width()+16+"px");
	});	
}

function addGlance() {
	jq(".glance").each(function() { 
		jq(this).parent().append("<div class='glancepicture' style='width: "+jq(this).width()+"px; height: "+jq(this).height()+"px;'></div>");
	});	
}

function positionPost() {
	jq("body.blog .post").each(function() {							 
	
		// jq(".date", this).css({ "margin-top": ""+((jq(this).height() - jq(".date", this).height()) *0.5)+"px"});
		// jq(".collectiontitle", this).css({ "margin-top": ""+((jq(this).height() - jq(".collectiontitle", this).height()) *0.5)+"px"});
		
		if (jq(".grid_4", this)[0]) {
			var margin = 0;
			var blockHeight;
			blockHeight = jq(".grid_4", this).outerHeight(true);

			margin = blockHeight - jq(".social", this).outerHeight(true) - jq("h2", this).outerHeight(true) - jq(".postmetadata", this).outerHeight(true);		
			
			jq(".social", this).css({ "margin-top": ""+Math.abs(margin)+"px"});
		}
		
			
	});
}

function slideshow() {
	jq('#slideshow img:eq(0)').show();
	jq('#slideshow img:gt(0)').hide();
	setInterval( function() {
		jq('#slideshow :first-child').fadeOut(3000)
		.next('img').fadeIn()
		.end().appendTo('#slideshow');
	}, 8000);
}

function tagPagination() {
	var numberOfTags = jq('ul.categories').children().size();
	var numberToShow = 16;
	var numberOfPages = Math.ceil(numberOfTags/numberToShow);
	var current = 0;

	if(numberOfPages > 0){
		var list = '';
			
		for(var i = 0; i < numberOfPages; i++){
			list += '<li id="' + i + '"></li>';
		}
		jq('.categoriesPages').html(list);
		jq('.categoriesPages li').addClass('categoriesPagesBg');
		jq('.categoriesPages li#0').removeClass('categoriesPagesBg').addClass('categoriesPagesBgActive');
		jq('.categoriesPages li').each(function(){
			jq(this).click(function(){
				current = jq(this).attr('id');
				
				var currentNr = '.categoriesPages li.' + current;
				jq('.categoriesPages li').removeClass('categoriesPagesBgActive').addClass('categoriesPagesBg');
				jq(this).removeClass('categoriesPagesBg').addClass('categoriesPagesBgActive');
				jq('ul.categories').animate({
					marginTop: current * -160 +'px'
				}, 200);
			})
		})
	}
}
