var isIE = false;
if (navigator.appVersion.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1){
	isIE = true;
}

function code_div_mouse_over()
{
	if (this.style.background == '' || this.style.background == '#fff' || this.style.background == '#ffffff' || this.style.background == 'rgb(255, 255, 255) none repeat scroll 0% 0%' || this.style.background == 'none repeat scroll 0% 0% rgb(255, 255, 255)' || this.style.background == 'rgb(255, 255, 255)')
		this.style.background = '#ddd';
}

function code_div_mouse_out()
{
	//rgb(221, 221, 221) none repeat scroll 0%
	if (this.style.background == '#ddd' || this.style.background == '#dddddd' || this.style.background == 'rgb(221, 221, 221) none repeat scroll 0% 0%' || this.style.background == 'none repeat scroll 0% 0% rgb(221, 221, 221)' || this.style.background == 'rgb(221, 221, 221)')
		this.style.background = '#fff';
}

function code_div_mouse_click()
{
	//alert(this.style.background);
	
	if (this.style.background != '#ffbebe' && this.style.background != 'rgb(255, 190, 190) none repeat scroll 0% 0%' && this.style.background != 'none repeat scroll 0% 0% rgb(255, 190, 190)' && this.style.background != 'rgb(255, 190, 190)')
		this.style.background = '#ffbebe';
	else
		this.style.background = '#fff';
		
	//hash highlighting
	var hash = '';
	var divs = document.getElementById("codeContainer").firstChild.firstChild.getElementsByTagName("div");
	for (i =0; i < divs.length; i++)
	{
		if (divs[i].style.background == '#ffbebe' || divs[i].style.background == 'rgb(255, 190, 190) none repeat scroll 0% 0%' || divs[i].style.background == 'none repeat scroll 0% 0% rgb(255, 190, 190)' || divs[i].style.background == 'rgb(255, 190, 190)')
		{
			hash += (i + 1)+',';
		}		
	}

	if (hash != '' || location.hash != '')
		location.hash = '#'+hash.substr(0,hash.length-1);
}

function set_codeContainer_mouseover()
{
	var highlight = new Array();
	if (location.hash != '')
	{		
		e = location.hash.substr(1).split(",");
		
		for (i = 0; i < e.length; i++)
		{
			highlight[e[i]] = 1;
		}
	}
	
	var divs = document.getElementById("codeContainer").firstChild.firstChild.getElementsByTagName("div");
	for (i =0; i < divs.length; i++)
	{
		divs[i].onmouseover=code_div_mouse_over;
		divs[i].onmouseout=code_div_mouse_out;
		
		divs[i].onmousedown=code_div_mouse_click;
		
		if (highlight[i] == 1 && i > 0)
		{
			divs[(i - 1)].style.background = '#ffbebe';
		}
	}
}

var showCode = false;
function show_hide_code()
{
	if (showCode)
	{
		document.getElementById("codeContainer").style.display = "block";
		document.getElementById("show_hide_img").src = "/images/bullet_arrow_down.png";
	}
	else
	{
		document.getElementById("codeContainer").style.display = "none";
		document.getElementById("show_hide_img").src = "/images/bullet_arrow_up.png";
	}

	position_footerBar();

	showCode = !showCode;
}

function position_footerBar()
{
	//alert(document.getElementById("menu").offsetHeight);
	//searchContainer
//	isIE = true;
	if (document.getElementById("menu").offsetHeight > (document.getElementById("content").offsetHeight + document.getElementById("searchContainer").offsetHeight) && !isIE)
	{	
		//alert(1);
			
		document.getElementById("footerbar").style.position = "absolute";
		document.getElementById("footerbar").style.top = (document.getElementById("menu").offsetHeight + 27) + "px";
	}
	else if (document.getElementById("footerbar").style.position == "absolute" && !isIE)
	{
		document.getElementById("footerbar").style.top = (document.getElementById("content").offsetHeight + 27) + "px";
	}
}

function select_syntax()
{
	if (isIE)
	{
		document.getElementById("select-table").deleteRow(document.getElementById("select-style").rowIndex);
		document.getElementById("select-syntax").style.display = 'block';
	}
	else {
		document.getElementById("select-style").innerHTML = '';
		document.getElementById("select-syntax").style.display = 'table-row';
	}
}

function fix_archive_table_container()
{
	//alert(document.getElementById("content").clientHeight);
	
	var rows = document.getElementsByName("archiveTable");
	var height = 0;
	for (i = 0; i < rows.length; i++)
	{
		if (height < rows[i].clientHeight)
		{
			height = rows[i].clientHeight;
		}
	}
	
	document.getElementById("content").style.height = (document.getElementById("content").clientHeight + height) + "px";
}

