var lastWidth = null;
var lastHeight = null;
var resized = false;

//Todo: You may need to adjust the minimum font size
var smallestFont = 10; //this is pixels (keep in mind this is meant for 800x600 size);
var fontSize = 1;
var newWidth = 0; var newHeight = 0;

function fixScreen(){
    //Resize the screen
    var w = screen.width -2;
    var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    window.moveTo(LeftPosition,0);
    self.resizeTo(screen.availWidth - 1, screen.availHeight);
    self.moveTo(LeftPosition,0);
    self.focus;
}

function fixImage(){
    size = getWindowSize().split('x');
    
    //See if we've been resized
    resized = (size[0] != lastWidth || size[1] != lastHeight) ? true : false;
    lastWidth = size[0];
    lastHeight = size[1];
    
    //But if we resize than we can do this dynamically
    if(size[0] / size[1] >= 2){
        //alert('wide');
        $('#backgroundImage').css('width', '100%');
        $('#backgroundImage').css('height', 'auto');
        //setStyleById('backgroundImage', 'width', '100%');
        //setStyleById('backgroundImage', 'height', 'auto');
    }else{
        //alert('tall');
        $('#backgroundImage').css('height', '100%');
        $('#backgroundImage').css('width', 'auto');
        //setStyleById('backgroundImage', 'width', 'auto');
        //setStyleById('backgroundImage', 'height', '100%');       
    }
    
    if(size[1] < 450 ){
        if($('heightSpacer').length){
            $('heightSpacer').hide();
        }
    }
    
    /*
    //Fix Font Size
    //take the height, divide it by a constant size ratio
    fontSize = (size[1] / 550) * smallestFont;
    fontSize = Math.round(fontSize);
    //alert(fontSize);
    //don't let it get any smaller.
    if(fontSize < smallestFont){
        setStyleByTag('body', 'fontSize', smallestFont + 'px', 1);
    }else{
        setStyleByTag('body', 'fontSize', fontSize + 'px', 1);
        setStyleByTag('p', 'height', 'auto', 1);
    }
    */
    
    //Fix Background Div for Portfolio
    if(document.getElementById('resizeBackgroundDiv')){
        //Get the width
        obj = document.getElementById('resizeBackgroundDiv');
        newWidth = obj.clientWidth;
        
        //It's a square so make the height the same as width
        obj.style.height = newWidth + 'px';        
    }
    
    //Fix the movie viewer's height. It assumes 4:3 aspect ratio
    if(document.getElementById('myMovie')){
        //padding
        newWidth -= 20;
        //if(newWidth > 400) newWidth = 400; //limit size
        document.getElementById('myMovie').style.width = newWidth + 'px';
        height = (newWidth / (4.0 /3.0)) + 20; //Room for the controls.
        document.getElementById('myMovie').style.height = height + 'px';
    }
    
    
    if(resized){
        if( (in_array(url, subpages) && url != 'ourwork.php') || url == 'ourclientsspeak.php'){
            //Which iFrame?
            if(document.getElementById('portfolioNavigator')){
                //document.getElementById('portfolioNavigator').contentWindow.windowResized();
            }else if(document.getElementById('testimonialNavigator')){
                document.getElementById('testimonialNavigator').contentWindow.windowResized();
            }
        }
    }
    
    if( $('#portfolioNavigator').length){
        //resize the portfolio navigator
        $('#portfolioNavigator').css('width', $('#resizeBackgroundDiv').width() - 56); //56 is the offset of the arrows width w/ margin
    }
}    

        
//GET THE WINDOW SIZE
function getWindowSize() {
    var 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;
    }
    return myWidth + "x" + myHeight;
}

