function ShowVideoDialog ( id )
{
    var pos = GenPopupPos ( 487, 275 );
    
    HideMediaDialogs();
    $( 'body' ).append ( '<div id="photo_bg"></div>' );
	
    $( '#photo_bg' ).css ( { height: GetYScroll() + 'px', opacity: 0.8 } );
    $( 'body' ).append ( '<div id="media_dialog_container"><img src="/images/najax_load.gif" width="32" height="32" class="media_dialog_li" /></div>' );
    $( '#media_dialog_container' )
        .css ( { top: pos.top + 'px',
                 left: pos.left + 'px' } );

	var data = {
		id: id
	}
	
	client_request ( 'places', 'get_video_dialog', '', 'GET', data, 'AfterShowVideoDialog' );
}

function AfterShowVideoDialog ( data )
{
	$( '#media_dialog_container' ).html ( data.content );
}

function Show3DDialog ( id )
{
    //$().scroll ( return false );
    
    var pos = GenPopupPos ( 487, 275 );
    
    HideMediaDialogs();
    $( 'body' ).append ( '<div id="photo_bg"></div>' );
	
    $( '#photo_bg' ).css ( { height: GetYScroll() + 'px', opacity: 0.8 } );
    $( 'body' ).append ( '<div id="media_dialog_container"><img src="/images/najax_load.gif" width="32" height="32" class="media_dialog_li" /></div>' );
    $( '#media_dialog_container' )
        .css ( { top: pos.top + 'px',
                 left: pos.left + 'px' } );

	var data = {
		id: id
	}
	
	client_request ( 'places', 'get_3d_dialog', '', 'GET', data, 'AfterShow3DDialog' );
}

function AfterShow3DDialog ( data )
{
	$( '#media_dialog_container' ).html ( data.content );
}

function Show3D ( file )
{
    $( 'div.place_3d' ).html ( '<div id="place_3d"></div><span>Вращайте панораму, удерживая левую кнопку мыши</span>' );
    swfobject.embedSWF ( file, "place_3d", "640", "480", "9.0.0" );
}

function ShowVideo ( file )
{
    $( 'div.place_video' ).html ( '<div id="place_video"></div>' );
    swfobject.embedSWF ( "/images/my_flv_player.swf?file=" + file, "place_video", "446", "364", "9.0.0" );
}

function ShowPhotoDialog ( place )
{
    var pos = GenPopupPos ( 487, 275 );
    
    HideMediaDialogs();
    $( 'body' ).append ( '<div id="photo_bg"></div>' );
	
    $( '#photo_bg' ).css ( { height: GetYScroll() + 'px', opacity: 0.8 } );
    $( 'body' ).append ( '<div id="photo_dialog_container"><div id="popup_ph_indicator">Идет загрузка...</div></div>' );
    $( '#photo_dialog_container' )
        .css ( { top: pos.top + 'px',
                 left: pos.left + 'px' } );

	var data = {
		place: place
	}
	
	client_request ( 'places', 'get_photo_dialog', '', 'GET', data, 'AfterShowPhotoDialog' );
}

function AfterShowPhotoDialog ( data )
{
	$( '#photo_dialog_container' ).html ( data.content );
	ShowPPhoto ( null, null, data.place );
}

function HideMediaDialogs ()
{
    //$().scroll ();
    
    $( '#op_bg' ).remove();
    $( '#photo_bg' ).remove();
    $( '#media_dialog_container' ).remove();
    $( '#media_dialog_container' ).remove();
    $( '#photo_dialog_container' ).remove();
}

function HidePhoto ()
{
    $( '#photo_bg' ).remove();
    $( '#photo_dialog_container' ).remove();
}

function HideVideo ()
{
    $( '#photo_bg' ).remove();
    $( '#media_dialog_container' ).remove();
}

function ShowPPhoto ( file, id, place )
{
    var next;
    var next_id;
    
    if ( !id )
    {
        id = $( 'td.photos_small_thumbnails > div:first' );
        id = id.attr ( 'id' );
        id = id.replace ( 'thumbnail_', '' );
    }

    if ( !file )
    {
        file = '/pic/places/' + place + '/' + id + '.jpg';
    }
    
    next = $( '#thumbnail_' + id + ' + div' );
    
    if ( next.length == 0 )
    {
        next = $( 'td.photos_small_thumbnails > div:first' );
        next_id = next.attr ( 'id' );
        next_id = next_id.replace ( 'thumbnail_', '' );
    } else {
        next_id = next.attr ( 'id' );
        next_id = next_id.replace ( 'thumbnail_', '' );
    }
    
    $( '#big_photo' )
        .find ( 'td' )
        .html ( '<img src="/images/ajax2.gif" width="32" height="32" id="ph_ai" />' );
        
    var img = new Image();
    
    img.onload = function () {
        $( '#ph_ai' ).remove();
        $( this ).animate ( { opacity: 'show' }, 330 );
    }
    
    $( '#big_photo' )
        .find ( 'td' )
        .append ( img );
    
    img.src = file;
    $( img ).bind ( 'click', function () {
        ShowPPhoto ( '/pic/places/' + place + '/' + next_id + '.jpg', next_id, place );
    } );
}