//culorile initiale
oldColors = new Array();

function HexToRgb(color)
{
	r = parseInt(color.substr(1,2), 16);
	g = parseInt(color.substr(3,2), 16);
	b = parseInt(color.substr(5,2), 16);
	return "rgb(" + r + ", " + g + ", " + b + ")";
}

//culorile initiale
function initColors(color1, color2, color3)
{
	if(navigator.appName == "Netscape")
	{
		if(color1 != "")
		{
			oldColors[0] = HexToRgb(color1);
		}
		if(color2 != "")
		{
			oldColors[1] = HexToRgb(color2);
		}
		if(color3 != "")
		{
			oldColors[2] = HexToRgb(color3);
		}
	}
	else
	{
		if(color1 != "")
		{
			oldColors[0] = color1;
		}
		if(color2 != "")
		{
			oldColors[1] = color2;
		}
		if(color3 != "")
		{
			oldColors[2] = color3;
		}
	}
}

function testColors(color)
{
	if(navigator.appName == "Netscape")
	{
		if(HexToRgb(color) == oldColors[0] || HexToRgb(color) == oldColors[1] || HexToRgb(color) == oldColors[2])
		{
			last_letter = new Array();
			last_letter = color.charAt(6);
			color = color.substr(0,6) + last_letter.replace(last_letter, "7");
			if(HexToRgb(color) == oldColors[0] || HexToRgb(color) == oldColors[1] || HexToRgb(color) == oldColors[2])
			{
				color = color.substr(0,6) + last_letter.replace(last_letter, "8");
			}
			if(HexToRgb(color) == oldColors[0] || HexToRgb(color) == oldColors[1] || HexToRgb(color) == oldColors[2])
			{
				color = color.substr(0,6) + last_letter.replace(last_letter, "9");
			}
		}
	}
	else
	{
		if(color == oldColors[0] || color == oldColors[1] || color == oldColors[2])
		{
			last_letter = new Array();
			last_letter = color.charAt(6);
			color = color.substr(0,6) + last_letter.replace(last_letter, "7");
			if(color == oldColors[0] || color == oldColors[1] || color == oldColors[2])
			{
				color = color.substr(0,6) + last_letter.replace(last_letter, "8");
			}
			if(color == oldColors[0] || color == oldColors[1] || color == oldColors[2])
			{
				color = color.substr(0,6) + last_letter.replace(last_letter, "9");
			}
		}
	}
	return color;
}

//seteaza culoarea
function setStyle(color1, color2, color3)
{
	newColors = new Array();
	newColors[0] = color1.toLowerCase();
	newColors[1] = color2.toLowerCase();
	newColors[2] = color3.toLowerCase();
	
	if (document.styleSheets[1].cssRules)
	{
		theStyle = document.styleSheets[1].cssRules;
	}
	//pentru explorer
	else if (document.styleSheets[1].rules)
	{
		theStyle = document.styleSheets[1].rules;
	}
	
	for(k=0;k<3;k++)
	{
		if(newColors[k] != "")
		{
			newColors[k] = testColors(newColors[k]);
			for(i=0;i<theStyle.length;i++)
			{
				//background
				if(theStyle[i].style.backgroundColor == oldColors[k])
				{
					theStyle[i].style.backgroundColor = newColors[k];
				}
				//color
				if(theStyle[i].style.color == oldColors[k])
				{
					theStyle[i].style.color = newColors[k];
				}
				//border
				if(theStyle[i].style.borderLeftColor == oldColors[k])
				{
					theStyle[i].style.borderLeftColor = newColors[k];
				}
				if(theStyle[i].style.borderRightColor == oldColors[k])
				{
					theStyle[i].style.borderRightColor = newColors[k];
				}
				if(theStyle[i].style.borderTopColor == oldColors[k])
				{
					theStyle[i].style.borderTopColor = newColors[k];
				}
				if(theStyle[i].style.borderBottomColor == oldColors[k])
				{
					theStyle[i].style.borderBottomColor = newColors[k];
				}
			}
		}
	}
	initColors(newColors[0], newColors[1], newColors[2]);
}

function show(id)
{
	if(document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "block";
	}
	else
	{
		document.getElementById(id).style.display = "none";
	}
}

function changeDescription(nr)
{
	if(nr == 1)
	{
		document.getElementById("descriere").innerHTML = "Background-ul si titlurile.";
	}
	else if(nr == 2)
	{
		document.getElementById("descriere").innerHTML = "Link-urile."
	}
	else if(nr == 3)
	{
		document.getElementById("descriere").innerHTML = "Link-urile din meniul din dreapta."
	}
	else
	{
		document.getElementById("descriere").innerHTML = "&nbsp;";
	}
}

function slide_down()
{
	//document.getElementById("change_colors").style.display = "block";
	new Effect.SlideDown(document.getElementById("change_colors"), {duration: 0.3});
}

function slide_up()
{
	//document.getElementById("change_colors").style.display = "block";
	new Effect.SlideUp(document.getElementById("change_colors"), {duration: 0.3});
}