onload = function () {
    //setBackgroundImages();
    //changeimages();
    setMainImageSize();
    setTimeout("setMainImageSize()", 100);
    oneBit = new OneBit('/1bit.swf'); 
    oneBit.specify('color', '#ff0000'); 
    oneBit.specify('playerSize', '18');
    oneBit.specify('background', '#FFFFFF'); 
    oneBit.specify('position', 'before'); 
    oneBit.specify('analytics', true); 
    oneBit.apply('a');
    //oneBit.apply('a', '#ffffff', '#ff5a00', '10');
}

onresize = function () {
    setMainImageSize();
}

onscroll = function () {
/*
    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;
    }
    
    var side_head = document.getElementById("side_head");
    var side_top = document.getElementById("side_top");
    var mainimageContainer = document.getElementById('imagecontainer');
    
    if(mainimageContainer != null) {
        
        var image_height = (mainimageContainer.offsetWidth/3892) * 2586;
            
        var container_height = myHeight;
        
        if(container_height > image_height) {
            container_height = image_height;
        }
        
        if(window.pageYOffset >= (container_height+10)) {
            side_head.setAttribute('class', '');
            side_top.setAttribute('class', 'hide');
        } else {
            side_head.setAttribute('class', 'singleitem');
            side_top.setAttribute('class', '');
        }
    } else {
        side_head.setAttribute('class', '');
        side_top.setAttribute('class', 'hide');
    }
    */
}

function toggleLatest() {
    var latestMenu = document.getElementById("latestMenu");
    
    if(latestMenu.style.top == '34px') {
        latestMenu.style.top = '-1000px';
    } else {
        latestMenu.style.top = '34px';
    }
}

function tweak() {
    var currentwidth = document.getElementById("content").offsetWidth;
    document.getElementById("content").style.width = (currentwidth - 1) + "px";
    setTimeout("tweak2()", 100);
}

function tweak2() {
    var currentwidth = document.getElementById("content").offsetWidth;
    document.getElementById("content").style.width = (currentwidth + 1) + "px";
}

var MAX_height = 12000;

var contentsBottomMargin = 237;
var contentsTop = 116;
var contentsMinHeight = 260;
var bottomSize = 220;

function setMainImageSize() {
	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;
    }
    
    var new_image_width = myWidth;
    var new_image_height = new_image_width*(2586/3892);
    
    if(new_image_height < myHeight) { 
        new_image_height = myHeight;
        new_image_width = new_image_height*(3892/2586);
    }
    
    var mainimageContainer = document.getElementById('imagecontainer');
    
    if(mainimageContainer != null) {
        
        var image_height = ((mainimageContainer.offsetWidth/3892) * 2586) - 50 - 24;
        
        var container_height = myHeight;
        
        if(container_height > image_height) {
            container_height = image_height;
        }
        
        mainimageContainer.style.height = container_height + 'px';
        
        var titlecontainer = document.getElementById('titlecontainer');
    
        if(titlecontainer != null) {
            titlecontainer.style.height = (container_height - 50) + "px";
        }
    }
    
    var photopageembed = document.getElementById('photopageembed');
    if(photopageembed != null) {
        photopageembed.style.height = (myHeight-50) + "px";
        photopageembed.style.width = myWidth + "px";
    }
    
    var latestinfo = document.getElementById('latestinfo');
    
    if(latestinfo != null) {
        
        var latestinfoheight = latestinfo.clientHeight;
        
        var latestimagecontainer = document.getElementById('latestimagecontainer');
        latestimagecontainer.style.height = latestinfoheight + 'px';
        
        if(latestinfoheight < 400) {
            latestinfoheight = 400;
        }
        
        var latestimageimg = document.getElementById('latestimageimg');
        latestimageimg.style.height = latestinfoheight + 'px';
        latestimageimg.style.marginLeft = '-'+(((3888/2588)*latestinfoheight)/2) + 'px';
    }	
    
    var grid = document.getElementById('grid');
    
    if(grid != null) {
        grid.style.height = document.body.offsetHeight + 'px';
    }
    
    var side_head = document.getElementById('side_head');
    var content = document.getElementById('content');
    if(side_head != null) {
        var content_width = content.offsetWidth;
        side_head.style.right = ((myWidth-content_width)/2) + 43 + "px";
    }
}

var itemoffsets = new Array();
var backgroundimages = new Array();
var backgroundimagesloaded = 0;

function setBackgroundImages() {
    maindivs = document.getElementById("main").getElementsByTagName("div");
    itemoffsets[0] = 0;
    count = 0;
    for( i = 0 ; i < maindivs.length ; i++ ) {
        if((maindivs[i].getAttribute("class") == "item") || (maindivs[i].getAttribute("className") == "item")) {
            if(maindivs[i].id) {
                if(count > 0) {
                    itemoffsets[count+1] = maindivs[i].clientHeight + findPos(maindivs[i]);
                } else {
                    itemoffsets[count+1] = maindivs[i].clientHeight + findPos(maindivs[i]);
                }
                backgroundimages[count] = maindivs[i].id.split('-')[0];
                count++;
            }
        }
    }
}

function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curtop;
}