// JavaScript Document

ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["closesec", "opensec"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
	},
	onopenclose:function(header, index, state, isuseractivated){ 
	}
});

$(function() {
		$('.menuitem > a').each(function(index){
				$(this).click(function(){
				$('body').css('background-color','#ffffff');
				if($('a.submenuheader').hasClass("inwshop")){
					$('a.submenuheader').removeClass("inwshop");
					var pidwAct=$('#opActual').val();
					if(pidwAct>0){ $('#wtn_'+pidwAct).removeClass("activo");}
					$('#mainwshop').empty();
					$('#mainwshop').css('display','none');
				}
				return false;
  			});									
		});
		$('.bcerrar').click(function(index){
			$('#flash').css("display","none");
		});
		$('.wshop').each(function(index) {
			$(this).click(function(){
				var pidwAct=$('#opActual').val();
				if(pidwAct>0){ $('#wtn_'+pidwAct).removeClass("activo");}
				var namewshop=$(this).children('a').attr("name");	
				pidwAct=namewshop.substring(namewshop.lastIndexOf("_") + 1);
				$('#wtn_'+pidwAct).addClass("activo");
				$('#opActual').val(pidwAct);
				$('body').css('background-color',$(this).attr("color"));
				$('a.submenuheader').addClass("inwshop");
				var urrele=$(this).children('a').attr("title")+".htm";
				if(urrele==".htm"){
					$('#mainwshop').empty();
					$('#mainwshop').append("<h1>Info no disponible</h1>");
				}else{
				 $.ajax({type:"POST",url:""+urrele+"",data:({}),dataType:"html",async:false,
					success:function(html){
						$('#mainwshop').empty();
						$('#mainwshop').append(html);
						$('#mainwshop').css('display','block');
						$('.sbwshop').bind('click',function(){
							var name=$(this).attr("name");	
							var pid=name.substring(name.lastIndexOf("_") + 1);	
							var pidAct=$('#sbActual').val();
							if(pidAct>0){
								$('#box_'+pidAct).css('display','none');
								$('#btn_'+pidAct).removeClass("activo");
							}
							$(this).addClass("activo");
							$('#sbActual').val(pid);
							$('#box_'+pid).css('display','block');
						});
						$('#sbActual').val(1);
						$('#box_1').css('display','block');
						$('#btn_1').addClass("activo");
					}
				 });
				}
				
				return false;
  			});
		});
		
	});
