/**
 * @author Diaan
 */

window.onresize = function() {
    setMainImageSize();
}

//IE7_PNG_SUFFIX = "-trans.png";
var type = "";
if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

var MAX_height = 12000;

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*(700/1050);
    
    if(new_image_height < myHeight) { 
        new_image_height = myHeight;
        new_image_width = new_image_height*(1050/700);
    }
    
    // Image minimum dimensions...
    if(new_image_width < 800) {
    	new_image_width = 800;
    	new_image_height = new_image_width*(700/1050);
    }
    
    
    var mainimage = document.getElementById('mainimage');
    var mainimageContainer = document.getElementById('imagecontainer');
       
    mainimage.setAttribute("className", "dynamic");
    
    mainimage.style.height = new_image_height + "px";
    mainimage.style.width = new_image_width + "px";
    
    if(new_image_width < 801) {
        mainimage.src = "images/background/" + mainimage.getAttribute("alt") + "_800.jpg";
    } else if(new_image_width < 1050) {
        mainimage.src = "images/background/" + mainimage.getAttribute("alt") + "_1050.jpg";
    } else if(new_image_width < 1501) {
        mainimage.src = "images/background/" + mainimage.getAttribute("alt") + "_1500.jpg";
    } else {
        mainimage.src = "images/background/" + mainimage.getAttribute("alt") + "_2000.jpg";
    }
}

// Image position stuff
var isIE6 = (getInternetExplorerVersion() == 6);

if(isIE6) {
	window.onscroll = whenScrolling;
}

// Navigation always to the left when scrolling
function whenScrolling()
{
  var mainimageContainer = document.getElementById('imagecontainer');
	scrollPosition = getScrollPosition();	
	mainimageContainer.style.top = scrollPosition["y"];
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

// Get scroll coordinates
function getScrollPosition()
{
	// See http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
	/*
	if (isSafari) {
		var windowScrollX = document.body.scrollLeft;
		var windowScrollY = document.body.scrollTop;
	}
	else {
	*/
	var windowScrollX = document.documentElement.scrollLeft;
	var windowScrollY = document.documentElement.scrollTop;
	//}
	var position = new Array();
	position["x"] = windowScrollX;
	position["y"] = windowScrollY;
	return position;
}	
