var currentSection = "frame0"; // The default loaded section on the page
var lastSection = "";
var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function to_back(target_what){
	 if (target_what != currentSection) document.getElementById('button-'+target_what).className='menu_normal';
}
function to_front(target_what){
	 document.getElementById('button-'+target_what).className='menu_over';
	 //onMouseOut="this.parentNode.className='menu_normal';"
}


function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}
function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )
	return Array(elemX, elemY);
}

	var scrollArea = 'content';
	var offset = 'frame0';

function ScrollSection(link)
{
	// Store the last section, and update the current section
	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	to_back(lastSection);
	to_front(currentSection);

	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	offsetPos = findElementPos(document.getElementById(offset));
	position[0] = position[0] - offsetPos[0];
	scrollStart(theScroll, -theScroll.style.left.split("px")[0], position[0], 'horiz');
}

function scrollStart(elem, start, end, type)
{
	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
	if (type == 'horiz') scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	else if (type == 'vert') scrollanim.timer = setInterval("scrollVertAnim();", 15);
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.style.left = -move+'px';
		scrollanim.time++;
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
		window.show_contact_t = true;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.style.bottom = move+'px';
		scrollanim.time++;
	}
}


/*
if (document.all) window.onscroll = move_info
else setInterval('move_info()', 100);
function move_info(){
	if (document.all) dim_scroll = 0;
	else if (document.getElementById) dim_scroll = window.pageYOffset;
	document.getElementById('floater_info').style.top = 30+dim_scroll;
}
 */

window.show_contact_t = false;
if (document.all) window.onscroll = move_contact
else setInterval('move_contact()', 100);
function move_contact(){
	if (window.show_contact_t){
		if (document.all)dim_scroll = 0;
		else if (document.getElementById) dim_scroll = window.pageYOffset;
		document.getElementById('contact').style.bottom = -dim_scroll;
	}
}
function hide_contact(){
   	window.show_contact_t = false;
	document.getElementById('contact').style.display = "none";
	document.getElementById('contact').style.bottom = "-500px" 
}
function show_contact(tip_comentariu){
	window.show_contact_t = false;
	document.getElementById('contact_form').style.display = "block";
	document.getElementById('contact_mesaj').style.display = "none";

	if (tip_comentariu=='intrebare'){
		document.getElementById('tip_comentariu').value = tip_comentariu;
		document.getElementById('titlu_contact').innerHTML = 'Mai multe informatii...';
		document.getElementById('title_tip_comentariu').innerHTML = 'Intrebarea dumneavoastra:';
	}
	else if (tip_comentariu=='consultanta'){
		document.getElementById('tip_comentariu').value = tip_comentariu;
		document.getElementById('titlu_contact').innerHTML = 'Mai multe informatii...';
		document.getElementById('title_tip_comentariu').innerHTML = 'Intrebarea dumneavoastra:';
	}
	else if (tip_comentariu=='parere'){
		document.getElementById('tip_comentariu').value = tip_comentariu;
		document.getElementById('titlu_contact').innerHTML = 'Rubrica pareri si sugestii';
		document.getElementById('title_tip_comentariu').innerHTML = 'Ce parere ati avut despre hotspoturile Welle?';
	}

	if (document.all) dim_scroll = 0;
	else if (document.getElementById) dim_scroll = window.pageYOffset;
	document.getElementById('contact').style.display = "block";
	h_element = document.getElementById('contact').clientHeight;
	document.getElementById('contact').style.left = (document.body.clientWidth -  document.getElementById('contact').clientWidth)/2 + 'px';
	scrollStart(document.getElementById('contact'), -dim_scroll-h_element, -dim_scroll, 'vert');	
}
window.welle_info_display = false;
function show_welle_info(){
	if (!window.welle_info_display){
		scrollStart(document.getElementById('welle_info'), -240, 0, 'horiz');
		window.welle_info_display = true;
	}
	else {
		scrollStart(document.getElementById('welle_info'), 0, -240, 'horiz');
		window.welle_info_display = false;

	}
}

function trimite_mesaj(){
		new Ajax.Request("mesaj.php", {
		 onSuccess : function(resp) {  
			  document.getElementById('contact_form').style.display = "none";
			  document.getElementById('contact_mesaj').style.display = "block";
			  document.getElementById('descr').value = "";
			  document.getElementById('contact_mesaj').innerHTML = "Va multumim pentru interesul acordat!<br> Va vom contacta in cel mai scurt timp posibil."+resp.responseText;
			 },
		 onFailure : function(resp) { alert("Oops, there's been an error.");},
		 parameters : "action=trimite_mesaj&tip_comentariu=" + $F('tip_comentariu') + "&nume=" + $F('nume') + "&telefon="+ $F('telefon') + "&email=" + $F('email') + "&descr=" + $F('descr'),
		 method: 'post',																					  
		 asynchronous: false
		});   
}

