/**
*  prehome.js
*  klmcorp version 0.0.1
*
*  Created by Klem % KLM on 15/05/07.
*  Copyright 2007 klm. All rights reserved.
*
*/


/**
* Microsoft (JScript 5.6)
* Activates conditional compilation support.
*/
var isMSIE = false;
var isMSIE7 = false;
/*@cc_on
isMSIE = true;
@if (@_jscript_version >= 5.7)
	isMSIE7 = true;
@end
@*/

var colors = new Array('#FF6600', '#FF3399', '#6699FF', '#000000', '#999999', '#FFFFFF');

var enterframe = 0;
var direction = 1;
var totalWidth = 200;
var beginWidth = 100;
var minWidth = 0;
if(isMSIE) minWidth = 10;
var stepper = 1;
var color1 = Math.round(Math.random()*6);
var color2 = Math.round(Math.random()*6);
while(color2 == color1){
	color2 = Math.round(Math.random()*6);
}
function startAnim()
{
	document.getElementById('text_right').innerHTML = document.getElementById('text_left').innerHTML;
	document.getElementById('mask_left').style.width= beginWidth+'px';
	document.getElementById('mask_right').style.width= beginWidth+'px';
	document.getElementById('mask_right').style.left= beginWidth+'px';
	document.getElementById('content_right').style.left= '0px';
	enterframe = window.setInterval('animateMask()',10);
}

function myParseInt(s)
{
	if(s.substr(0,1) == "-")
		return -parseInt(s.substr(1,s.length), 10);
	else
		return parseInt(s, 10);
}

function animateMask()
{
	if(direction == 1){
		var left = totalWidth - (myParseInt(document.getElementById('mask_right').style.width) + stepper);
		document.getElementById('text_right').style.left = (myParseInt(document.getElementById('text_right').style.left) + stepper) + 'px';
	}
	else{
		var left = totalWidth - (myParseInt(document.getElementById('mask_right').style.width) - stepper);
		document.getElementById('text_right').style.left = (myParseInt(document.getElementById('text_right').style.left) - stepper) + 'px';
	}
	var right = totalWidth - left;
	document.getElementById('mask_left').style.width = left+'px';
	document.getElementById('content_left').style.width = left+'px';
	document.getElementById('mask_right').style.width = right+'px';
	document.getElementById('content_right').style.width = right+'px';
	document.getElementById('mask_right').style.left = left+'px';			
	if((left == (totalWidth-minWidth)) || (left == minWidth))
	{
		direction *= -1;
		if(left == minWidth)
		{
			var tmp = Math.round(Math.random()*6);
			while((tmp == color1) || (tmp == color2)){
				tmp = Math.round(Math.random()*6);
			}			
			var tmp2 = Math.round(Math.random()*6);
			while((tmp2 == color1) || (tmp2 == color2) || (tmp2 == tmp)){
				tmp2 = Math.round(Math.random()*6);
			}
			color1 = tmp;
			color2 = tmp2;
			document.getElementById('mask_left').style.backgroundColor = colors[color2];
			document.getElementById('text_left').style.color = colors[color1];
		}
		else
		{
			document.getElementById('mask_right').style.backgroundColor = colors[color1];
			document.getElementById('text_right').style.color = colors[color2];
		}
	}
	
}
