// JavaScript Document
$(function() {
    $("img.imageToScale").scaleImage({
        parent: '.fondo',
        center: false,
        fade: 500
    });
});

$(window).resize(function() { 
  $("img.imageToScale").scaleImage({
        parent: '.fondo',
        center: false,
        fade: 0
    });
}); 

//$(".botonera img").live("mouseover mouseout", function(event) {
  //if ( event.type == "mouseover" ) {
	//img = $(this).attr('src');
	//btn = $(this).attr('title');
	//imgover = btn+'up.gif';
	//$(this).attr({ src: imgover });
  //} else {
	//$(this).attr({ src: img });
  //}
//});
seccion = "Home";
$(".botonera img").live('click', function() {
	$(".botonera img").stop().animate({ left: [-9, 'swing']}, 300);
	$(this).stop().animate({ left: [0, 'swing']}, 300);
	seccion = $(this).attr('alt');
//	if (seccion == "Home"){
//	  $("#home-1").stop().animate({ right: 0}, 500, 'swing',
//			function(){$("#home-2").stop().animate({ right: 0}, 500, 'swing',
//					function(){$("#home-3").stop().animate({ right: 0}, 500, 'swing');});});
//  }
//  else{
//	  $("#home-1").stop().animate({ right: -616}, 500, 'swing',
//			function(){$("#home-2").stop().animate({ right: -596}, 500, 'swing',
//					function(){$("#home-3").stop().animate({ right: -577}, 500, 'swing');});});
//  }
});

$(".botonera img").live("mouseover mouseout", function(event) {
  if ($(this).attr('alt') != seccion){
  	if ( event.type == "mouseover" ) {
		$(this).stop().animate({ left: [0, 'swing']}, 300);
	} else {
		$(this).stop().animate({ left: [-9, 'swing']}, 300);
  	}
  }  
});

//$('#form1').live('submit', function () {
//	var formulario = $('#form1').serialize(); 
//    $.ajax({
//		type: "POST",
//		url: "http://www.jjo.cl/registrate.php",
//		global: false,
//		data: formulario,
//		success: function(msg){
//			$('.glass').empty().html(msg).find('#registrate');
//			},
//		error: function(msg){alert ('Favor reintente')}
//    });       
//    return false;
//});

$(document).ready(function(){
						   
	$("#home-1").live("mouseover mouseout", function(event) {
	  if ( event.type == "mouseover" ) {
		$(".home-novedades").stop().animate({ height: 319}, 500, 'swing');
	  } else {
		$(".home-novedades").stop().animate({ height: 154}, 500, 'swing');
	  }
	});
	
	$("#home-2").live("mouseover mouseout", function(event) {
	  if ( event.type == "mouseover" ) {
		$(".home-coleccion").stop().animate({ height: 259}, 500, 'swing');
		$(".bx-wrapper a").css('display' , 'block');
	  } else {
		$(".home-coleccion").stop().animate({ height: 154}, 500, 'swing');
		$(".bx-wrapper a").css('display' , 'none');
	  }
	});
	
	$(".tiendas-botonabrir").live('click', function() {
											  var pos_lista = $('.tiendas-lista').css('right');
											  if (pos_lista == '0px'){
											  	$(".tiendas-lista").stop().animate({ right: -140}, 500, 'swing');								  
											  }else{
												$(".tiendas-lista").stop().animate({ right: 0}, 500, 'swing');
											  }
											  });
	
	$(".tiendas-lista li").live('click', function() {
											 	var posicion = $(this).attr("value");
											   	var div_tienda_click = "#"+$(this).attr("class");
												$(".tiendas-lista li").each(function(){
													var div_tienda = "#"+$(this).attr("class");
													var div_tienda_value = $(div_tienda).data('nivoslider');
													if (div_tienda_value != undefined){
														$(div_tienda).data('nivoslider').stop(); //Stop the Slider
													}																					 
													});
												$(div_tienda_click).nivoSlider({
													effect:'boxRandom', // Specify sets like: 'fold,fade,sliceDown'
													controlNav:false, // 1,2,3... navigation
												});
												$("#tiendas-scroll").stop().animate({ left: -posicion}, 700, 'swing');
											   });
	
	$(".glass").stop().animate({ right: 0}, 500, 'swing');
	
	// Boton de registro dentro de club jjo
	$("#btnregistro-club").live('click', function() {
			seccion = "Registrate"
			//Oculto la capa del contenido
			$(".glass").stop().animate({ right: -907}, 500, 'swing',
			function(){
				//Borro el contenido
				$(".glass").html('');
				//Cargo el nuevo contenido de Registrate
				if (seccion == "Registrate"){
					$(".fondo img").attr({ src: 'jjo.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('registrate.php #registrate',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
						});
				}
			});// Fin cierre ventana contenido
	}); //Fin botonera .img click	
	// fin boton registro dentro de club jjo
	
	$(".botonera img").live('click', function() {
			//Oculto la capa del contenido
			$(".glass").stop().animate({ right: -907}, 500, 'swing',
			function(){
				//Borro el contenido
				$(".glass").html('');
				//Cargo el nuevo contenido del Home
				if (seccion == "Home"){
					$(".fondo img").attr({ src: 'jjo.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 1000);
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 1000);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 1000);
					$(".text-registrate").stop().animate({ width: ['hide', 'swing']}, 1000);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 1000);
					$(".glass").load('index.php #home',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
							$('.bxslider').bxSlider();
							$('#home-slide').nivoSlider({
								effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
								pauseTime:3000, // How long each slide will show
								pauseOnHover:false, // Stop animation while hovering
								controlNav:false, // 1,2,3... navigation
							});
						});
				}
				//Cargo el nuevo contenido de Colección
				if (seccion == "Colección"){
					$(".fondo img").attr({ src: 'bano.jpg' });
					$(window).resize();
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-manwoman-2011").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('coleccion.php #coleccion',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
							$('#woman').nivoSlider({
								effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
								pauseTime:4000, // How long each slide will show
								controlNav:false, // 1,2,3... navigation
								pauseOnHover:false, // Stop animation while hovering
							});
							$('#man').nivoSlider({
								effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
								pauseTime:5000, // How long each slide will show
								pauseOnHover:false, // Stop animation while hovering
								controlNav:false, // 1,2,3... navigation
							});
						});
				}
				//Cargo el nuevo contenido de Campaña
				if (seccion == "Campaña"){
					$(".fondo img").attr({ src: 'cama.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-campana-2011").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('campana.php #campana',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
							$('#campana-slide').nivoSlider({
								effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
								pauseOnHover:false, // Stop animation while hovering
								controlNav:false, // 1,2,3... navigation
							});
						});
				}
				//Cargo el nuevo contenido de Tiendas
				if (seccion == "Tiendas"){
					$(".fondo img").attr({ src: 'bano.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('tiendas.php #tiendas',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
							$("#tiendas-slide-fcenter").nivoSlider({
								effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
								controlNav:false, // 1,2,3... navigation
							});
						});
				}
				//Cargo el nuevo contenido de Registrate
				if (seccion == "Registrate"){
					$(".fondo img").attr({ src: 'jjo.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('registrate.php #registrate',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
						});
				}
				//Cargo el nuevo contenido de Club JJO
				if (seccion == "Club"){
					$(".fondo img").attr({ src: 'cama.jpg' });
					$(window).resize();
					$(".text-manwoman-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-campana-2011").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-tiendas").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-registrate").stop().animate({ width: ['hide', 'swing']}, 500);
					$(".text-club").stop().animate({ width: ['show', 'swing']}, 1000);
					$(".glass").load('club.php #club',
						function(){
							//Muestro nuevamente el contenido una vez cargado
							$(".glass").stop().animate({ right: 0}, 500, 'swing');
						});
				}
			});// Fin cierre ventana contenido
	}); //Fin botonera .img click
});//Fin document Ready
