	function pageload(hash){  
		var cache_not=Math.random();  
		if(hash){  		
			var1 = hash.split('-');
			opt = "";
			switch (var1[0]){
				case 'producto':
					opt = 1;
					break;
				case 'destacado':
					opt = 0;
					break;
				case 'familia':
					opt = 2;
					break;
				case 'producto_fam':
					opt = 3;
					break;
				case 'detalle':
					opt = 4;
					break;
			}
			GenRuta(var1[1],opt);	
			if(var1.length == 3){
				txt = "?id=" + var1[1] + "&pag=" +  var1[2];
			}else{
				txt = "?id=" + var1[1];
			}
			
			$("#contenido-general").load("modulos/" + var1[0]+ ".php" + txt,function(){
				$("a[@rel='detalle']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='familia']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='home']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='marcas']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='categ']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='pag']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
							
			});
		}  
		else{
			$("#contenido-general").load("modulos/destacado.php",function(){
				$("a[@rel='detalle']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				}); 
				$("a[@rel='familia']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				}); 
				$("a[@rel='home']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				}); 
				$("a[@rel='marcas']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='categ']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
				$("a[@rel='pag']").click(function(){  
					var hash = this.href;  
					hash = hash.replace(/^.*#/, '');  
					$.historyLoad(hash);  
					return false;  
				});
			});
		} 
		
	}
	
	function GenRuta(Id, Tipo){
		/* 
			1 - categoria
			2 - marcas
			3 - modelos
			4 - detalle
		*/
		$.get("modulos/gen_ruta.php",{id:Id,tipo:Tipo},function(data){
			$("#gral_ruta").html(data);												
		});	
	}
	
$(document).ready(function(){
					
							   
	$("#btnbsq").click(function(){
		if($("input[@name=buscar]").val() == ""){
			alert("Debe ingresar un valor a buscar");
			$("input[@name=buscar]").focus();
		}else{
			var txt = $("input[@name=buscar]").val();
			var lol;
			var ty;
			cAR = " ";
			cR = "+";
			lol = txt.split(cAR).join(cR);
			cAR = "-";
			cR = "*";
			ty = lol.split(cAR).join(cR);
			var hash = "bsq-" + ty;
		 	$.historyLoad(hash);
		}
		return false;  		  
	});	

	$("a[@rel='cat']").click(function(){  
		var hash = this.href;  
		hash = hash.replace(/^.*#/, '');  
		$.historyLoad(hash); 
		
		return false;  
	}); 

	$("a[@rel='inicio']").click(function(){  
		var hash = this.href;  
		hash = hash.replace(/^.*#/, '');  
		$.historyLoad(hash); 
		return false;  
	});  
	
	$("a[@rel='marca']").click(function(){  
		var hash = this.href;  
		hash = hash.replace(/^.*#/, '');  
		$.historyLoad(hash);  
		return false;  
	});  

	$.historyInit(pageload);  
	
	var options = {
	    resizeLgImages:     true,
	    displayNav:         true,
	    handleUnsupported:  'remove',
	    keysClose:          ['c', 27] // c or esc
	};

	Shadowbox.init(options);

	$('#cajabanner').cycle({ 
	    fx:     'fade', 
	    speed:   800, 
	    timeout: 5000, 
	    next:   '#cajabanner', 
	    pause:   1 
	});	
	
	
});
