var imageSwitchArray = [{
	image: 'comunicare.jpg',
	title: 'Comunicarea in afaceri',
	text: 'Comunicarea cu partenerii de afaceri este foarte importanta pentru tine. Noi te ajutam.'
},{
	image: 'start.jpg',
	title: 'Keepto da Startul in afaceri',
	text: 'Cu felicitarile keepto te vei detasa de competitorii tai. Noi te ajutam sa fii cu un pas inainte.'
},{
	image: 'ecoresponsabilitate.jpg',
	title: 'EcoResponsabilitate',
	text: 'Foloseste felicitarile online. Economisesti bani protejand mediul inconjurator.'
},{
	image: 'bun_venit_clienti.jpg',
	title: 'Felicitari de bun venit (clienti)',
	text: 'Incepe cu dreptul orice noua afacere. Spune bun venit partenerilor sau clientilor tai.'
},{
	image: 'bun_venit_angajati.jpg',
	title: 'Felicitari de bun venit (angajati)',
	text: 'Spune bun venit in echipa noilor tai angajati sau subalterni. Integrarea lor depinde de tine.'
},{
	image: 'fidelizare.jpg',
	title: 'Felicitari de fidelizare',
	text: 'Fidelizarea si loializarea clientilor sau angajatilor tai este acum ridicol de simpla.'
},{
	image: 'la_multi_ani.jpg',
	title: 'Felicitari La Multi Ani',
	text: 'Spune "La multi ani" partenerilor si angajatilor tai. Nu te costa nimic dar ai multe de castigat.'
},{
	image: 'scuze.jpg',
	title: 'Felicitari pentru scuze',
	text: 'Problemele reprezinta oportunitatea de a consolida relatiile cu partenerii tai. Afla cum!'
}];

var currentTimer = 0, nextIncrement = 0, currentSelection = 0, switchInterval = 5;
var isScrolling = false, scrollSteps = new Array(5, 10, 15, 25, 34, 34, 25, 15, 10, 5);

function switchImage(index) {
	if (index >= imageSwitchArray.length) index = 0;
	nextIncrement = currentTimer + switchInterval;
	document.getElementById('switcherText').innerHTML = '<span>' + imageSwitchArray[index].title + '</span> ' + imageSwitchArray[index].text;
	document.getElementById('switcherContainer').style.backgroundImage = 'url("/images/home/' + imageSwitchArray[index].image + '")';
	currentSelection = index + 1;
}

function doSwitch() {
	if (currentTimer == nextIncrement)
		switchImage(currentSelection);
	currentTimer++;
	setTimeout('doSwitch()', 1000);
}

function scrollImagesLeft(divId, amount) {
	if (isScrolling) return false;
	
	doScrollLeft(0, divId);
}

function scrollImagesRight(divId, amount) {
	if (isScrolling) return false;
	
	doScrollRight(0, divId);
}

function doScrollLeft(stepIndex, divId) {
	if (stepIndex >= scrollSteps.length) {
		isScrolling = false;
		return;
	}
	
	document.getElementById(divId).scrollLeft += scrollSteps[stepIndex];
	stepIndex++;
	setTimeout('doScrollLeft(' + stepIndex + ', "' + divId + '")', 20);
}

function doScrollRight(stepIndex, divId) {
	if (stepIndex >= scrollSteps.length) {
		isScrolling = false;
		return;
	}
	
	document.getElementById(divId).scrollLeft -= scrollSteps[stepIndex];
	stepIndex++;
	setTimeout('doScrollRight(' + stepIndex + ', "' + divId + '")', 20);
}

function showDivTexte() {
	document.getElementById('header_drop_scroller').style.display = 'block';
}

function hideDivTexte() {
	document.getElementById('header_drop_scroller').style.display = 'none';
}

function showDivSubtexte(id) {
	document.getElementById('subcats_' + id).style.display = 'block';
}

function hideDivSubtexte(id) {
	document.getElementById('subcats_' + id).style.display = 'none';
}

var httpObject = null;

function doSidebarLogin() {
	var xmlhttp;
	// Attempt to initialize xmlhttp object
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
    catch (e) {
		// Try to use different activex object
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	// If not initialized, create XMLHttpRequest object
	if (!xmlhttp) {
		if (typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		else {
			alert("Browser-ul dvs. nu poate rula script-uri AJAX.\nFolositi Mozilla Firefox, Internet Explorer sau Opera.");
			return null;
		}
	}
	
	httpObject = xmlhttp;
	
	httpObject.open("POST", "/login/auth_sidebar/", true);
	httpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpObject.setRequestHeader("Connection", "close");
	httpObject.onreadystatechange = sidebarLoginStatus;
	httpObject.send("user=" + encodeURIComponent(document.formLogin.user.value) + "&pass=" + encodeURIComponent(document.formLogin.pass.value));
}

function sidebarLoginStatus() {
	if (httpObject.readyState == 4) {
		if (httpObject.responseText == '') {
			document.location.reload();
		}
		else {
			alert(httpObject.responseText);
		}
	}
}

