
function adjustImages(cols_min, cols_max) {
    $('.item').removeClass('clear').removeClass('last');
    min = cols_min-1;
    max = cols_max-1;

    offset = 0;

    windowWidth = $(window).width() - 20 - 15;

    var iterator = 0;
    while (offset < images.length) {
	dx = 0;
	i = 0;

	while ( (dx) <= windowWidth && i <= max && (offset + i) < images.length) {
	    dx += parseInt( images[offset + i] );
	    i++;
	}

	actualWindowWidth = windowWidth - (i * 20);
	var sum=0;

	for (var j=0; j < i; j++) {
	    var w;

//	    if (offset == images.length - 1 && actualWindowWidth > 2 * dx) {
////		actualWindowWidth = actualWindowWidth / 2;
//		actualWindowWidth = Math.floor( parseInt(images[offset + j]) ) ;
//		alert('test');
//	    }
	    if (offset == images.length - 1) {
		actualWindowWidth = Math.min(Math.floor( parseInt(images[offset + j]) ), actualWindowWidth );
	    }

	    var margin = 0;

	    w = Math.floor( ( parseInt(images[offset + j]) + margin ) * actualWindowWidth / dx );

	    sum += w;

	    $element = $('.item:eq('+ (offset + j) +')');
	    $element.css('width', w+'px');
	    $element.find('img').css('width', w+'px');

	    if (j == 0) {
		$element.addClass('clear');
	    }

	    if (j == i-1) {
		$element.addClass('last');
	    }

	}

	offset += i;
	iterator++;
    }

}

$(window).load(function(){
    var cy = Math.round(Math.random() * $(document).height());
    var cx = Math.round(Math.random() * $(document).width());
    $('#circle')
	.css('left', '' + cx + 'px')
	.css('top', '' + cy + 'px' )
	.show()
	.click(
	    function() {
		$(this).hide();
	    }
	)
});

function isScrollbar() {
  var docHeight = $(document).height();
  var scroll    = $(window).height() + $(window).scrollTop();
  return (docHeight == scroll);
}

