// JavaScript Document

function flashTopic(topic){	
	AC_FL_RunContent(
		"codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0",
		"width", "550",
		"height", "100",
		"src", "topic",
		"quality", "best",
		"pluginspage", "http://www.adobe.com/go/getflashplayer_de",
		"align", "middle",
		"play", "true",
		"loop", "true",
		"scale", "showall",
		"wmode", "transparent",
		"devicefont", "false",
		"id", "topic",
		"bgcolor", "#006130",
		"name", "topic",
		"menu", "false",
		"allowFullScreen", "false",
		"allowScriptAccess","sameDomain",
		"movie", "topic",
		"salign", "",
		"flashvars","topic="+topic
		); //end AC code

}

var fade = false;
var fade2 = false;
var fadeStatus=100;

function fadeIn(obj,target,add,last,control){
	control = control || 0;
	if (control == 'x' || control == 1){
		last = fadeStatus;
	}
	 
	if (control == 0 || control == 'x'){fade = true; fade2 = false;}
	 if (!fade2){
	fade = true;
	if (last < target){
	document.getElementById(obj).setAttribute('style','filter:alpha(opacity='+last+');-moz-opacity:'+(last/100)+';opacity:'+(last/100)+';');
	last += add;
	fadeStatus = last;
	window.setTimeout('fadeIn("'+obj+'",'+target+','+add+','+last+',1)',50);
	}else{
		fade = false;
		document.getElementById(obj).setAttribute('style','filter:alpha(opacity='+target+');-moz-opacity:'+(target/100)+';opacity:'+(last/100)+';');
		fadeStatus = target;
	}
	}
	
}

function fadeOut(obj,target,add,last,control){
	control = control || 0;
	if (control == 'x' || control == 1){
		last = fadeStatus;
	}
	if (control == 0 || control == 'x'){fade2 = true;fade = false;}
	if (!fade){
	if (last > target){
	document.getElementById(obj).setAttribute('style','filter:alpha(opacity='+last+');-moz-opacity:'+(last/100)+';opacity:'+(last/100)+';');
	last -= add;
	fadeStatus = last;
	window.setTimeout('fadeOut("'+obj+'",'+target+','+add+','+last+')',50);
	}else{
		fade2 = false;
		document.getElementById(obj).setAttribute('style','filter:alpha(opacity='+target+',1);-moz-opacity:'+(target/100)+';opacity:'+(last/100)+';');
		fadeStatus = target;
	}
	}
	
	
}




function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}


function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
	
	
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}


function changePic(obj,pic){
	pic = pic || 'pic';
	document.getElementById(pic).src = obj.firstChild.src;
	
}

function showHide(obj){
	
	var allDivs = document.getElementsByTagName('div');
	var allAs = document.getElementsByTagName('a');
	
	for (i=0;i < allDivs.length;i++){
		if (allDivs[i].className == 'show'){
			allDivs[i].className = 'hide';
		}
	}

	for (i=0;i < allAs.length;i++){
		if (allAs[i].className == 'show'){
			allAs[i].className = 'hide';
		}
	}

	obj.className = 'show';
	if (document.getElementById(obj.name).className == 'hide'){
	document.getElementById(obj.name).className = 'show';
	}
	
}

function rise(obj,startX,endX,startY){
	if (startX < endX){
		document.getElementById(obj).style.bottom = startX+'px';
		document.getElementById(obj).style.left = startY+'px';
		startX+=2;
		startY-=2;
		
		window.setTimeout('rise("'+obj+'",'+startX+','+endX+','+startY+')',50);
	}	
}
