var sliderResize = function(){

    var viewportwidth,
        viewportheight;
     
    if (typeof window.innerWidth != 'undefined'){
        viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight;
    }

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0){
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight;
    }
     
    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }

    var resize = function(img, maxh, maxw) {

        var ratio = maxh/maxw;
        
        if (img.height/img.width > ratio){
            if (img.height > maxh){

              img.width = Math.round(img.width*(maxh/img.height));
              img.height = maxh;
            }
            
        } else {

            if (img.width > maxh){

              img.height = Math.round(img.height*(maxw/img.width));
              img.width = maxw;
            }
            
        } 
    },
    
    scale = function(img, maxH, maxW, currW, currH){

        var ratio = currH / currW;

        if(currW >= maxW && ratio <= 1){
            
            currW = maxW;
            currH = currW * ratio;
            
        } else if(currH >= maxH){
        
            currH = maxH;
            currW = currH / ratio;
            
        } else {
        
            currH = maxH;
            currW = currH / ratio;
        
        }
        
        img.width = currW;
        img.height = currH;
        //return [currW, currH];
        
    },
    
    entries = document.getElementById('entries'),
    main_content = document.getElementById('main_content'),
    main_inner = document.getElementById('main_inner'),
    entry = document.getElementById('entry'),
    image = entry.getElementsByTagName('img')[0];

    if(image){
        
        var imageWidth = image.width || 0,
        imageHeight = image.height || 0;


        if(!document.getElementById('day_overview')){

            entries.style.height = '350px';
            main_content.style.height = '350px';
            main_inner.style.bottom = '55';
            scale(image, '350', '780', imageWidth, imageHeight);

        } else {

            entries.style.height = '511px';
            main_content.style.height = '511px';
            main_inner.style.bottom = '55';
            scale(image, '511', '780', imageWidth, imageHeight);

        }

    }

};

sliderResize();

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    }
};


addEvent(window, "resize", sliderResize );
















