        $(document).ready(function() {	

			//Rollover INIT///
			
			PEPS.rollover.init();			  

			///////////
			//DISEŅO//
        	///////////

            //Click and Hover events for thumbnail list

			$(".botonera li:first").addClass('active'); 
            $(".image_thumb li:first").addClass('active'); 
            $(".image_thumb li").click(function(){ 					

                //Set Variables

                var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
                var imgDesc = $(this).find('.image_navigator').html(); 	//Get HTML of block1
				var imgDesc2 = $(this).find('.image_text').html(); 	//Get HTML of block1

                if ($(this).is(".active")) {  //If it's already active, then...
                    return false; // Don't click through
                } else {

                    $(".botonera").html(imgDesc);	
					$(".desc").html(imgDesc2);	
                    $(".imagen").attr({ src: imgTitle });
					$(".botonera li:first").addClass('active'); 

					//Nueva botonera
					$(".botonera li").click(function(){ 

						//Set Variables
						var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL

						if ($(this).is(".active")) {  //If it's already active, then...
							return false; // Don't click through
						} else {
							$(".imagen").attr({ src: imgTitle });
						}

						$(".botonera li").removeClass('active'); //Remove class of 'active' on all lists
						$(this).addClass('active');  //add class of 'active' on this list only
						return false;

					}) .hover(function(){

						$(this).addClass('hover');

						}, function() {

						$(this).removeClass('hover');

					});	

                }

                $(".image_thumb li").removeClass('active'); //Remove class of 'active' on all lists

                $(this).addClass('active');  //add class of 'active' on this list only

                return false;

            }) .hover(function(){

                $(this).addClass('hover');

                }, function() {

                $(this).removeClass('hover');

            });

            $(".main_image ul li:first").addClass('active'); 
            $(".main_image ul li").click(function(){ 

                //Set Variables

                var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL

                if ($(this).is(".active")) {  //If it's already active, then...
                    return false; // Don't click through
                } else {

                    $(".imagen").attr({ src: imgTitle });

                }

                $(".main_image  ul li").removeClass('active'); //Remove class of 'active' on all lists
                $(this).addClass('active');  //add class of 'active' on this list only
                return false;

                

            }) .hover(function(){

                $(this).addClass('hover');
                }, function() {
                $(this).removeClass('hover');

            });

			///////

			//WEB//

			///////

			

            //Click and Hover events for thumbnail list

			$(".botonera2 li:first").addClass('active'); 

			

            $(".image_thumb2 li:first").addClass('active'); 

            $(".image_thumb2 li").click(function(){ 					

				

                //Set Variables

                var imgTitle2 = $(this).find('a').attr("href"); //Get Main Image URL

                var imgDesc2 = $(this).find('.image_navigator2').html(); 	//Get HTML of block1

				var imgDesc22 = $(this).find('.image_text2').html(); 	//Get HTML of block1

				

                

                if ($(this).is(".active")) {  //If it's already active, then...

                    return false; // Don't click through

                } else {

                    //Cambio imagen y texto	

					

					//$(".imagen2").hide();

					

                    $(".botonera2").html(imgDesc2);	

					$(".desc2").html(imgDesc22);	

                    $(".imagen2").attr({ src: imgTitle2 });

					$(".botonera2 li:first").addClass('active'); 

					

					//Mostramos la imagen

					//$(".imagen2").fadeIn(100);



					//Nueva botonera

					$(".botonera2 li").click(function(){ 

						

						//Set Variables

						var imgTitle2 = $(this).find('a').attr("href"); //Get Main Image URL



						if ($(this).is(".active")) {  //If it's already active, then...

							return false; // Don't click through

						} else {

												

							//$(".imagen2").hide();

							//Cambio imagen y texto		

							$(".imagen2").attr({ src: imgTitle2 });

							

							//$(".imagen2").fadeIn(100);

							

						}

						

						$(".botonera2 li").removeClass('active'); //Remove class of 'active' on all lists

						$(this).addClass('active');  //add class of 'active' on this list only

						return false;

						

					}) .hover(function(){

						$(this).addClass('hover');

						}, function() {

						$(this).removeClass('hover');

					});	

					

                }

                

                $(".image_thumb2 li").removeClass('active'); //Remove class of 'active' on all lists

                $(this).addClass('active');  //add class of 'active' on this list only

                return false;

                

            }) .hover(function(){

                $(this).addClass('hover');

                }, function() {

                $(this).removeClass('hover');

            });

            

            $(".main_image2 ul li:first").addClass('active'); 

            $(".main_image2 ul li").click(function(){ 



                //Set Variables

                var imgTitle2 = $(this).find('a').attr("href"); //Get Main Image URL

                

                if ($(this).is(".active")) {  //If it's already active, then...

                    return false; // Don't click through

                } else {

					

					//$(".imagen2").hide();

                    //Cambio imagen y texto		

                    $(".imagen2").attr({ src: imgTitle2 });

					

					//$(".imagen2").fadeIn(100);

					

                }

                

                $(".main_image2  ul li").removeClass('active'); //Remove class of 'active' on all lists

                $(this).addClass('active');  //add class of 'active' on this list only

                return false;

                

            }) .hover(function(){

                $(this).addClass('hover');

                }, function() {

                $(this).removeClass('hover');

            });

			

			//NEWS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			
            //Seleccionar primer elemento de botonera cargada

			//$(".botonera3 li:first").addClass('active'); 

            //Seleccionar primer elemento de paginador

			/*$(".paginator3 li:first").addClass('active'); 

            $(".paginator3 li").click(function(){ 					

                //Set Variables

                var imgDesc = $(this).find('.block3').html(); 	

				var imgDesc2 = $(this).find('.image_text3').html();

                if ($(this).is(".active")) {  //If it's already active, then...

                    return false; // Don't click through

                } else {

                    //Cambio imagen y texto	

                    $(".botonera3").html(imgDesc);	


                }

                $(".paginator3 li").removeClass('active'); //Remove class of 'active' on all lists

                $(this).addClass('active');  //add class of 'active' on this list only

                return false;

            }) .hover(function(){

                $(this).addClass('hover');

                }, function() {

                $(this).removeClass('hover');

            });*/

			

			//POPUP!!!!

			var count = 0;

			//When you click on a link with class of poplight and the href starts with a # 

			$('a.poplight[href^=#]').click(function() {									

				var popID = $(this).attr('rel'); //Get Popup Name

				var popURL = $(this).attr('href'); //Get Popup href to define size

			

				//Pull Query & Variables from href URL

				var query= popURL.split('?');

				var dim= query[1].split('&');

				var popWidth = dim[0].split('=')[1]; //Gets the first query string value

			

				//Fade in the Popup and add close button
				
				if (count==0) {

				$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://www.artfactory.es/assets/img/close.png" class="btn_close" title="Close Window" alt="Close" border="0" /></a>');
				
				count = 1;

				}

				//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css

				var popMargTop = ($('#' + popID).height() + 80) / 2;

				var popMargLeft = ($('#' + popID).width() + 80) / 2;

			

				//Apply Margin to Popup

				$('#' + popID).css({

					'margin-top' : -popMargTop,

					'margin-left' : -popMargLeft

				});

			

				//Fade in Background

				$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.

				/*$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies */

			

				return false;

			});

			

			//Close Popups and Fade Layer

			$('a.close, #fade,a.close2' ).live('click', function() { //When clicking on the close or fade layer...
																 
				count = 0;
				
				$('#fade , .popup_block').fadeOut(function() {

					$('#fade, a.close').remove();  //fade them both out

				});

				return false;

			});

            

        });//Close Function





        var timeout         = 500;

        var closetimer		= 0;

        var ddmenuitem      = 0;

        

        function jsddm_open()

        {	jsddm_canceltimer();

            jsddm_close();

            ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

			

        function jsddm_close()

        {	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

        

        function jsddm_timer()

        {	closetimer = window.setTimeout(jsddm_close, timeout);}

        

        function jsddm_canceltimer()

        {	if(closetimer)

            {	window.clearTimeout(closetimer);

                closetimer = null;}}

        

        $(document).ready(function()

        {	

		

			$('#jsddm > li').bind('mouseover', jsddm_open);

            $('#jsddm > li').bind('mouseout',  jsddm_timer);

			

		});
		
		
	PEPS = {};
	
	PEPS.rollover = 
	{
	   init: function()
	   {
		  this.preload();
		  
		  $(".ro").hover(
			 function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, 
			 function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
		  );
	   },
	
	   preload: function()
	   {
		  $(window).bind('load', function() {
			 $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
		  });
	   },
	   
	   newimage: function( src )
	   { 
		  return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0]; 
	   },
	
	   oldimage: function( src )
	   { 
		  return src.replace(/_o\./, '.'); 
	   }
	};

        

        document.onclick = jsddm_close;
