$(document).ready(function(){
    $(".inbox1_fix").append('<div id="flash-menu" style="position: absolute; padding-left: 8px; padding-top: 10px; margin-top: 83px"><embed src="/userfiles/image/foto_tovarov.swf" quality="high" width="150" height="30" name="jara3" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></div>');    
});

function ytvideo(id)
{
    $(".ytvideo").css("visibility", "hidden");
    $("#ytvideo"+id).css("visibility", "visible");
}


function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function truebody(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//запускаем тень
function oShowFuzz(){
    $("body").append("<div id='ofuzz'></div>");
    $("#ofuzz").css("height", $(document).height());
    $("#ofuzz").show();
}


//Выводим  прогресс картинку
function oShowProgres(startslash){
    //lj,fdkzt
    $("body").append("<div id='oprev_progres'><img src='"+startslash+"images/fotgal/bar.gif' id='oprev_progres_img' alt='Load...'/></div>");
    oprev_progres_img_width = 100; //Ширина прогресс картинки
    oprev_progres_img_height = 100;//Высота прогресс картинки

    $("#oprev_progres").css("margin-left", (-oprev_progres_img_width/2));
    $("#oprev_progres").css("margin-top", (-oprev_progres_img_height/2));
    $("#oprev_progres").css("top", (parseInt($(window).height()/2+getBodyScrollTop())));
    $("#oprev_progres").css("width", (oprev_progres_img_width));
    $('#oprev_progres').show();
}

function showbig(imgname, startslash){
//imgwidth, imgheight,
    //запускаем тень
    oShowFuzz();

    //Выводим  прогресс картинку
    oShowProgres(startslash);

    //грузим превью картинки
    imgPreloader=new Image();
    imgPreloader.onload=function(){
        imgPreloader.onload=null;
        var pagesize=OgetPageSize();
        var x=pagesize[0];
        var y=pagesize[1];
        var imageWidth=imgPreloader.width;
        var imageHeight=imgPreloader.height;

    x = parseInt(x);
    y = parseInt(y);

    arr_size = resizeimg(imageWidth, imageHeight, 1);

    imageWidth = arr_size[0];
    imageHeight = arr_size[1];

//        if(imageWidth>x){
//            imageHeight=imageHeight*(x/imageWidth);
//            imageWidth=x;
//            if(imageHeight>y){
//                imageWidth=imageWidth*(y/imageHeight);
//                imageHeight=y;
//            }
//        }else if(imageHeight>y){
//            imageWidth=imageWidth*(y/imageHeight);
//            imageHeight=y;
//            if(imageWidth>x){
//                imageHeight=imageHeight*(x/imageWidth);
//                imageWidth=x;
//            }
//        }

//       imgwidth = parseInt(imgwidth, 0);
//       imgheight = parseInt(imgheight, 0);
       imgwidth = parseInt(imageWidth);
       imgheight = parseInt(imageHeight);

        $("body").append("<div id='omsgbox'><img src='"+imgname+"' id='oimgprv' alt='prev...'/></div>");

        $("#omsgbox").css("margin-left", (-imgwidth/2));
        $("#omsgbox").css("margin-top", (-imgheight/2));
        $("#omsgbox").css("top", ($(window).height()/2+getBodyScrollTop()));
        $("#omsgbox").css("height", (imgheight));
        $("#omsgbox").css("width", (imgwidth));
        $("#oimgprv").css("width", (imgwidth));
        $("#oimgprv").css("height", (imgheight));
        $('#oimgprv').attr('src', imgname);
        $('#omsgbox').show();


        $("#oprev_progres").remove();
        $('#omsgbox').click(function(){
            $("#ofuzz").remove();
            $("#omsgbox").remove();
        });

    }
    imgPreloader.src=imgname;
    //грузим превью картинки

    return false;
}

function clc(imgname, imgwidth, imgheight, startslash){
    
    //запускаем тень
    oShowFuzz();
    
    //Выводим  прогресс картинку
    oShowProgres(startslash);

    //грузим превью картинки
    imgPreloader=new Image();
    imgPreloader.onload=function(){
        imgPreloader.onload=null;
        var pagesize=OgetPageSize();
        var x=pagesize[0];
        var y=pagesize[1];
        var imageWidth=imgPreloader.width;
        var imageHeight=imgPreloader.height;
        if(imageWidth>x){
            imageHeight=imageHeight*(x/imageWidth);
            imageWidth=x;
            if(imageHeight>y){
                imageWidth=imageWidth*(y/imageHeight);
                imageHeight=y;
            }
        }else if(imageHeight>y){
            imageWidth=imageWidth*(y/imageHeight);
            imageHeight=y;
            if(imageWidth>x){
                imageHeight=imageHeight*(x/imageWidth);
                imageWidth=x;
            }
        }

//       imgwidth = parseInt(imgwidth, 0);
//       imgheight = parseInt(imgheight, 0);

       imgwidth = imageWidth;
       imgheight = imageHeight;

        $("body").append("<div id='omsgbox'><img src='"+imgname+"' id='oimgprv' alt='prev...'/></div>");

        $("#omsgbox").css("margin-left", (-imgwidth/2));
        $("#omsgbox").css("margin-top", (-imgheight/2));
        $("#omsgbox").css("top", ($(window).height()/2+getBodyScrollTop()));
        $("#omsgbox").css("height", (imgheight));
        $("#omsgbox").css("width", (imgwidth));
        $("#oimgprv").css("width", (imgwidth));
        $("#oimgprv").css("height", (imgheight));
        $('#oimgprv').attr('src', imgname);
        $('#omsgbox').show();


        $("#oprev_progres").remove();
        $('#omsgbox').click(function(){
            $("#ofuzz").remove();
            $("#omsgbox").remove();
        });

    }
    imgPreloader.src=imgname;
    //грузим превью картинки

    return false;
}

function OgetPageSize(){
    var de=document.documentElement;
    var w=window.innerWidth||self.innerWidth||(de&&de.clientWidth)||document.body.clientWidth;
    var h=window.innerHeight||self.innerHeight||(de&&de.clientHeight)||document.body.clientHeight;
    arrayPageSize=[w,h];
    return arrayPageSize;
}

$(window).bind("resize", function(){
    $("#omsgbox").css("top", (truebody().clientWidth/2));
    $("#ofuzz").css("height", $(window).height());
});

