var slider;
var sliderId="slider";
var slides;
function preInitSlide() {
    if ((document.getElementById)&&(slider=document.getElementById(sliderId))) {
        if (typeof preInitTimer != 'undefined') clearTimeout(preInitTimer);
    } else {
        preInitTimer = setTimeout("preInit()",2);
    }
}
function init_slides(){
    preInitSlide();
    slides = new Array;
    var node = slider.firstChild;
    while (node) {
        if (node.nodeType==1) {
            slides.push(node);
        }
        node = node.nextSibling;
    }
}
function reportSize() {
    myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else {
        if( document.documentElement &&( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else {
            if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
        }
    }
}
function reSize(u){
    var a,b,c,d,e;
    reportSize();
    e = u.width/u.height;
    a = myWidth;
    b = a/e;
    if(b>=myHeight){
        c = -((b-myHeight)/2);
        d = 0;    
    }else{
        b = myHeight;
        a = b*e;
        c = 0;
        d = -((a-myWidth)/2)
    }
    for(p=0;p<slides.length;p++){
        if(u.src == slides[p].src){
            slides[p].style.width = a+"px";
            slides[p].style.height = b+"px";
            slides[p].style.top = c+"px";
            slides[p].style.left = d+"px";
        }
    }    
}
function get_size(ImgSrc){
    var newImg = new Image();
    newImg.src = ImgSrc.src;
    newImg.onload = function(){
        reSize(newImg);   
    }    
}
window.onload = function(){
    init_slides();
    for(i=0;i<slides.length;i++){
        get_size(slides[i]);
    }
    init_gallery();
}
window.onresize = function(){
    init_slides();
    for(i=0;i<slides.length;i++){
        get_size(slides[i]);
    }
}
