gCursorX=0;
gCursorY=0;
needClose=0;
wndOpen=0;

jQuery('document').ready(function(){
    jQuery('body').append("<table id=\"modal_wnd\" cellpadding=0 cellspacing=0 style='z-index:9999'><tr><td><img src='pics/corner_left_top.png'><td style='background:url(pics/side_top.png)'><td><img src='pics/corner_right_top.png'><tr><td style='background:url(pics/side_left.png)'><td class=\"back\" align=right><a href='javascript:closeModalWnd();'><img src='pics/b_drop.png'></a><div  id=\"sbody_inner\"></div><td style='background:url(pics/side_right.png)'><tr><td><img src='pics/corner_left_bottom.png'><td  style='background:url(pics/side_bottom.png)'><td><img src='pics/corner_right_bottom.png'></table>");
    
    jQuery('body').mousemove(function(ev){
        gCursorX=ev.pageX;
        gCursorY=ev.pageY;
    });
    
    jQuery('body').click(function(ev){
        if(wndOpen==1){
            needClose=1;
            setTimeout(checkCloseWnd,500);
        } 
        
    });
    
    jQuery('#modal_wnd').click(function(ev){
        setTimeout('needClose=0',5);
    });
});
function showModalWnd(Sbody){
    jQuery('#sbody_inner').html(Sbody);
    $('sbody_inner').innerHTML=Sbody;
    
    setTimeout('needClose=0',5);
    scrollTop=jQuery("html").scrollTop();
    
    tw=parseInt(document.body.clientWidth);
    th=parseInt(document.body.clientHeight);
    
    tx =tw/2-jQuery('#modal_wnd').width()/2;
    tx=parseInt(tx);
    ty=gCursorY-200;
    
    /*alert(tx);
    alert(jQuery('#modal_wnd').width());
    alert(tw);*/

	while (Sbody.indexOf("{quot}")>=0){
		Sbody=Sbody.replace("{quot}","'");	
	}

    jQuery('#modal_wnd').animate({left:gCursorX-100,top:gCursorY},0);
    jQuery('#modal_wnd').animate({left: tx,top:ty},700);
    jQuery('#modal_wnd').css('visibility','visible');
    
    setTimeout('wndOpen=1',700);
    
	return false;
}


function closeModalWnd(){
	jQuery('#modal_wnd').animate({top:-900,left:-500},1000);
    setTimeout("jQuery('#modal_wnd').css('visibility','hidden')",1000);
    wndOpen=0;
}

function checkCloseWnd(){
    if(needClose){
        closeModalWnd();
    }
}
