// Copyright (C) 2007 stretchgames.com. All Rights Reserved.
var w=h=myWidth=myHeight=bannerHeight=0;

function indexInit()
{
   getSize(); 
   setIndexSize()
}

function gpageInit()
{
   getSize(); 
   setGpageSize()
}

//from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow 
function getSize()
{ 
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth - 16;
        myHeight = window.innerHeight - 16;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth - 16;
        myHeight = document.documentElement.clientHeight - 12;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth - 16;
        myHeight = document.body.clientHeight - 12;
    }

    if(myHeight > myWidth*600/400) {
        // size to fit width
        w = myWidth;
        h = w*400/600;
    } else {
        // size to fit height
        h = myHeight
        w = h*600/400;
    }
    //alert(myWidth+' '+myHeight+' '+w+' '+h);
}

function setIndexSize() {
    // set element sizes
    bannerHeight = myWidth*40/1024;
    var banner = document.getElementById('banner');
    banner.setAttribute('width', myWidth);
    banner.setAttribute('height', bannerHeight);
    //var wrapper = document.getElementById('wrapper');
    //wrapper.setAttribute('width', myWidth);
}

function setGpageSize() {
    // set element sizes
    bannerHeight = myWidth*40/1024;
    var banner = document.getElementById('banner');
    banner.setAttribute('width', myWidth);
    banner.setAttribute('height', bannerHeight);
    var gwrapper = document.getElementById('gwrapper');
    gwrapper.setAttribute('width', myWidth);
    var gamecore = document.getElementById('gamecore');
    var fullscreen = document.getElementById('gfull');
    //var gameheader = document.getElementById('gameheader');
    var obj = document.getElementById('object');
    var embed = document.getElementById('swfobj');
    if(embed === null) {
        //alert("embed is null");
        embed = document.getElementById('SWFOBJ');
        if(embed === null) {
            //alert("EMBED is null");
            var embedtags = document.getElementsByTagName("EMBED"); 
            for (var i = 0; i < embedtags.length; i++) { 
                //alert("found embed tag by tag name");
                embed=embedtags[i];
            }
        }
    }

    var objHeight, objWidth;
    if(fullscreen !== null) {
        objHeight = myHeight-bannerHeight-30;
        objWidth = myWidth-186;
    } else {
        objHeight = myHeight-bannerHeight-30-100;
        objWidth = myWidth-186-160;
    }
/*
    if(objHeight > objWidth*300/400) {
        // size to fit width
        w = objWidth;
        h = w*300/400;
    } else {
        // size to fit height
        h = objHeight
        w = h*400/300;
    }
*/
    w = objWidth;
    h = objHeight;
    gamecore.setAttribute('width', w);
    //gameheader.setAttribute('width', w);
    obj.setAttribute('width', w);
    obj.setAttribute('height', h);
    if(embed !== null) {
        embed.setAttribute('width', w);
        embed.setAttribute('height', h);
    }

    var h3 = document.getElementById('fullscreen');
    if(myWidth < 1000) {
        var h1 = document.getElementById('lhead');
        var h2 = document.getElementById('chead');
        var gb = document.getElementById('gamebody');
        var gr = document.getElementById('gameright');
        var sp = document.getElementById('sep');
        h1.setAttribute('style', 'font-size:10px');
        h2.setAttribute('style', 'font-size:10px');
        if(h3) {
           h3.setAttribute('style', 'font-size:10px');
        }
        gr.setAttribute('style', 'font-size:10px');
        gb.setAttribute('style', 'margin: 0px 4px 0px 4px');
        sp.setAttribute('style', 'clear:both');
    }
    if(fullscreen) {
        if(h3) {
            h3.setAttribute('style', 'display:none');
        }
    }
}

var fullwin;
function stretchfull(url)
{
    fullwin=window.open(url,'_stretchfull');
    if (window.focus) {
        fullwin.focus();
    }
}


