/*function prepare_modal_cross () {
	var modal_cross = document.createElement('img');
	modal_cross.id = 'modal_cross';
	modal_cross.src = '/graphics/modal_cross.png';
	modal_cross.style.zIndex = '9999999';
	modal_cross.style.position = 'fixed';
	modal_cross.style.zoom = '1';
	modal_cross.style.right = '0px';
	modal_cross.style.top = '0px';
	modal_cross.style.width = '50px';
	modal_cross.style.height = '50px';
	modal_cross.style.cursor = 'pointer';
	modal_cross.style.display = 'none';
		
	return modal_cross;
}*/


function prepare_modal_back () {
	var modal = document.createElement('div');
	modal.id = 'modal_up';
	modal.style.zIndex = '9999';
	modal.style.position = 'absolute';
	modal.style.zoom = '1';
	modal.style.left = '0px';
	modal.style.top = '0px';
	modal.style.width = $(document).width() + 'px';
	modal.style.height = $(document).height() + 'px';
	$(window).bind('resize', function(){
		$('#modal').width($(document).width());
		$('#modal').height($(document).height());
	});
	modal.style.opacity = '0.90';
	modal.style.filter = 'alpha(opacity = 90)';
	modal.style.backgroundColor = '#ffffff';
//	modal.style.webkitBoxShadow = 'inset 0px 0px 240px #777777';
//	modal.style.MozBoxShadow = 'inset 0px 0px 240px #777777';
//	modal.style.boxShadow = 'inset 0px 0px 480px #777777';
	modal.style.display = 'none';
		
	return modal;
}

function prepare_modal_window_up (width, height, inner_html, shadow, href) {
	var modal_window_up = document.createElement('div');

	modal_window_up.id = 'modal_window_up';
	modal_window_up.style.zIndex = '99999';
	if (navigator.userAgent.toLowerCase().indexOf('msie') > -1) {
		modal_window_up.style.position = 'absolute';
	} else {
		modal_window_up.style.position = 'fixed';
	}
	modal_window_up.style.left = '50%';
	modal_window_up.style.marginLeft = '-' + Math.floor(width / 2) + 'px';
	modal_window_up.style.top = 225 + 'px';
	modal_window_up.style.width = width + 'px';
	modal_window_up.style.height = height + 'px';
	if (href != '') {
		modal_window_up.style.cursor = 'pointer';
	}
	modal_window_up.href = href;
	if (shadow != false) {
		modal_window_up.style.backgroundColor = '#fff';
		modal_window_up.style.webkitBoxShadow = '0px 0px 6px #999999';
		modal_window_up.style.MozBoxShadow = '0px 0px 6px #999999';
		modal_window_up.style.boxShadow = '0px 0px 12px #999999';
		if (navigator.userAgent.toLowerCase().indexOf('msie') > -1) {
			modal_window_up.style.border = '3px solid #bbbbbb';
		}
	}
	//modal_window_up.style.webkitBorderRadius = '10px';
	//modal_window_up.style.MozBorderRadius = '10px';
	//modal_window_up.style.borderRadius = '10px';
	modal_window_up.style.display = 'none';

	modal_window_up.innerHTML = inner_html;

	return modal_window_up;
}

function remove_modal_layout () {
	if (navigator.userAgent.toLowerCase().indexOf('msie') > -1) {
		$('#modal_window_up').animate({'top': '120px'}, 200, function () {
			$('#modal_up').animate({'opacity': '0.0'}, 300, function () {
			    $('#modal_up').remove();
			});
			$('#modal_window_up').remove();
		});
	} else {
		$('#modal_window_up').animate({'opacity': '0.0', 'top': '120px'}, 200, function () {
			$('#modal_up').animate({'opacity': '0.0'}, 300, function () {
			    $('#modal_up').remove();
			});
			$('#modal_window_up').remove();
		});
	}
}

function prepare_modal_layout (width, height, inner_html, shadow, href) {
	var _body = document.getElementsByTagName('body')[0];
		
	var modal = prepare_modal_back();
	var modal_window_up = prepare_modal_window_up(width, height, inner_html, shadow, href);

	_body.appendChild(modal_window_up);
	_body.appendChild(modal);
		
	$(modal).click(function(){
		remove_modal_layout();
	});

	
/*	if (href != '') {
		$(modal_window_up).click(function(){
			location.href = $(modal_window_up)[0].href;
			return false;
		});
	} else {
		$(modal_window_up).click(function(){
			remove_modal_layout();
		});
	}
	*/
	
	document.onkeydown = NavigateThrough;
	function NavigateThrough (event) {
		if (!document.getElementById) return;
		if (window.event) event = window.event;
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
			case 0x1b: //Esc
				if ($('#modal_window_up').length > 0) {
					remove_modal_layout();
				}
			break;
		}
	}


	$(modal).show();
	$(modal).css({'opacity': '0.0'});
	$(modal).animate({'opacity': '0.85'}, 200, function () {
		$(modal_window_up).show();
		if (navigator.userAgent.toLowerCase().indexOf('msie') > -1) {
			$(modal_window_up).css({'top': '80px'});
			$(modal_window_up).animate({'top': '225px'}, 300);
		} else {
			$(modal_window_up).css({'opacity': '0.0', 'top': '80px'});
			$(modal_window_up).animate({'opacity': '1.0', 'top': '225px'}, 300);
		}
	});
}

