//$(document).ready(function(){
//    $(".slideimge img").hover(function()
//    {
//        this.className = "slideimge11";
//    });
//    $(".slideimge img").hover(function()
//    {
//        this.className = "slideimge11";
//    });
//
//});
//
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
}


$(document).ready(function(){

    var width = $("#bigimg").attr("width");
    var height = $("#bigimg").attr("height");

    arr_size = resizeimg(width, height, 0);

    img_w = arr_size[0];
    img_y = arr_size[1];


    //alert(width);
    $('#bigimg').attr('width', img_w);
    $('#bigimg').attr('height', img_y);
    //
    $('#divbigimg').attr('width', img_w);
    $('#divbigimg').attr('height', img_y);
//
});


function sel_clide( img_w, img_y, fglimage_id){
    var tmpId = $('#so_group').attr('rel');

    $('#so_group').attr('rel', "so_group");
    $('#so_group').attr('id', tmpId);


    $('#arel'+fglimage_id).attr('rel', "fglimage_id");
    $('#arel'+fglimage_id).attr('id', "so_group");



    

    arr_size = resizeimg(img_w, img_y, 0);

    img_w = arr_size[0];
    img_y = arr_size[1];


    //truebody().clientWidth
    //alert($(window).height());

    //var row = document.getElementById("gallslideprevrow");
    var idicon = "icon"+fglimage_id;
    var icon = document.getElementById(idicon);
    var img_url = icon.getAttribute("src").replace('/icon','');

    //icon.setAttribute("class", "test");
    icon.className = "img_slide_v_clc";

    var tmpidicon = document.getElementById('tmpidicon');
    if(tmpidicon.value.length > 0){
        //alert(tmpidicon.value);
        icon = document.getElementById(tmpidicon.value);
        icon.className = "img_slide_v";
    }
    //alert(tmpidicon.value);
    tmpidicon.value = idicon;

    //var bigimg = document.getElementById("big"+fglimage_id);
    //$('#big'+fglimage_id).fadeOut();
    //$('#big'+fglimage_id).fadeIn();

    // $('#gallslideprevrow').attr('background-position', img_w/2+'center ');
    $('#divbigimg').fadeTo(500, 0,function () {
        //$('#bigimg').remove();
        //        $('#bigimg').attr('src', $("#tmpstsl").val()+"images/fotgal/bar.gif");
        //        $('#bigimg').attr('width', '100');
        //        $('#bigimg').attr('height', '100');
        //        $('#bigimg').show("fast");
        //$('#big'+fglimage_id).

        $('#bigimg').remove();
        $('#fscl').append('<img id="bigimg" src="'+$("#tmpstsl").val()+"images/spacer.gif"+'" width="'+img_w+'" height="'+img_y+'" alt="photo" border="0" >');
        imgPreloader=new Image();
        imgPreloader.onload=function(){
            imgPreloader.onload=null;
            $('#bigimg').remove();
            $('#divbigimg').attr('width', img_w);
            $('#divbigimg').attr('height', img_y);
            //$('#bigimg').fadeTo(100, 0);
            showbigact = "showbig('"+img_url+"', '"+$("#tmpstsl").val()+"')";

            $('#fscl').attr('href', img_url);
            //$('#divbigimg').append('<a rel="example_group" href="/sophoto/example/9_b.jpg" title="Lorem ipsum dolor sit amet"><img id="bigimg" src="'+img_url+'" width="'+img_w+'" height="'+img_y+'" alt="photo" border="0" onclick="'+showbigact+'"></a>');
            //$('#divbigimg').append('<img id="bigimg" src="'+img_url+'" width="'+img_w+'" height="'+img_y+'" alt="photo" border="0" onclick="'+showbigact+'">');
            $('#fscl').append('<img id="bigimg" src="'+img_url+'" width="'+img_w+'" height="'+img_y+'" alt="photo" border="0" >');
            $('#bigimg').attr('display', 'none');
            //$('#bigimg').attr('src', img_url);
            $('#bigimg').attr('width', img_w);
            $('#bigimg').attr('height', img_y);

            $('#divbigimg').fadeTo(1000, 1);
        }

        imgPreloader.src=img_url;
    //������ ������ ��������
    });

//var newCell = row.insertCell(0);//� ��������� ������ ��������� �������
//newCell.width="200";//��������� ����� ������� ������ 200 ��������
//newCell.align="center";//��������� ���������������� �� ������
//newCell.innerHTML='<img src="'+img_url+'" alt=""  border="0" width='+img_w+' height='+img_y+'>';
//var td1 = d.createElement("TD");

//row.appendChild(td1);

// ��������� ������
//td1.innerHTML = '<img src="'+img_url+'" alt="'+img_title+'" title="'+img_title+'" border="0" width='+img_w+' height='+img_y+'>';
}

function resizeimg(w_or, h_or, par){

    if(par<1){
        w_new = parseInt($(window).width()+getBodyScrollLeft()-400);
        h_new = parseInt($(window).height()+getBodyScrollTop()-60);
    }else{
        w_new = parseInt($(window).width()+getBodyScrollLeft()-20);
        h_new = parseInt($(window).height()+getBodyScrollTop()-20);
    }


    if(h_new <=480) {
        h_new = 480;
    }
    if(w_new <=500) {
        w_new = 500;
    }

    ratio = w_new/h_new;

    src_ratio=w_or/h_or;
    if (ratio<src_ratio) {
        h_or = w_new/src_ratio;
        w_or = w_new;
    }
    else {
        w_or = h_new*src_ratio;
        h_or = h_new;

    }
    arraySize=[w_or,h_or];
    return arraySize;

}
$(window).bind("resize", function(){
    var width = $("#bigimg").attr("width");
    var height = $("#bigimg").attr("height");

    arr_size = resizeimg(width, height, 0);

    img_w = arr_size[0];
    img_y = arr_size[1];


    //alert(width);
    $('#bigimg').attr('width', img_w);
    $('#bigimg').attr('height', img_y);
    //
    $('#divbigimg').attr('width', img_w);
    $('#divbigimg').attr('height', img_y);
//
});


