function gid(id){return document.getElementById(id);}
function pulse(pulser){
	pulser.pulseIntervalName = setInterval(function(){pulseInterval(pulser);},100);
}

function pulseInterval(pulser){
	switch(pulser.opac_dir){
		case "git":
			pulser.opac_val -= 0.03;
			if(pulser.opac_val < 0.2){
				pulser.opac_dir ="come";
			}else{
				pulser.style.opacity = pulser.opac_val;
				pulser.style.filter = "alpha(opacity=" + (pulser.opac_val * 100) + ")";
			}			
		break;
		case "come":
			pulser.opac_val += 0.05;
			if(pulser.opac_val > 0.8){
				pulser.opac_dir ="git";
			}else{
				pulser.style.opacity = pulser.opac_val;
				pulser.style.filter = "alpha(opacity=" + (pulser.opac_val * 100) + ")";
			}
		break;
		default:
			pulser.opac_dir ="come";
			pulser.opac_val =0.0;
			pulser.style.opacity = "0.0";
			pulser.style.filter = "alpha(opacity=0)";
		break;
	}
}

function togCont(target,destination,sign_cs){
	target = gid(target);
	if(destination){
		target.toggleDestination = destination;
	}else{
		target.toggleDestination = target.scrollHeight
	}
	if(target.offsetHeight == 0){
		initToggle(target,"open",35);
		try{
			gid('plus'+sign_cs).style.display = 'none';
		}catch(e){}
	}else{
		initToggle(target,"close",35);
		try{
			gid('plus'+sign_cs).style.display = 'block';
		}catch(e){}
	}
}
function initToggle(element,direction,step){
	if(element.toggeling){
		//do nothing
	}else{
		element.toggeling = direction;
		element.toggleIntervalName = setInterval(function(){toggleElement(element,step);},35);
	}
}

function toggleElement(element,step){
	var msg = "";
	if(element.toggleIntervalName){
		switch(element.toggeling){
			case "open":
				if(element.toggleDestination > (element.offsetHeight + step)){
					element.style.height = (element.offsetHeight*1.0 + step) + "px";
					element.style.opacity = element.offsetHeight / element.toggleDestination;
					element.style.filter = "alpha(opacity=" + (element.style.opacity * 100) +")";
				}else{
					element.style.height = element.toggleDestination + "px";
					clearInterval(element.toggleIntervalName);
					element.style.opacity = "1.0";
					element.style.filter = "alpha(opacity=100)";
					element.toggeling = false;
				}
			break;
			case "close":
				if(element.offsetHeight > step){
					element.style.height = (element.offsetHeight*1.0 - step) + "px";
					element.style.opacity = element.offsetHeight / element.toggleDestination;
					element.style.filter = "alpha(opacity=" + (element.style.opacity * 100) +")";
				}else{
					element.style.opacity = "0.0";
					element.style.filter = "alpha(opacity=0)";
					element.style.height = "0px";
					clearInterval(element.toggleIntervalName);
					element.toggeling = false;
				}			
			break;
			default:
					clearInterval(element.toggleIntervalName);
					element.toggeling = false;				
			break;
		}
	}
}
function content_section_toggle_indicator_change(target,indicator){
	if(1){
	
	}
}


function animate_clients(num){
	var strip = gid('clients_slides_strip');
	if(strip){
		if(!strip.animating){
			if(document.clientsTimeout){
				clearTimeout(document.clientsTimeout);
			}
			strip.animating = true;
			write_client_information(num);
			strip.destination = ((-1000)*(num - 1));
			strip.step = parseInt(strip.destination - parseInt(strip.style.right.replace(/px/,''))) / 25;
			var clientsInterval = false;
			clientsInterval = setInterval(function(){animate_clients_act(strip,clientsInterval);},20);
			var clNum = gid("clients_slides_buttons").getElementsByTagName("SPAN").length;
			document.clientsTimeout = setTimeout(function(){animate_clients((num % clNum) + 1);},10000);
		}
	}
}

function animate_clients_act(strip,clientsInterval){
	if(clientsInterval){
		var right = parseInt(strip.style.right.replace(/px/,''));
		if((right + strip.step - strip.destination)/(right - strip.destination) > 0){
			strip.style.right  = right + strip.step + "px";
		}else{
			strip.style.right = strip.destination + "px";
			strip.animating = false;
			clearInterval(clientsInterval);
		}
	}
}

function write_client_information(num){
	var v_buttons = gid("clients_slides_buttons").getElementsByTagName("SPAN");
	var v_buttons_l = v_buttons.length;
	for(var i = 0; i < v_buttons_l; i++){
		v_buttons[i].className = v_buttons[i].className.replace(" on",'');	
	}
	v_buttons[num - 1].className = v_buttons[num - 1].className + " on";
	var t1 = gid("client_slide_text1");
	gid("clients_slide_click_capture").onclick = gid("client_img_" + num).onclick;
	t1.innerHTML = "";
	t1.destination = gid("client_text1_" + num).innerHTML;
	t1.inervalName = setInterval(function(){typeText(t1);},30);
	var t2 = gid("client_slide_text2");
	t2.innerHTML = "";
	t2.destination = gid("client_text2_" + num).innerHTML;
	t2.inervalName = setInterval(function(){typeText(t2);},30);
}

function typeText(t){
	if(t.inervalName){
		if(t.destination){
			t.innerHTML += t.destination.substr(0,1);
			 t.destination = t.destination.substr(1);
		}else{
			clearInterval(t.inervalName);
			t.inervalName = false;
		}
	}
}

function media_menu_select(tab,list){
	var lists = gid("media_center_list").childNodes;
	var lists_l = lists.length;
	for(var i = 0; i < lists_l; i++){
		if(lists[i].tagName == "UL"){
			if(lists[i].id == "list" + list){
				lists[i].style.display = "block";
			}else{
				lists[i].style.display = "none";
			}
		}
	}
	
	var tr = gid("media_center_menu_tabs_tr").childNodes;
	var tr_l = tr.length;
	for(i = 0; i < tr_l; i++){
		if(tr[i].tagName == "TD"){
			switch(tr[i].className){
				case "prev":
				case "next":
				case "none":
					tr[i].className = "none";
				break;
				default:
					tr[i].className = tr[i].className.replace(/\son/,'');
				break;
			}
		}
	}
	tab.className += " on";
	var start_bg = tab.previousSibling;
	while(start_bg.nodeType != 1){
		start_bg = start_bg.previousSibling;
	}
	var end_bg = tab.nextSibling;
	while(end_bg.nodeType != 1){
		end_bg = end_bg.nextSibling;
	}
	start_bg.className += " on";
	end_bg.className += " on";
	var prev = start_bg.previousSibling;
	if(prev){
		while(prev.nodeType != 1){
			prev = prev.previousSibling;
		}
		if(prev){
			prev.className = "prev";
		}
	}
	var next = end_bg.nextSibling;
	if(next){
		while(next.nodeType != 1){
			next = next.nextSibling;
		}
		if(next){
			next.className = "next";
		}
	}
}