var image = new Array();
var over_image = new Array();

var	kicking_id;
var	kicking_status = 'stop';
var	kicking_flag = 0;
var menu_pad = 6;
var brace_active = 0;

var xmlHttp = createXmlHttpRequestObject();
var xmltext = '';
var xmlsection = '';

function loadImages()
{
	
	if (document.getElementById)
	{
		document.getElementById('hidepage').style.visibility = 'hidden';
	}
	else
	{
		if (document.layers)
		{
			document.hidepage.visibility = 'hidden';
		}
		else
		{ 
			document.all.hidepage.style.visibility = 'hidden';
		}
	}
	
	initEffects();	
	
	image[0] = new Image();
	image[0].src = siteurl + "/images/close.gif";
	over_image[0] = new Image();
	over_image[0].src = siteurl + "/images/close2.gif";
	
	document.getElementById("menu").onmouseout = menu_kicking_stop_all;
	
}

function initEffects()
{
	
	ob_table = new fx.Opacity($("table"), {duration:1000});
	
	ob_logo = new fx.Width($("logo"), {duration:600});

	ob_zebra_top = new fx.Width($("zebra_top"), {duration:500});
	ob_sun = new fx.Opacity($("sun"), {duration:500});
	ob_section_title = new fx.Width($("section_title"), {duration:500});
	ob_text = new fx.Opacity($("text_block"), {duration:700});
	ob_bright_stripe = new fx.Opacity($("bright_stripe"), {duration:1000});
	ob_orange_stripe = new fx.Width($("orange_stripe"), {duration:800, transition: fx.linear});
	ob_green_stripe = new fx.Width($("green_stripe"), {duration:300, transition: fx.linear});
	
	ob_menu_manual = new fx.Width($("menu_manual"), {duration:300, transition: fx.circ, onComplete: function(){ ob_menu_zebra_story.custom(0, 186);	}});
	ob_menu_zebra_story = new fx.Width($("menu_zebra_story"), {duration:300, transition: fx.circ, onComplete: function(){ ob_menu_fun_games.custom(0, 128);	}});
	ob_menu_fun_games = new fx.Width($("menu_fun_games"), {duration:300, transition: fx.circ, onComplete: function(){ ob_menu_brace_painter.custom(0, 147);	}});
	ob_menu_brace_painter = new fx.Width($("menu_brace_painter"), {duration:300, transition: fx.circ, onComplete: function(){ ob_menu_home.custom(0, 77);	}});
	ob_menu_home = new fx.Width($("menu_home"), {duration:300, transition: fx.circ, onComplete: function(){ ob_text.toggle(); }});
	
	ob_section_title = new fx.Width($("section_title"), {duration:500});

	start_effect();
}

function start_effect()
{
	ob_table.hide();
	
	ob_logo.hide();

	ob_zebra_top.hide();
	ob_sun.hide();
	ob_section_title.hide();
	ob_text.hide();
	ob_bright_stripe.hide();
	ob_orange_stripe.hide();
	ob_green_stripe.hide();
	
	ob_menu_manual.hide();
	ob_menu_zebra_story.hide();
	ob_menu_fun_games.hide();
	ob_menu_brace_painter.hide();
	ob_menu_home.hide();

	step1();
}

function step1()
{
	ob_table.toggle();	
	setTimeout("step2()", 1000);
}

function step2()
{
	ob_logo.custom(0, 206);	
	setTimeout("step3()", 600);
	
}
function step3()
{
	ob_zebra_top.custom(0, 581);
	setTimeout("step4()", 500);
}
function step4()
{
	ob_sun.toggle();
	ob_bright_stripe.toggle();
	ob_orange_stripe.custom(0, 585);
	setTimeout("step5()", 500);
}
function step5()
{
	ob_green_stripe.custom(0, 189);
	ob_section_title.custom(0, 250);
	ob_menu_manual.custom(0, 249);
}

function menu_kicking()
{
	if (kicking_status != 'stop')
	{					
		if (kicking_status == 'up')
		{	
			if (menu_pad == 2) kicking_status = 'down';
			else menu_pad -= 1;		
		}
		if (kicking_status == 'down')
		{
			if (menu_pad == 11) kicking_status = 'up';
			else menu_pad += 1;
		}
		if (kicking_id) document.getElementById(kicking_id).style.paddingTop = menu_pad;
		setTimeout("menu_kicking()", 15);
	}
}

function menu_kicking_start(id)
{
	kicking_id = id;
	setTimeout("menu_kicking_start2()", 50);
}

function menu_kicking_start2()
{
	if (kicking_flag == 0 && kicking_id)
	{
		kicking_status = 'stop';
		menu_pad = 6;

		document.getElementById(kicking_id).style.paddingTop = menu_pad;
		kicking_flag = 1;
		setTimeout("kicking_status = 'up';", 15);
		setTimeout("menu_kicking('" + kicking_id + "')", 50);
	}
}

function menu_kicking_stop()
{
	kicking_status = 'stop';
	kicking_flag = 0;
	document.getElementById(kicking_id).style.paddingTop = 6;
}

function menu_kicking_stop_all()
{
	kicking_id = 0;
	kicking_flag = 0;
	kicking_status = 'stop';
}

function createXmlHttpRequestObject()
{
   var xmlHttp;
   if(window.ActiveXObject)
   {
	  try
	  {
		 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  catch (e)
	  {
		 xmlHttp = false;
	  }
   }
   else
   {
	  try
	  {
		 xmlHttp = new XMLHttpRequest();
	  }
	  catch (e)
	  {
		 xmlHttp = false;
	  }
   }
   if (!xmlHttp)
	  alert("Error creating the XMLHttpRequest object.");
   else
	  return xmlHttp;
}

function handleServerResponse()
{
   if (xmlHttp.readyState == 4)
   {
	  if (xmlHttp.status == 200)
	  {
	  	try
		{					
			xmlResponse = xmlHttp.responseXML;
 			xmlDoc = xmlResponse.documentElement;
			xmltext = xmlDoc.getElementsByTagName('text')[0].firstChild.data;		
			xmlsection  = xmlDoc.getElementsByTagName('section')[0].firstChild.data;
			change_content2();
		}
		catch (e)
		{
			alert("Error reading the responce: " + e.toString());
		}
	  }
	  else
	  {
		 alert("There was a problem accessing the server: " + xmlHttp.statusText);
	  }
   } 
}

function change_content(id)
{
	if (brace_active == 0)
	{
		document.getElementById("text").innerHTML = '<img src="' + siteurl + '/images/indicator.gif" alt="" /> Loading...</div>';
		xmlHttp.open("GET", siteurl + "/update_content.php?id=" + id, true);
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	else
	{
		bracepainter_close();
		setTimeout("change_content('" + id + "');", 2000);
	
	}
}

function change_content2(request)
{
		ob_section_title.custom(250, 0);
		setTimeout("ob_text.hide();", 500);
		setTimeout("document.getElementById('text').innerHTML = xmltext;", 550);
		setTimeout("document.getElementById('section_title').innerHTML = '<nobr>" + xmlsection + "</nobr>';", 550);	
		setTimeout("ob_text.toggle();", 600);	
		setTimeout("ob_section_title.custom(0, 250)", 600);
		
}

function bracepainter_open()
{
	if (brace_active == 0)
	{
		brace_active = 1;
	
		ob_main_block = new fx.Opacity($("main_block"), {duration: 1000});
		ob_bracepainter = new fx.Width($("bracepainter"), {duration: 1000});
			
		ob_main_block.toggle();
		setTimeout("bracepainter_open2()", 1000);
		
	}
}

function bracepainter_open2()
{
	
	document.getElementById("main_block").style.display = "none";
	document.getElementById("bracepainter").style.display = "block";
	ob_bracepainter.hide();;
	ob_bracepainter.custom(30, 787);

	setTimeout("show_bracepainter_flash()", 1000);
}

function show_bracepainter_flash()
{
	document.getElementById("bracepainter-flash").innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="535" height="288" id="braces" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + siteurl + '/flash/braces.swf" /><param name="flashvars" value="xmlsource1=' + siteurl + '/flash/xml/menu_top.xml&xmlsource=' + siteurl + '/flash/xml/menu_colors.xml&xmlsource2=' + siteurl + '/flash/xml/xmlhint.xml" /><param name="quality" value="high" /><param name="bgcolor" value="#f4f4f4" /><embed src="' + siteurl + '/flash/braces.swf" flashvars="xmlsource1=' + siteurl + '/flash/xml/menu_top.xml&xmlsource=' + siteurl + '/flash/xml/menu_colors.xml&xmlsource2=' + siteurl + '/flash/xml/xmlhint.xml" quality="high" bgcolor="#f4f4f4" width="535" height="288" name="braces" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}

function bracepainter_close()
{
	document.getElementById('bracepainter-flash').innerHTML = '';
	ob_bracepainter.custom(787, 20);
	setTimeout("document.getElementById('bracepainter').style.display = 'none';", 1000);
	setTimeout("document.getElementById('main_block').style.display = 'block';", 1000)
	setTimeout("ob_main_block.toggle();", 1000);
	
	brace_active = 0;
}

function roll_out(id)
{
	if (document.images)
	{
		document.images['image_' + id].src = image[id].src;
	}	
}

function roll_over(id)
{
	if (document.images)
	{
		document.images['image_' + id].src = over_image[id].src;
	}
}