var gallery;



function change_image (id, image)
{
    var image_dir = '/images/';
    
    var get_image = new Image();
    get_image.src = image_dir + image;

    document.images[id].src = image_dir + image + '?rnd='+Math.random();
}




function show_hide_layer (id, action)
{
    if (action == "show")
    {
        document.getElementById(id).style.display = 'block';
        document.getElementById(id).style.visibility = 'visible';
    }
    else if (action == "hide")
    {
        document.getElementById(id).style.display = 'none';
        document.getElementById(id).style.visibility = 'hidden';
    }
    else if ( document.getElementById(id) )
    {
        if ( document.getElementById(id).style.display == 'none' ) 
        {
            show_hide_layer( id, "show" );
        }
        else
        {
            show_hide_layer( id, "hide" );
        }
    }
}



function gallery_scroll ( gallery_id )
{
    if( !gallery_id ) gallery_id = 45;
    
    getContent( 'simple_gallery/' + gallery_id, '', 'get', 'gallery_container' );
}



function switch_gallery ( gallery_id )
{
    if ( gallery_id == 45 || gallery_id == 46 || gallery_id == 47 )
    {
        if ( gallery_id == 45 )
        {
            document.images['index_screenshottab'].src = "/images/simple/index_screenshottab_over.jpg";
            document.images['index_graphicstab'].src = "/images/simple/index_graphicstab.jpg";
            document.images['index_wallpapertab'].src = "/images/simple/index_wallpapertab.jpg";
        }
        else if ( gallery_id == 46 )
        {
            document.images['index_screenshottab'].src = "/images/simple/index_screenshottab.jpg";
            document.images['index_graphicstab'].src = "/images/simple/index_graphicstab_over.jpg";
            document.images['index_wallpapertab'].src = "/images/simple/index_wallpapertab.jpg";
        }
        else if ( gallery_id == 47 )
        {
            document.images['index_screenshottab'].src = "/images/simple/index_screenshottab.jpg";
            document.images['index_graphicstab'].src = "/images/simple/index_graphicstab.jpg";
            document.images['index_wallpapertab'].src = "/images/simple/index_wallpapertab_over.jpg";
        }
        
        gallery = gallery_id;
                
        gallery_scroll ( gallery_id );
    }
    else return false;
}



function getimage ( image_id )
{
    window_width = screen.width - 100;
    window_height = screen.height - 100;

    window.open ( '/getimage/' + image_id + '.html', 'image', 'width=' + window_width + ', height=' + window_height + ', left=50, top=50' );
}



function resizeWindow()
{
    window_width = screen.width - 100;
    window_height = screen.height - 44;

    workflow_window_width = window_width;
    workflow_window_height = window_height - 115;
    
    image_width = document.images['gallery_image'].width;
    image_height = document.images['gallery_image'].height;
    
    document.getElementById('gallery_getimage_preview').style.width = workflow_window_width;
    document.getElementById('gallery_getimage_preview').style.height = workflow_window_height;
    document.getElementById('gallery_getimage_loader').style.display = "none";
    
    if ( workflow_window_width < image_width || workflow_window_height < image_height )
    {
        var nPercent = 0;
        var nPercentW = 0;
        var nPercentH = 0;
        
        nPercentW = workflow_window_width / image_width;
        nPercentH = workflow_window_height / image_height;
        
        if ( nPercentH < nPercentW )
            nPercent = nPercentH;
        else
            nPercent = nPercentW;
    
        
        document.images['gallery_image'].width = image_width * nPercent;
        document.images['gallery_image'].height = ( image_height * nPercent ) - 5;
        document.getElementById('gallery_getimage_zoom').style.display = "block";
    }
}



function showfullimage ()
{
    document.getElementById('gallery_getimage_zoom').style.display = "none";
    document.images['gallery_image'].width = image_width;
    document.images['gallery_image'].height = image_height;
}



function showvideo( name, video, image, container, skin )
{
    if ( !skin )
    {
        var skin = 'rfo_skin2';
    }
    var video = video.replace( /\/flash\//i, "/");
	var image = image.replace( /\/flash\//i, "/");
    
    document.getElementById("videoplayer_name").innerHTML = '<div>' + name + '</div>';
    document.getElementById("videoplayer_download").innerHTML = '<a href="/content' + video + '.avi" class="videoplayer_download">скачать полную версию видео</a>';

    var so = new SWFObject( "/images/flash/video_player.swf", "videoplayer", "250", "260", "8", "#1b252e");
    so.addParam("wmode", "transparent");
    so.addVariable( "skin_url", "/images/flash/" + skin + ".swf" );
    so.addVariable( "flv_url", "/content" + video + ".flv" );
    so.addVariable( "preview_url", "/content" + image );
    so.write( container );
}



function MM_preloadImages()
{
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function loginunion ( id )
{
    if (id.checked == true) 
    {
        show_hide_layer( 'rf_account_form', 'hide' );
    }
    else
    {
        show_hide_layer( 'rf_account_form', 'show' );
    }
}


function liveinternet_counter()
{
	document.write('<img src="http://counter.yadro.ru/hit?r' + escape(document.referrer) + ((typeof(screen)=='undefined')?'':';s'+screen.width+'*'+screen.height+'*'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)) + ';u' + escape(document.URL) +';i' + escape('Жж'+document.title.substring(0,80)) + ';' + Math.random() + '" width=10 height=10 alt="">');
}



function getItemSellInfo( id_item )
{
    window.open( '/payment/item/' + id_item + '.html', 'itemsellinfo', 'width=475, height=500, scrollbars=yes' );
}



jQuery(function( $ ){

// скачать клиент
	$('.check_license > .check').click(function() {
		if ($(this).hasClass('active')) {
			$(this).removeClass('active');
			$('.download_button').removeClass('active');
		} else {
			$(this).addClass('active');
			$('.download_button').addClass('active');
		}
	});

	$('.check_license_accept').click(function() {
		if ($('.check_license > .check').hasClass('active')) {
			$('.check_license > .check').removeClass('active');
			$('.download_button').removeClass('active');
		} else {
			$('.check_license > .check').addClass('active');
			$('.download_button').addClass('active');
		}
	});
	
	$('.link_agreement').click(function() {
		$('.download_box_agreement').show();
	});	
	
	$('.download_box_agreement_close').click(function() {
		$('.download_box_agreement').hide();
	});	

});









