var currentSelectedCat = 0;
var currentSelectedSubCat = 0;
function leftCatClick(id) {
	if (!$("catList" + id)) return;
	
	var ind = currentSelectedCat;
	if(currentSelectedCat) {
		$("catList" + ind).style.display = "none";		
		//$("catLI" + ind).className = "";
		$("catLIA" + ind).className = "link1";
	}
	currentSelectedCat = id;
	ind = id;
	$("catList" + ind).style.display = "";
	//$("catLI" + ind).className = "leftCatSel";
	$("catLIA" + ind).className = "linksel";	
}

function setSubmenuActive(id) {	
	var ind;
	if(currentSelectedSubCat) {
		ind = currentSelectedCat;	
		$("catLIA" + ind).className = "link1";
	}	
	if(currentSelectedCat == id) return;
	
	currentSelectedSubCat = id;
	ind = id;	
	$("catLIA" + ind).className = "linksel";
	
}


function mainSearchSubmit() {
	var el = $("mainSearch");
	var v = el.value.replace(/^\s+|\s+$/g,"");
	if(v == "") {		
		alert('Introduceti cuvantul cautat');
		el.focus();
		return false;
	}
	return true;
}

function mainNewsletterSubmit() {
	var el = $("mainNewsletter");
	
	if(el.value=="") {
		el.value = " ";
		alert('Introduceti adresa de email');
		el.value = "";
		el.focus();
		return false;
	}
	
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i;		
	if(!emailRegExp.test(el.value)) {
		alert('Adresa de email introdusa nu este valida');
		el.focus();
		return false;
	}
	
	return true;
}

var numNewProducts = 0;
var currentNewProduct = 1;
var newProdBoxHeight = 0;
var newProductsAnimating = 0;

function scrollNewProducts()	 {
	if(newProductsAnimating || currentNewProduct>numNewProducts) return;
	
	id="#newProdsList";

	scrollAmount = 
		-(jQuery(id+" li").eq(currentNewProduct-1).offset()["top"]-
		  jQuery(id+" li").eq(currentNewProduct).offset()["top"]);
	
	currentNewProduct++;
	newProductsAnimating = 1
	jQuery(id).animate({
		"top":"-="+scrollAmount+"px"
		},1500,"", function(){ 
				if(currentNewProduct>numNewProducts){
					currentNewProduct = 1;
					jQuery(this).css("top","0px");
				}
				newProductsAnimating = 0;
			});
	
}

var numPromoProducts = 0;
var currentPromoProduct = 1;
var promoBoxHeight = 0;
var promoProductsAnimating = 0;

function scrollPromo(){
	if(promoProductsAnimating || currentPromoProduct>numPromoProducts) return;
	
	id="#promoList";
	
	scrollAmount = 
		-(jQuery(id+" li").eq(currentPromoProduct-1).offset()["top"]-
		  jQuery(id+" li").eq(currentPromoProduct).offset()["top"]);
	
	currentPromoProduct++;	  
	promoProductsAnimating = 1;
	jQuery(id).animate({
		"top":"-="+scrollAmount+"px"
		}, 1500, "", function(){ 
				if(currentPromoProduct>numPromoProducts){
					currentPromoProduct = 1;
					jQuery(this).css("top","0px");
				}
				promoProductsAnimating = 0;
			});
	
}

jQuery(document).ready(function($) {
	if(numNewProducts) {
		$("#newProdsContainer, #newProdsList li").css("height", newProdBoxHeight);		
		setInterval("scrollNewProducts()",6200);
	}
	if(numPromoProducts) {
		$("#promoContainer, #promoList li").css("height", promoBoxHeight);
		setInterval("scrollPromo()",6000);
	}

});
