/*
Theme Name: JYD
Version: 1.0
Author: <a href="http://www.jyd.at">(c) 2010 JYD</a>
*/

jQuery(document).ready(function fader(){
						   jQuery(".eachpost a img").fadeTo(100, 0.9); // This sets the opacity of the thumbs to fade down to 30% when the page loads
						   jQuery(".eachpost a img").hover(function(){
						   jQuery(this).fadeTo(100, 1.0); // This should set the opacity to 100% on hover
						   },function(){
						   jQuery(this).fadeTo(100, 0.9); // This should set the opacity back to 30% on mouseout
						   });
});

jQuery(document).ready(function(){
						   jQuery("#header img").fadeTo("fast", 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
						   jQuery("#header img").hover(function(){
						   jQuery(this).fadeTo("normal", 0.3); // This should set the opacity to 100% on hover
						   },function(){
						   jQuery(this).fadeTo("normal", 1.0); // This should set the opacity back to 30% on mouseout
						   });
});

					   
						  

	var MIN_COLS = 5;
	var COL_WIDTH = 150;
	var GAP = 10; 
	
	var offx = 0;
	var offy = 0;
	maxy = new Array();
	
	// on site load (DOM READY)
	jQuery(function() { 
		offy = jQuery('#allposts').offset().top;
		offx = jQuery('#allposts').offset().left;
		arrange();
	});
	
	/*
// on window resize, call again
	jQuery(window).resize( function() { arrange(); } );
	
	arrange();
*/
	
	function arrange() {
	
		// how many columns fits here?
		var columns = Math.max(2 , MIN_COLS);
		//var columns = Math.max(MIN_COLS, parseInt(jQuery('body').innerWidth() / (COL_WIDTH+GAP))); */
		jQuery('.eachpost').css('width',COL_WIDTH  + 'px');
		jQuery('.twocols').css('width', COL_WIDTH*2 + GAP  );
		jQuery('.threecols').css('width', COL_WIDTH*3 + GAP*2);

		for (x=0; x < columns; x++) {
			maxy[x] = 0;
		}
		
		// lets iterate over all posts
		jQuery('.eachpost').each(function(i) {

			var pos, cursor, w , altura= 0;
			
			w = (Math.floor(jQuery(this).outerWidth() / COL_WIDTH));
			cursor = 0;

			if (w>1) {
				for (x=0; x < columns-(w-1); x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}
				pos = cursor;
				
				for (var x=0; x<w; x++) {
					altura = Math.max(altura, maxy[pos+x]);
				}
				for (var x=0; x<w; x++) 
					maxy[pos+x] = parseInt(jQuery(this).outerHeight()) + GAP + altura;
					
				jQuery(this).css('left', pos*(COL_WIDTH+GAP) + offx).css('top',altura + offy);
			}
			else {
			
				for (x=0; x < columns; x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}

				jQuery(this).css('left', cursor*(COL_WIDTH+GAP) + offx).css('top',maxy[cursor] + offy);
				maxy[cursor] += jQuery(this).outerHeight() + GAP;
			}
		});
	
		
	}
