// JavaScript Document

	/* FUNCIONES DE AJAX */
		
	function procesando (obj)
	{
		var div = "#" + obj;
		var html = '<div align="center" style="width:100%"><img src="images/bigrotation.gif" width="40" height="40" /></div>';
		$(div).html(html);
	}
	
	function postAjax(direccion,data, div)
	{
		 $.ajax({
				beforeSend: procesando(div),
				type: "POST",
				url: direccion,
				cache: false,
				data: data,
				success: function(htmlResult)
				{
					var obj = "#" + div;
					$(obj).html(htmlResult);
				}
		});
	}
	
	function getAjax(direccion,data, div)
	{
		 $.ajax({
				beforeSend: procesando(div),
				type: "GET",
				url: direccion,
				cache: false,
				data: data,
				success: function(htmlResult)
				{
					var obj = "#" + div;
					$(obj).html(htmlResult);
				}
		});
	}
	
	function getAjaxSP(direccion,data, div)
	{
		 $.ajax({
				type: "GET",
				url: direccion,
				data: data,
				cache: false,
				success: function(htmlResult)
				{
					var obj = "#" + div;
					$(obj).html(htmlResult);
				}
		});
	}
	

	/* FUNCIONES DEL FUNCIONAMIENTO DEL SITIO */
	
	$(document).ready(function(){
		/*if ($.browser['version'] == '6.0')
		{
			alert('Para la correcta visualizacion de este sitio recomendamos la utilizacion de IE 7 / Mozilla Firefox');
			document.location = "index_error.html";
		}*/
		
		preload = new Image();
		preload.src = "images/cateCoaxC.jpg";
		preload = new Image();
		preload.src = "images/cateCompC.jpg";
		preload = new Image();
		preload.src = "images/cateSubC.jpg";
		preload = new Image();
		preload.src = "images/cateAmpC.jpg";
		preload = new Image();
		preload.src = "images/cateCabC.jpg";
		preload = new Image();
		preload.src = "images/botonHoverSS.gif";
		
		setHome();
		
		$('#menu_principal').find('a').bind('click',function(e){
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			
			var vinculo = $(this).attr('href');
			$.ajax({
				//beforeSend: procesando('contenidos'),
				type: "GET",
				url: vinculo,
				cache: false,
				success: function(htmlResult)
				{
					$('#contenidos').fadeOut('slow',function(){
						var obj = "#contenidos";
						$(obj).html(htmlResult);
						$('#contenidos').fadeIn('slow', function(){
							switch (vinculo)
							{
								case 'productos.php':
									preload = new Image();
									preload.src = "images/botonMenuProductosSCHoverTS.gif";
									setMenu();
									setDetalles();
									break;
								case 'contacto.php':
									$.getScript('scripts/validar.form.contacto.js');
									break;
								case 'combos.php':
									setCombos();
									break;
								case 'home.php':
									Imagen1 = new Image();
									Imagen1.src = "images/cateCoaxC.jpg";
									Imagen2 = new Image();
									Imagen2.src = "images/cateCompC.jpg";
									Imagen3 = new Image();
									Imagen3.src = "images/cateSubC.jpg";
									Imagen4 = new Image();
									Imagen4.src = "images/cateAmpC.jpg";
									Imagen5 = new Image();
									Imagen5.src = "images/cateCabC.jpg";
									setHome();
									break;
								case 'novedades.php':
									setDetalles();
									break;
								case 'wooferApp.php':
									$.getScript('scripts/wapp.js');
									break;
								case 'compatibilidad.php':
									$.getScript('scripts/compatibilidad.js');
									break;
								case 'juegos.php':
									$.getScript('scripts/swfobject.js');
									$.getScript('scripts/games.js');
									break;
							}
						});
					});
				}
			});
		});
	
		$('.imagenesSecundarias').find('img').bind('click', function(){
			var vinculo = $(this).attr('src');
			vinculo = vinculo.replace("&ancho=50&alto=50", "&ancho=200&alto=200");
			var html = '<img src="'+vinculo+'"/>';
			$('#detalleImagenPrincipal').html(html);
		});
	});
	
	function setDetalles ()
	{
		initLytebox();
	}
	
	function setPaginado()
	{
		$('#paginado').find('a').bind('click',function(e){
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			
			var vinculo = $(this).attr('href');
			vinculoAux = vinculo.split('?');
			direccion = "productos.listado.php";
			data = vinculoAux[1];
			$.ajax({
				//beforeSend: procesando('derecha'),
				type: "GET",
				url: direccion,
				cache: false,
				data: data,
				success: function(htmlResult)
				{
					$('#derecha').fadeOut('slow',function(){
						var obj = "#derecha";
						$(obj).html(htmlResult);
						$('#derecha').fadeIn('slow', function(){
							setPaginado();
							setDetalles();									  
						});
					});
				}
			});
		});
	}
	
	function setMenu ()
	{
		$.getScript('scripts/menu.js');
		$('#menuProductos').find('a').bind('click',function(e){
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			
			var vinculo = $(this).attr('href');
			vinculoAux = vinculo.split('?');
			direccion = "productos.listado.php";
			data = vinculoAux[1];
			$.ajax({
				//beforeSend: procesando('derecha'),
				type: "GET",
				url: direccion,
				cache: false,
				data: data,
				success: function(htmlResult)
				{
					$('#derecha').fadeOut('slow',function(){
						var obj = "#derecha";
						$(obj).html(htmlResult);
						$('#derecha').fadeIn('slow', function(){
							setPaginado();
							setDetalles();
						});
					});
				}
			});
		});
	}

	function setCombos()
	{
		$('#comboListado').find('a').bind('click', function(e){
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			
			$('#comboListado').find('a').removeClass('comboListadoItemSelected');
			$(this).addClass('comboListadoItemSelected');
			var vinculo = $(this).attr('href');
			vinculoAux = vinculo.split('?');
			direccion = vinculoAux[0];
			data = vinculoAux[1];
			$.ajax({
				//beforeSend: procesando('derecha'),
				type: "GET",
				url: direccion,
				cache: false,
				data: data,
				success: function(htmlResult)
				{
					$('#combos_detalle').fadeOut('slow',function(){
						var obj = "#combos_detalle";
						$(obj).html(htmlResult);
						$('#combos_detalle').fadeIn('slow', function(){
							initLytebox();
						});
					});
				}
			});
		});
	}
	
	function setHome()
	{
		$('#contenedorImagenesHome').find('a').bind('click',function(e){
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			
			var vinculoHome = $(this).attr('href');
			vinculoId = vinculoHome.split("=");
			$.ajax({
				//beforeSend: procesando('contenidos'),
				type: "GET",
				url: vinculoHome,
				cache: false,
				success: function(htmlResult)
				{
					$('#contenidos').fadeOut('slow',function(){
						var objHome = "#contenidos";
						$(objHome).html(htmlResult);
						$('#contenidos').fadeIn('slow', function(){
							/*Abro el menu*/
							setMenu ();
							$("#menu_"+vinculoId[1]).css({"visibility": "visible","display": "block"}).show(150);
							initLytebox();
						});
					});
				}
			});
		});
	}