﻿loadMainOK = false;

function loadMainPage()
{
	try
  	{	// Firefox, Opera 8.0+, Safari, Internet Explorer 7
  		http = new XMLHttpRequest();
  	}
	catch (err)
  	{	// Internet Explorer
  		try
  		{	// Internet Explorer 6.0+
  			http = new ActiveXObject('Msxml2.XMLHTTP');
  		}
		catch (err)
    	{
    		try
    		{	// Internet Explorer 5.5+
    			http = new ActiveXObject('Microsoft.XMLHTTP');
    		}
			catch (err)
			{
				alert('Your browser does not support AJAX!');
			}
		}
	}
	http.open('get', 'ajax/main.ajx');
	http.onreadystatechange=function()
	{
		if(http.readyState == 4)
		{
			document.getElementById('contents').innerHTML = http.responseText;
			if (http.status == 200)
			{
				loadMain();
				document.getElementById('contents').className = 'scrollOff';
				loadMainOK = true;
			}
		}
	}
	http.send(null);
}
	
function loadMain()
{
	switch (language)
	{
		case 'fr':
			document.getElementById('endorsed').innerHTML= 'Lawrence, endorsé par JMC Guitars';
			break;
		case 'en':
			document.getElementById('endorsed').innerHTML= 'Lawrence, endorsed by JMC Guitars';
			break;
		case 'nl':
			document.getElementById('endorsed').innerHTML= 'Lawrence, gesponsord door JMC Guitars';
			break;
	}
}

portLnr = 1;
portRnr = 2;
interval = 2000;

port1 = new Image();
port1 = 'images/main/portrait-1.jpg';
port2 = new Image();
port2 = 'images/main/portrait-2.jpg';
port3 = new Image();
port3 = 'images/main/portrait-3.jpg';
port4 = new Image();
port4 = 'images/main/portrait-4.jpg';
port5 = new Image();
port5 = 'images/main/portrait-5.jpg';
port6 = new Image();
port6 = 'images/main/portrait-6.jpg';
land1 = new Image();
land1 = 'images/main/landscape-1.jpg';
land2 = new Image();
land2 = 'images/main/landscape-2.jpg';
land3 = new Image();
land3 = 'images/main/landscape-3.jpg';
land4 = new Image();
land4 = 'images/main/landscape-4.jpg';
land5 = new Image();
land5 = 'images/main/landscape-5.jpg';
land6 = new Image();
land6 = 'images/main/landscape-6.jpg';
land7 = new Image();
land7 = 'images/main/landscape-7.jpg';
land8 = new Image();
land8 = 'images/main/landscape-8.jpg';
jmc1 = new Image();
jmc1 = 'images/main/jmc-1.jpg';
jmc2 = new Image();
jmc2 = 'images/main/jmc-2.jpg';
jmc3 = new Image();
jmc3 = 'images/main/jmc-3.jpg';
jmc4 = new Image();
jmc4 = 'images/main/jmc-4.jpg';

setInterval('getPicture();', interval);

function getPicture()
{
	if (loadMainOK && posSel == 20) {selectPicture();}
}

function selectPicture() {
	do
	{
		picSel = Math.random();
		picSel = picSel * 10;
		picSel = Math.round(picSel);
	}
	while (picSel < 1 || picSel > 4);

	switch (picSel)
	{
		case 1:
			showPicPortL();
			break;
		case 2:
			showPicLscape();
			break;
		case 3:
			showPicPortR();
			break;
		case 4:
			showPicJmc();
	}
	
	do {
		interval = Math.random();
		interval = interval * 5000;
		interval = Math.round(interval);
	} while (interval < 2000);
}

function showPicPortL() {
	do
	{
		portLnr = Math.random();
		portLnr = portLnr * 10;
		portLnr = Math.round(portLnr);
	}
	while (portLnr < 1 || portLnr > 6 || portLnr == portRnr);
		
	portLnrStr = '' + portLnr;
	document.getElementById('picPortL').src = 'images/main/portrait-' +  portLnrStr +'.jpg';
}

function showPicLscape() {
	do
	{
		LscapeNr = Math.random();
		LscapeNr = LscapeNr * 10;
		LscapeNr = Math.round(LscapeNr);
	}
	while (LscapeNr < 1 || LscapeNr > 8);
		
	LscapeNrStr = '' + LscapeNr;
	document.getElementById('picLscape').src = 'images/main/landscape-' +  LscapeNrStr +'.jpg';
}

function showPicPortR() {
	do
	{
		portRnr = Math.random();
		portRnr = portRnr * 10;
		portRnr = Math.round(portRnr);
	}
	while (portRnr < 1 || portRnr > 6 || portRnr == portLnr);
		
	portRnrStr = '' + portRnr;
	document.getElementById('picPortR').src = 'images/main/portrait-' +  portRnrStr +'.jpg';
}

function showPicJmc() {
	do
	{
		JmcNr = Math.random();
		JmcNr = JmcNr * 10;
		JmcNr = Math.round(JmcNr);
	}
	while (JmcNr < 1 || JmcNr > 4);
	
	JmcNrStr = '' + JmcNr;
	document.getElementById('picJmc').src = 'images/main/jmc-' +  JmcNrStr +'.jpg';
}

