var navwidth = 350;
var contentmaxwidth = 0;
var tmp;
var tmp1;
function rotCard() {
	tmp1 = Math.floor(Math.random()*25) + 1;
	document.getElementById("card").getElementsByTagName("img")[0].src = "/portfolio/media/cards/" + tmp1 + ".jpg";
}
function doLoad() {
	doPositioning();
	rotCard();
	setInterval("rotCard()", 3000);
	document.getElementById("start").style.display = "block";
}
function contentNav(obj, name, cmw) {
	document.getElementById("content").src = obj.href;
	if (cmw) contentmaxwidth = cmw;
	else contentmaxwidth = 0;
	for (var x = 0; x < getElementsByClassName(document, "description").length; x++) {
		getElementsByClassName(document, "description")[x].style.display = "none";
	}
	document.getElementById(name).style.display = "block";
	doPositioningAct();
	return false;
}
function doPositioning() {
	document.getElementById("content").style.height = "1px";
	document.getElementById("content").style.width = "1px";
	if (BrowserDetect.browser == "Explorer") doPositioningAct();
	else {
		setTimeout("doPositioningAct()", 100);
		setTimeout("doPositioningAct()", 1000);
	}
}
function doPositioningAct() {
	document.getElementById("content").style.height = Math.max(document.getElementById("nav").offsetHeight + 1, findViewport()[1] - 4) + "px";
	tmp = findViewport()[0] - navwidth - 4;
	if (BrowserDetect.browser != "Explorer" && findViewport()[1] <= document.getElementById("nav").offsetHeight) tmp -= 19; /* 17 */
	if (contentmaxwidth != 0) {
		document.getElementById("content").style.width = Math.min(contentmaxwidth, tmp) + "px";
		tmp = Math.round(Math.max(0, tmp - contentmaxwidth) / 2);
		document.getElementById("main").style.marginRight = tmp + "px";
		document.getElementById("main").style.marginLeft = tmp - 1 + "px";
	} else {
		document.getElementById("main").style.marginRight = 0;
		document.getElementById("main").style.marginLeft = 0;
		document.getElementById("content").style.width = tmp + "px";
	}
}
function doPositioningCentre() {
	document.getElementById("title").style.marginTop = (findViewport()[1] - document.getElementById("title").offsetHeight) / 2 + "px";
	// document.getElementById("title").style.display = "block";
}
function doPositioningCC() {
	if (findViewport()[0] < 1320) document.getElementById("grid").style.maxWidth = "530px";
	else document.getElementById("grid").style.maxWidth = "1060px";
	document.getElementById("grid").style.marginTop = (findViewport()[1] - document.getElementById("grid").offsetHeight) / 2 + "px";
	document.getElementById("grid").style.marginLeft = (findViewport()[0] - document.getElementById("grid").offsetWidth) / 2 + "px";
// document.getElementById("title").style.display = "block";
}
function findViewport() {
/* Get viewport size script by Andy Langton
   http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/ */
	var viewportwidth;
	var viewportheight;
	if (typeof window.innerWidth != 'undefined') {
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	} else {
	// older versions of IE
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	return [viewportwidth, viewportheight];
}
function getElementsByClassName(node, classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
/* Browser Detect by Peter-Paul Koch
   http://www.quirksmode.org/js/detect.html */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();