var window_width   = 998;  // ширина страницы
var window_height  = 700;  // высота страницы
var menu_height    = 240;  // высота меню
var page_width     = 3881; // ширина полотна
var page_height    = 3390; // высота полотна
var offset_width   = 0;
var offset_height  = 0;
var offset_dop     = 0; 

/*
$.ajaxSetup({
  url: "ajax.php",
  type: "POST",
  error: ajaxError,
  dataType: "html",
  contentType: "application/x-www-form-urlencoded"
});

function ajaxError(XMLHttpRequest, textStatus, errorThrown){ // обработчик ошибки 
    alert(textStatus);
    return true;

}
*/

$().ready(function(){ 
    //borrowed from jQuery easing plugin
    //http://gsgd.co.uk/sandbox/jquery.easing.php
    $.easing.elasout = function(x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    };

    offset_width   = (document.body.offsetWidth-window_width)/2;    
    offset_height  = (document.body.offsetHeight-window_height)/2;   
    offset_dop     = (document.body.offsetHeight-window_height+menu_height)/2; 

    var ww = page_width + offset_width;
    var hh = page_height + offset_dop;

    $('#main .pages_main').css({ top: offset_dop, left:offset_width });
    $('#main .pages_main').css({ width:ww, height:hh });

    selTab('p0');

    $("#fixedtop #a0").click(function(){ 
        selTab('p0'); 
        return false; 
    });
    $("#fixedtop #a1").click(function(){ 
        selTab('p1'); 
        return false; 
    });
    $("#fixedtop #a2").click(function(){ 
        selTab('p2'); 
        return false; 
    });
    $("#fixedtop #a3").click(function(){ 
        selTab('p3'); 
        return false; 
    });
    $("#fixedtop #a4").click(function(){ 
        selTab('p4'); 
        return false; 
    });
    $("#fixedtop #a5").click(function(){ 
        selTab('p5'); 
        return false; 
    });
    $("#fixedtop #a6").click(function(){ 
        selTab('p6'); 
        return false; 
    });

});

function choose(item){
    $('#fixedtop a').removeClass("active");
    if(item=="p0") return;
    var s = '#fixedtop #' + item.replace(/p/,"a");
    $(s).addClass("active");
}

function move(item){
    var x,y;

    switch(item){
        case 'p0':
            x = 0;
            y = 1643;
            break;
        case 'p1':
            x = 1113;
            y = 2689;
            break;
        case 'p2':
            x = 2586;
            y = 2101;
            break;
        case 'p3':
            x = 3280;
            y = 327;
            break;
        case 'p4':
            x = 803;
            y = 0;
            break;
        case 'p5':
            x = 1486;
            y = 1302;
            break;
    }

    x = x + 'px';
    y = parseInt(y - offset_height + offset_dop - 30,10) + 'px';

    $('#main').scrollTo({ top:y, left:x }, 800, { axis:'xy', onAfter:choose(item), easing:'elasout' });
}

function selTab(item)
{
    move(item);
}

