//http://www.javascripttoolbox.com/bestpractices/#all
//http://www.pageresource.com/jscript/jmath.htm
//http://www.comptechdoc.org/independent/web/cgi/javamanual/javadocument.html
//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
//http://www.yourhtmlsource.com/javascript/dhtmlexplained.html#WhatIsDHTML



var mouse_x = 0, mouse_y = 0;

function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function follow(evt) {if (document.getElementById) {var obj = document.getElementById(divName).style; obj.visibility = 'visible';
mouse_x = parseInt(mouseX(evt));
mouse_y = parseInt(mouseY(evt));}}

//document.onmousemove = follow;
                    




var headings = new Array();
var decorations = new Array();
var circle_centre_x = 500;
var circle_centre_y = 300;
var circle_radius   = 200; // base circle definitions off browser screen... update  compatibility for all browsers
var time_add = 0.0;
var factor = 0.3;
var decoration_factor = -1.5;
var decoration_circle_radius = 300;
var paused = false;

	var focus_elements = new Array();
	focus_elements[0] = "title";
	focus_elements[1] = "rose-centre";



function load() //make only execute after document.onload or something
	{
//	var this_link;
//	for (this_link in document.links)
//		{
//		if (document.links[this_link].className == "heading")
//			headings[headings.length] = document.links[this_link];
//		}

	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;
		}
	
	circle_centre_x = Math.round(myWidth / 2);
	circle_centre_y = Math.round(myHeight / 2);
	
	
	var this_div;
	var all_divs = document.getElementsByTagName('div');
	for (this_div in all_divs)
		{
		if (all_divs[this_div].className == "heading")
			headings[headings.length] = all_divs[this_div];
		if (all_divs[this_div].className == "decoration")
			decorations[decorations.length] = all_divs[this_div];
		}
	}

function moveheadings()
	{
	var this_heading;
	var this_decoration;

	var index;
	var a;
	var x, y, angle;
	
	for (this_heading in headings)
		{
		angle = (360 / headings.length) * -this_heading + Math.round(time_add);
		
		x = Math.round( circle_centre_x + circle_radius * Math.sin( angle * Math.PI/180) );
		y = Math.round( circle_centre_y + circle_radius * Math.cos( angle * Math.PI/180) );
		
		a = headings[this_heading];
		a.style.top  = (y - Math.round( a.offsetHeight / 2)) + "px";
		a.style.left = (x - Math.round( a.offsetWidth / 2))  + "px";
		}
	
	time_add = time_add + factor; // factor = {+1, 0, -1} relative to mousemoves
	
	for (this_decoration in decorations)
		{
		angle = (360 / decorations.length) * this_decoration + Math.round(time_add * decoration_factor);//mouse_x / mouse_y);
		
		//alert(angle + "   " + this_decoration);
		x = Math.round( circle_centre_x + decoration_circle_radius * Math.sin( angle * Math.PI/180) );
		y = Math.round( circle_centre_y + decoration_circle_radius * Math.cos( angle * Math.PI/180) );
		
		a = decorations[this_decoration];
		a.style.top  = (y - Math.round( a.offsetHeight / 2)) + "px";
		a.style.left = (x - Math.round( a.offsetWidth / 2))  + "px";
		}
		
	for (index in focus_elements)
		{
		a = document.getElementById(focus_elements[index]);
		a.style.top  = Math.round(circle_centre_y - Math.round( a.offsetHeight / 2)) + "px";
		a.style.left = Math.round(circle_centre_x - Math.round( a.offsetWidth / 2))  + "px";
		//if (Math.round(time_add * 3) % 630 == 66)
		//	alert(a.style.top + "   " + (circle_centre_y - a.offsetHeight));
		}
	
	test_pause();
	}


function test_pause() 
	{
	if (paused) 
		{
		setTimeout ( "test_pause()", 20 );
		}
	else	{
		setTimeout ( "moveheadings()", 20 );
		}
	}

	
setTimeout("load()", 1);
setTimeout("moveheadings()", 100 );

//setTimeout ( "alert(headings.length)", 1100);
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

//http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html


function find_client_width()
	{
	var viewportwidth;
	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
		{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
		}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
		{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
		}
 
	// older versions of IE
	
	else
		{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
	return viewportwidth;
	}

function find_client_height()
	{
	var viewportwidth;
	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
		{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
		}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
		{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
		}
 
	// older versions of IE
	
	else
		{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
	return viewportheight;
	}
//http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/


function resize()
	{
	circle_centre_x = Math.round( find_client_width() / 2);
	circle_centre_y = Math.round( find_client_height() / 2);
	}

function hoverlink_in()
	{
	paused = true;
	}
	
function hoverlink_out()
	{
	paused = false;
	}

//////////////mousemove events, lighting up of image border and text, and stopping of wheel
