$(document).ready(fld_init);

var sCk = location.href.indexOf("buscar")>-1 ? "mapa" : "proxprom";

function fld_init() {
	$(".itProv").each(function (a, b) {
		$(b).click(fld_click).attr("status", "up").attr("index", a);
	});
	$(".itProv .arrUp").css({ display: "none" });
	$(".grpPromos ul").css({ display: "none" });
	
	var nIdx = getCookie(sCk, -1);
	if(nIdx>-1) $(".itProv:eq("+nIdx+")").click();
}

function fld_click() {
	var jThis = $(this);
	var nIdx  = jThis.attr("index");
	var sSts  = jThis.attr("status");
	if(sSts=="up") {
		jThis.attr("status", "dn");
		jThis.find(".arrUp").css({ display: "inline" });
		jThis.find(".arrDn").css({ display: "none" });
		jThis.parent().parent().find(".grpPromos ul").css({ display: "block" });
	} else {
		jThis.attr("status", "up");
		jThis.find(".arrUp").css({ display: "none" });
		jThis.find(".arrDn").css({ display: "inline" });
		jThis.parent().parent().find(".grpPromos ul").css({ display: "none" });
	}
	setCookie(sCk, nIdx)
	return false;
}

function setCookie(name, value) {
	document.cookie = name+"="+value+"";
}

function getCookie(name, def) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return def;
}
