$(document).ready(function(){
	home_enlaces_relacionados();



	//Con galeria_horizontal.js
	if(typeof gal_hor_inicia == 'function') { 
		gal_hor_inicia(); 
	}
	//Con navegacion_barras_grandes.js
	if(typeof nav_bar_gra_inicia == 'function') { 
		nav_bar_gra_inicia(); 
	}
	
	
	desplegables_inicia();
	
	ventana_imagen_principal_inicia();
	
	//Con popup.js
	if(typeof popup_imagenes_carga == 'function') { 
		popup_imagenes_carga(); 
	}
	if($('#flash_fondo')){
		$(window).resize(function(){
			$('#flash_fondo').flash({
				swf: '/fondos_vid/elkenburnsdee.swf',
				width: '100%',
				height: '100%',
				wmode: 'transparent'
			});
		});
	}
});

//Inicia los enlaces relacionados de la home
function home_enlaces_relacionados(){

	///if($('#flash_fondo')){
		$('#flash_fondo').flash({
			swf: '/fondos_vid/elkenburnsdee.swf',
			width: '100%',
			height: '100%',
			wmode: 'transparent'
		});
	//} else {
		$('#imagen_fondo').flash({
			swf: '/fondos_vid/fondos_imagen.swf',
			width: '100%',
			height: '100%',
			wmode: 'transparent'
		});
		
	//}
	var anchocaja=312;
	$('div#home ul.enlaces_relacionados li.nivel_1').each(function(i,item){
		$(item).children('div').children('ul').children('li').children('a').each(function(i2,item2){
			$(item2).css('left',(anchocaja*i2)+'px');
		});
	});
	home_enlaces_relacionados_actualiza_botones_estado();
}
//home_enlaces_relacionados_actualiza_botones_estado
function home_enlaces_relacionados_actualiza_botones_estado(){
	$('div#home ul.enlaces_relacionados li.nivel_1').each(function(i,item){
		var cuantas=$(item).children('div').children('ul').children('li').size();
		var anchocaja=312;//px
		var posicion=parseFloat($(item).children('div').children('ul').css('left'),10)/anchocaja;
		if(posicion>-cuantas+1){
			$(item).children('a.alante').click(function() {
				home_enlaces_relacionados_alante(item);
			});
			$(item).children('a.alante').attr('class','alante');
		} else {
			$(item).children('a.alante').attr('class','alante inactivo');
		}
		if(posicion<=-1){
			$(item).children('a.atras').click(function() {
			  home_enlaces_relacionados_atras(item);
			});
			$(item).children('a.atras').attr('class','atras');
		} else {
			$(item).children('a.atras').attr('class','atras inactivo');
		}
	});
}


//enlace relacionado de la home hacia alante
function home_enlaces_relacionados_alante(item){
	var cuantas=$(item).children('div').children('ul').children('li').size();
	var anchocaja=312;//px
	var posicion=parseFloat($(item).children('div').children('ul').css('left'),10)/anchocaja;
	if(posicion>-cuantas+1){
		$(item).children('a.atras').unbind('click');
		$(item).children('a.alante').unbind('click');
		$(item).children('div').children('ul').animate( { 'left': ((posicion-1)*anchocaja)+'px' }, 300, 'linear', function() {
		      home_enlaces_relacionados_actualiza_botones_estado();
		    });
	}
}
//enlace relacionado de la home hacia adelante
function home_enlaces_relacionados_atras(item){
	var cuantas=$(item).children('div').children('ul').children('li').size();
	var anchocaja=312;//px
	var posicion=parseFloat($(item).children('div').children('ul').css('left'),10)/anchocaja;
	if(posicion<=-1){
		$(item).children('a.atras').unbind('click');
		$(item).children('a.alante').unbind('click');
		$(item).children('div').children('ul').animate( { 'left': ((posicion+1)*anchocaja)+'px' }, 300, 'linear', function() {
		      home_enlaces_relacionados_actualiza_botones_estado();
		    });
	}
}





function desplegables_inicia(){
	$('a.desplegable_enlace').each(function(i,item){
		$(item).click(function(){
			desplegables_cambia(i);
			return false;
		});
		
	});

}


function desplegables_cambia(i){
	var enlace=$('a.desplegable_enlace').get(i);
	var contenido=$('div.desplegable_contenido').get(i);
	if($(contenido).css('display')=='none'){
		$(enlace).css('background-position','0px 0px');
		$(contenido).slideDown("slow");//.css('display','block')
	} else {
	$(enlace).css('background-position','0px -50px');
		$(contenido).slideUp("slow");//.css('display','none');
	}
}

// ventana_imagen_principal_inicia

function ventana_imagen_principal_inicia(){
	$('div#ventana_imagen_principal').mouseenter(function(){
		ventana_imagen_principal_muestra_thumbs();
	});
	$('div#ventana_imagen_principal').mouseleave(function(){
		ventana_imagen_principal_oculta_thumbs();
	});
	$('div#ventana_imagen_principal a').each(function(i,item){
		
	});
}

function ventana_imagen_principal_muestra_thumbs(){
	$('div#ventana_imagen_principal ul').stop(true,false).animate({
	    'left': '503px'
	  }, 300, function() {
	    // Animation complete.
	  });	
}
function ventana_imagen_principal_oculta_thumbs(){
	$('div#ventana_imagen_principal ul').stop(true,false).animate({
	    'left': '576px'
	  }, 300, function() {
	    // Animation complete.
	  });	
}

function prod_menu_muestra(id,enlace){
	$('.parte_producto').each(function(i,item){
		$(item).hide();
	});
	$('#'+id).show();
	$('ul#menu_sec ul li a.activo').removeAttr('class');
	$($('ul#menu_sec ul li a').get(enlace)).attr('class','activo');
	//console.log(enlace.parent);
}


