// general vars
var cl_w = 0, cl_h = 0, menu_width = 133, footers_height = 150;
var isIE = navigator.userAgent.indexOf("MSIE")>=0, 
isOpera = navigator.userAgent.indexOf("Opera")>=0, 
isFirefox = navigator.userAgent.indexOf("Firefox")>=0;

// "display" vars
var disp_init = false, 
disp_x = 660, 
disp_y = 60, 
img_arr, 
delay_arr, 
curr_frame = 0;

// handler of resize
window.onresize = windowResize;
	
function Int(val)
{
	return val - 0;
}

function contentWidth()
{
	return cl_w - menu_width;
}

function setFootersHeight(val)
{
	footers_height = Int(val);
}

function contentResize()
{
	var content = document.all.item("content");
	if ( content != null )
	{
		content.style.height = cl_h - footers_height;
	}
}	
	
function emailClick( account )
{
	var URL = "mailto:" + account + "@" + "bogemic.com";
	window.location = URL;
}
	
function getTickCount()
{
	var d = new Date();
	var ms = 0;
	ms += d.getHours() * 60 * 60 * 1000;
	ms += d.getMinutes() * 60 * 1000;
	ms += d.getSeconds() * 1000;
	ms += d.getMilliseconds();
	return ms;
}

// this function sets two global vars upon exit: cl_w - window client width, cl_h - window client height
function getWindowSize() 
{
  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;
  }
  
  // correct size for Opera and Firefox
  if ( isOpera )
  {
	myWidth = myWidth - 18;
  }
  else if ( isFirefox )
  {
	myWidth = myWidth - 24;
  }
  
  cl_w = myWidth;
  cl_h = myHeight;
}
 
function windowResize()
{
	getWindowSize();
	displaySetPos();
	contentResize();
}

function displaySetPos()
{
	// set position for "display"
	var d = document.all.item("display");
	if ( d != null )
	{
		if ( cl_w > contentWidth() )
		{
			d.style.left = ( cl_w - contentWidth() ) / 2 + disp_x;
		}
		else
		{
			d.style.left = disp_x;
		}
		
		d.style.top = disp_y;
		d.style.visibility = "visible";
	}
}

function displayInit()
{
	var i, img = document.all.item("disp_img");

	if ( disp_init )
		return;
	
	disp_init = true;
	
	// preload images
	img_arr = new Array();
	delay_arr = new Array();
	
	for( i = 0 ; i < 16; i++ )
	{
		img_arr[i] = new Image; 
		
		if ( i < 10 )
			img_arr[i].src = img.alt + "/000" + i + ".png";
		else
			img_arr[i].src = img.alt + "/00" + i + ".png";
			
		if ( i % 4 )
		{
			delay_arr[i] = 100;
		}
		else
		{
			if ( i % 8 )
			{
				delay_arr[i] = 1000;
			}
			else
			{
				delay_arr[i] = 10000;
			}
		}
    }

	//debugger;
	windowResize();
	img.src = img_arr[curr_frame].src;
	img.alt = "";
	displayStartTimer( delay_arr[curr_frame] );
}

function displayOnTimer()
{
	var img = document.all.item("disp_img");
	if ( img == null )
		return;
	
	curr_frame++;
	if ( curr_frame == 16 )
		curr_frame = 0;
		
    img.src = img_arr[curr_frame].src;
	displayStartTimer( delay_arr[curr_frame] );
}

function displayStartTimer( delay )
{
    self.setTimeout( "displayOnTimer()", delay );
}