var ca;
var cb;
var chapter;
// кэширование ролловера в нижней плашке
var bottomImg = new Image(633 , 83);
bottomImg.src = '/pic/b2.gif' ;
var bottomImgO = new Image(633 , 83);
bottomImgO.src = '/pic/b2o.gif';

window.onload = function(){
    var reg = new RegExp(/^http:\/\/[^\/]+\/([^\/|.]+)/);
    var m = reg.exec(document.location.toString());
    undefined != m ? chapter = m[1] : chapter = 'index';
    // console.log(chapter);
    initDHTMLAPI();
    var def = $$('default');
    if(def.length != 0){
        var defA = def[0].readAttribute('a');
        var defB = def[0].readAttribute('b');
    }else{
        var defA = 'Black';
        var defB = 'White';
    }
    ca = new Colorizer(defA, 'a');
    // console.log(ca._elements);
    cb = new Colorizer(defB, 'b');
    applyFPenStyle(defA, 'a'); 
    applyFPenStyle(defB, 'b');
    Event.observe('bottomRO', 'mouseover', function(){ $('bottomRO').src = bottomImgO.src; } ); 
    Event.observe('bottomRO', 'mouseout', function(){  $('bottomRO').src = bottomImg.src;  } );

    // pnghack(); 
} 

window.onscroll = function(){
    //console.log('scroll');
}      
function applyFPenStyle(style, group){
    var csimg, cs;
    var g = group.toLowerCase();
    if('a' == g){
        ca.setStyle(style);
    }else if('b' == g){
        cb.setStyle(style);
    }
    var bpimg = 'url(/files/Image/bottom/' + cb.style + '.gif)';
    $('bottomPlate') ? $('bottomPlate').setStyle( {backgroundImage : bpimg} ) : true;
    
    csimg = 'url(/files/Image/' + chapter + '/' + ca.style + '.gif)';
    cs = $$('#chapterSign.b');
    cs.length ? cs[0].setStyle( {backgroundImage : csimg} ) : true;  
    cs = $$('#chapterSign1.b');
    cs.length ? cs[0].setStyle( {backgroundImage : csimg} ) : true;
       
    csimg = 'url(/files/Image/' + chapter + '/' + cb.style + '.gif)';
    cs = $$('#chapterSign.a');
    cs.length ? cs[0].setStyle( {backgroundImage : csimg} ) : true; 
    cs = $$('#chapterSign1.a');
    cs.length ? cs[0].setStyle( {backgroundImage : csimg} ) : true;  
}
function applyDefaultStyle(){
    ca.resetStyle();
    cb.resetStyle();
    applyFPenStyle(ca.style, 'a');
    applyFPenStyle(cb.style, 'b');
}

// открывающееся окно с картинкой
function popupImage(imagePath){
    var w = '/image_window.php?pic='+imagePath;
    var arg = 'toolbar=no,';
    arg+= 'location=no,';
    arg+= 'directories=no,';
    arg+= 'status=no,';
    arg+= 'menubar=no,';
    arg+= 'scrollbars=no,';
    arg+= 'resizable=yes,';
    arg+= 'copyhistory=no,';
    arg+= 'width=10,';
    arg+= 'height=10';
    window.open(w,'',arg);
    }

function loadImage() {
    var addr = document.location.toString() ;
    var reg = '\?pic=';
    var pic = addr.split(reg);
	im = getId('targetImage');
    im.src = pic[1];
    }

function windowResize() {
    var n = getBrowser();
    var winW = im.width+70 ;
    var winH = im.height+70 ;
    if (n=='N'){
	    window.innerWidth = winW ;
	    window.innerHeight = winH ;
    }else if (n=='IE'){
        window.resizeTo(winW , winH);
    }else if (n=='O'){
        window.resizeTo(winW+10 , winH+30);
        }

}

