/*
    *****************************************
    JAVASCRIPT SITIO WEB DOSVE
    *****************************************
    =========================================
    www.dosve.com.ar
    =========================================
*/


jQuery(document).ready(init);


function init() {	
	
	// ocultar todos los submenues:
	jQuery('#access > div.menu > ul > li > ul').hide();
	jQuery('#access > div.menu > ul > li > ul > li > ul').hide();
	
	// hacer aparecer el submenu correspondiente (current_section):
	jQuery("li.current_page_ancestor > ul").animate({height: 'show', opacity: 'show'}, 200);
	jQuery("li.current_page_parent > ul").animate({height: 'show', opacity: 'show'}, 200);
	jQuery("li.current_page_item > ul").animate({height: 'show', opacity: 'show'}, 200);
	
	// agregar eventos a los links
	jQuery('#access > div.menu > ul > li > a').click(toggleShowSubMenus);
	jQuery('#access > div.menu > ul > li > ul > li > a').click(toggleShowSubMenus);
	
	//agregarEventosJuguetones();
	
}


function agregarEventosJuguetones(){
	/* esto esta apagado ahora */
	jQuery('div.menu ul li a').hover(function(){
		//mouseenter:
			jQuery(this).animate({'padding-left':'+=5px'}, 100);
		}, function(){
		//mouseleaave:
			jQuery(this).animate({'padding-left':'-=5px'}, 200);
	});
}


function toggleShowSubMenus(){

	var estabaVisible;
	
	// chequear si el submenu estaba visible:
	if(jQuery("ul", jQuery(this).parent()).css("display") == "none"){
		estabaVisible = false;
	} else {
		estabaVisible = true;
	}
	
	// ocultar todos los submenues:
	jQuery('li > ul', jQuery(this).parent().parent()).animate({height: 'hide', opacity: 'hide'}, 200);
	
	// si tiene submenu:
	if(jQuery(this).parent().children().size() > 1 ){
		// si NO estaba visible: mostrar
		if(estabaVisible == false){
			// si el padre tiene la clase .children
			if(jQuery(this).parent().parent().hasClass("children")){
				var ir_a = jQuery(">ul>li:first-child>a", jQuery(this).parent()).attr('href');
				window.location = ir_a;
			} else{
				// animar la apertura del hijo, si el padre no era un "children":
				jQuery(">ul", jQuery(this).parent()).animate({height: 'show', opacity: 'show'}, 200);
			}
		} else{
			// si estaba visible: ocultar
			jQuery(">ul", jQuery(this).parent()).animate({height: 'hide', opacity: 'hide'}, 200);
		}
		// no ir al link:
		return false;
	}
}

