var thread = true;
function fading_department(){
	curr_department_obj = document.getElementById("curr_department");
	if (get_thread() && curr_department_obj)
	{
	
		curr_id = document.getElementById("curr_department").value;
		size_id = document.getElementById("sizeofdepartment").value;
		
		current = parseInt(curr_id);
		size	= parseInt(size_id)
		old_id  = current - 1;
		if (current >= size)
		{
			current = 0;
		}
		curr_div = document.getElementById("department_"+current);
		hover_class = document.getElementById("department_link_"+current);
		
		old = document.getElementById("department_"+old_id);
		old_hover_class = document.getElementById("department_link_"+old_id);
		if (curr_div)
		{
			if (old)
			{
				old.style.display = 'none';
				old_hover_class.className = 'arrow';
				instantset(old);
			}
			
			curr_div.style.display = 'block';
			
			hover_class.className = 'arrow_department';
			//fade_start(curr_div);
			browserdetect=curr_div.filters? "ie" : typeof curr_div.style.MozOpacity=="string"? "mozilla" : ""
			highlighting=setInterval("gradualfade(curr_div)", 300);
			document.getElementById("curr_department").value = parseInt(current) + 1;
			setTimeout("fading_department()", 5000);
			
		}
	}
	
}

function set_departments(id){
	set_thread(false);
	for (i=0; i<parseInt(document.getElementById("sizeofdepartment").value); i++)
	{
		document.getElementById("department_"+i).style.display = 'none';
	}
	obj = document.getElementById("department_"+id);
	browserdetect=curr_div.filters? "ie" : typeof curr_div.style.MozOpacity=="string"? "mozilla" : ""
	highlighting=setInterval("gradualfade(obj)", 300);
	obj.style.display = 'block';
	document.getElementById("curr_department").value = parseInt(id) + 1;
	set_thread(true);
}
function set_thread(obj){
	var thread = obj;
}
function get_thread(){
	return thread;
}

function gradualfade(cur2){
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
	cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
	else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
	cur2.filters.alpha.opacity+=20
	else if (window.highlighting)
	clearInterval(highlighting)
}

function instantset(textcontainerobj){
	if (browserdetect=="mozilla")
	textcontainerobj.style.MozOpacity=1;
	else if (browserdetect=="ie")
	textcontainerobj.filters.alpha.opacity=10;
}


/*   News  */

function goto_news(){
	
	if (document.getElementById("news_link") && document.getElementById("news_link").value && document.getElementById("news_link").value.indexOf("_") != -1)
	{
		news_link_array = document.getElementById("news_link").value.split("_");
		window.location = 'index.php?do=category&id='+news_link_array[1]+'&pageid='+news_link_array[0];
	}
}


temp=""
nextchar=-1;
nextline=1;
cursor="\\"
function animate(){
	document.getElementById("news_link").value=line_link[nextline];
	if (temp==line[nextline] & temp.length==line[nextline].length & nextline!=lines){
		nextline++;
		nextchar=-1;
		document.bannerform.banner.value=temp;
		
		temp="";
		setTimeout("nextstep()",1000)}
	else if (nextline==lines & temp==line[nextline] & temp.length==line[nextline].length){
		nextline=1;
		nextchar=-1;
		document.bannerform.banner.value=temp;
		temp="";
		setTimeout("nextstep()",1000)}
	else{
		nextstep()
	}
}

function nextstep(){

	if (cursor=="\\"){
		cursor="|"}
	else if (cursor=="|"){
		cursor="/"}
	else if (cursor=="/"){
		cursor="-"}
	else if (cursor=="-"){
		cursor="\\"}

	nextchar++;
	temp+=line[nextline].charAt(nextchar);
	document.bannerform.banner.value=temp+cursor
	setTimeout("animate()",75)
}


//if IE 4+ or NS6

//if IE 4+ or NS6
	if (document.all||document.getElementById)
	window.onload=animate
