function add_event(obj, handle, lstnr) {
	try {
		obj.addEventListener(handle, lstnr, false);
	} catch(e) {
		obj.attachEvent("on"+handle, lstnr);
	}
}

// add_event( window, 'load' , set_tag_paper );
$(document).ready( function () {
	$('#content_menu').width( getBrowserWidth()-330 );
} );

function getBrowserWidth() {
	if ( window.innerWidth ) { return window.innerWidth; }
	else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }
	else if ( document.body ) { return document.body.clientWidth; }
	return 0;
}

function getBrowserHeight() {
	if ( window.innerHeight ) { return window.innerHeight; }
	else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }
	else if ( document.body ) { return document.body.clientHeight; }
	return 0;
}

function set_tag_paper( e ) {
	var width = getBrowserWidth()-800;
	var height = getBrowserHeight()-300;
	var divElm = document.getElementsByTagName( 'div' );
	var tag = new Array();
	var xpos = new Array();
	var ypos = new Array();
	minx = width;
	miny = height;
	maxx = 0;
	maxy = 0;
	for ( i=0, j=0 ;  i < divElm.length; i++ ) {
		if ( divElm[i].id.indexOf('tag_') == 0 ) {
			tag[j] = divElm[i];
			xpos[j] = Math.floor(Math.random()*width);
			ypos[j] = Math.floor(Math.random()*height);
			minx = Math.min(minx, xpos[j]);
			maxx = Math.max(maxx, xpos[j]);
			miny = Math.min(miny, ypos[j]);
			maxy = Math.max(maxy, ypos[j]);
			j++;
		}
	}
	for ( i=0; i < tag.length; i++ ) {
		if (xpos[i] == minx)
			tag[i].style.left = (xpos[i]/3)+'pt';
		else if (xpos[i] == maxx)
			tag[i].style.left = (width-Math.floor(xpos[i]/7))+'pt';
		else if ( ( xpos[i]-minx ) < 50 )
			tag[i].style.left = (xpos[i]+50)+'pt';
		else if ( ( maxx-xpos[i] ) < 50 )
			tag[i].style.left = (xpos[i]-50)+'pt';
		else
			tag[i].style.left = xpos[i]+'pt';
		if (ypos[i] == miny)
			tag[i].style.top = (ypos[i]/3)+'pt';
		else if (ypos[i] == maxy)
			tag[i].style.top = (height-Math.floor(ypos[i]/7))+'pt';
		else if ( ( ypos[i]-miny ) < 30 )
			tag[i].style.top = (ypos[i]+30)+'pt';
		else if ( ( maxy-ypos[i] ) < 30 )
			tag[i].style.top = (ypos[i]-30)+'pt';
		else
			tag[i].style.top = ypos[i]+'pt';
		tag[i].style.display = 'block';
	}
}

