/**
 * @author Bjoern R. Salgert
 * @date 30.08.2009
 */

/**
 * 
 * @param {Object} value
 */ 
function isset(value) {
	return (value != null) && (value != undefined);
}
function getRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
	return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}
function getHeight(selfHeight) {
	var h = $(document).height();
	return getRandom(0, h - selfHeight);
}
function getWidth(selfWidth) {
	var w = $(document).width();
	return getRandom(0, w - selfWidth);
}
function createBox(id, item) {
	var content = '<div class="mover"></div>';
	content += '<a class="title" href="'+item.url+'">'+item.title+'</a>'; 
	if (isset(item.description)) {
		content += '<div class="description">' + item.description + '</div>'; 
	}
	content += '<a class="link" href="'+item.url+'">[ GO ]</a>'; 
	$("#insert").after("<div class=\"box\" id=\""+id+"\">"+content+"</div>");
	$("#"+id).draggable({handle: '.mover'});
	$("#"+id).hide();
	$("#"+id).show("slow", function() {
		$("#"+id).animate({top:getHeight(250),left:getWidth(300)}, 1000);
	});
}