var current = 0;

model_current = 0;        
model_prev = model.length-1;
model_next = 1;
previewscroll = "";
previewopacity = "";

for (x=0; x<model.length; x++) {
    model[x]['DATA'][4] = model[x]['DATA'][4]?(model[x]['DATA'][4]+' млн.$'):"";
}

function models_show_preview( element,current,opacity,currstyle) {
    var preview_html = "<table cellpadding=0 cellspacing=0 class='mpreview'><tr>";
    for (x=0;x<model.length;x++) {
        preview_html = preview_html + '<td><div><img class="'+opacity+'" src="'+model[x]['PREVIEW']+'" onclick="javascript:models_change('+x+')"/></div></td>';
    }
    preview_html = preview_html + '</tr></table>';
    
    $(element).html(preview_html);
       
    $(element+' img:eq('+current+')').removeClass(opacity);
    $(element+' img:eq('+current+')').toggleClass(currstyle);
    $(element+' td>div:eq('+current+')').toggleClass('stroke');
      
    previewscroll = element;
    previewopacity = opacity;
    currentstyle = currstyle;

    $(element+' img').hover( function() { $(this).removeClass(opacity); }, function() { $(this).addClass(opacity); } );
    
    $(element+' img:eq('+model_current+')').unbind('mouseover');
    $(element+' img:eq('+model_current+')').unbind('mouseout');    
}
 
function models_change( next ) {

    model_prev = (next-1>=0)?(next-1):model.length-1;
    model_next = (next+1<model.length)?(next+1):0;

    element = $(previewscroll+' img:eq('+model_current+')');
    $(element).removeClass(currentstyle);    
    $(element).addClass(previewopacity);
    $(element).parent().toggleClass('stroke');
    $(element).bind('mouseover', function() { $(this).removeClass(previewopacity) } );
    $(element).bind('mouseout', function() { $(this).addClass(previewopacity) } );     
       
    model_current = next;
    element = $(previewscroll+' img:eq('+model_current+')');
    $(element).unbind('mouseover');
    $(element).unbind('mouseout');         
    $(element).removeClass(previewopacity);
    $(element).addClass(currentstyle);    
    $(element).parent().toggleClass('stroke');
        
    $('#models_top').attr('src', model[ next ]['IMAGE']);
    $("#review_container table tr.header td a").attr('href',model[next]["HREF"]);
    $("#review_container table tr.header td a p").html(model[next]["NAME"]);
    $("#review_container table tr:gt(1) td.jtech").each( function(index){ this.innerHTML=model[next]["DATA"][index]?model[next]["DATA"][index]:""; })   
    
    return false;
} 