$(document).ready(function() {
				
				// FANCY BOX
				
				$("a.example1").fancybox();
				
				$(".various3").fancybox({
				'width'				: 600,
				'height'			: 335,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
				});
				
				// HEIGHT BACKGROUNDS AND MOVE HEIGHT
				
				$(window).resize(function() {
					var wh = $(window).height();
					$(".background").css("height", wh + "px");
					$(".showroom").css("height", wh + "px");
					var ww = $(window).width();
					$(".boxBG").css("width", ww * 2 + "px");
					$(".background").css("width", ww +"px");
				});
				
				$(window).resize();

				// OPEN MENUS
				var last_area = '';
				
				$(".menu").click(function(){
											var ancho = $(this).attr("ancho");
											var area = $(this).attr("area");
											$(".apartado").animate({"width" : "0px"},{duration: 200, queue: true},'linear');
											$(".apartado2").animate({"width" : "0px"},{duration: 200, queue: true},'linear');
											if (area != last_area){ //Si es la misma seccion no la abrimos
												$("#"+area).animate({"width" : ancho+"px"},{duration: 300, queue: true},'linear');
												last_area = area;
											} else {
												last_area = '';
											}
											
				});
				
				$("#noticias .contenido .box .image").click(function(){
																	  $(".apartado2").animate({"width" : "0px"},{duration: 200, queue: true},'linear');
																	  var proyectoID = $(this).parent().attr("noticia");
																	  var pathWork = "noticia.php?id=" + proyectoID;
																	  $("#leerNew .contenido").load(pathWork, function(){});
																	  $(".apartado2").animate({"width" : "460px"},{duration: 300, queue: true},'linear');
				});
				
				/* PASADOR IMAGENES AUTOMATICO HEADER */
			
					var slider = 1;
					
					var currentPicture = new Array();
					
					currentPicture[0] = 'rs/bg_8.jpg';
					currentPicture[1] = 'rs/bg.jpg';
					currentPicture[2] = 'rs/bg_2.jpg';
					currentPicture[3] = 'rs/bg_3.jpg';
					currentPicture[4] = 'rs/bg_4.jpg';
					currentPicture[5] = 'rs/bg_5.jpg';
					currentPicture[6] = 'rs/bg_6.jpg';
					currentPicture[7] = 'rs/bg_7.jpg';
					
					var titles = new Array();
					
					titles[0] = "JOYPER SHOWROOM 8/8";
					titles[1] = "JOYPER SHOWROOM 1/8";
					titles[2] = "JOYPER SHOWROOM 2/8";
					titles[3] = "JOYPER SHOWROOM 3/8";
					titles[4] = "JOYPER SHOWROOM 4/8";
					titles[5] = "JOYPER SHOWROOM 5/8";
					titles[6] = "JOYPER SHOWROOM 6/8";
					titles[7] = "JOYPER SHOWROOM 7/8";
					
					var nextInfo;
					
					function showInfo(){
		
										
		
										//$(".showroom .boxBG li:last").html(currentPicture[slider]); 
										
										$(".titFoto").animate({"width" : "0px"},200,'linear',function(){	
																					$(this).html(titles[slider]); //Activa los nombres del array
																					$(this).animate({"width" : "146px"},{duration: 300, queue: true},'linear');
																			   		});
										
										$(".showroom .boxBG").animate({"margin-left":"-" + $(window).width() + "px"},800,function(){
											$(this).find("li:last").after($(this).find("li:first"));
											$(this).css("margin-left","0px");
											$(".showroom .boxBG li:last").attr("style", "background-image: url(" + currentPicture[slider] + ");");
											nextInfo = setTimeout(showInfo,6000);
										});
										
										slider = slider + 1;
										if (slider == currentPicture.length) {slider = 0;}					
					}		
					
					showInfo();
				
				$(".controls .btNext").hover(function(){ $(this).css("background-position","center bottom")}, function(){ $(this).css("background-position","center top")});
				$(".controls .btPrev").hover(function(){ $(this).css("background-position","center bottom")}, function(){ $(this).css("background-position","center top")});
				
				$(".btNext").click(function(){ 
											clearTimeout(nextInfo);
										   	showInfo()
				});
				
				$(".btPrev").click(function(){ 
											clearTimeout(nextInfo);
				});
				
				//PRELOAD IMAGES

				//$.preloadImages("rs/bg.jpg", "rs/bg_2.jpg", "rs/bg_3.jpg", "rs/bg_4.jpg");							
});
