		$(function() {

		// Select all links with lightbox class
		$('a.lightbox').lightBox(); 
        $('label.pre').labelOver('over');
		$("#tabs").tabs();

		MopSliderInitialize(); 
		PicClicker();

		    $('#slideshow').cycle({
		    	speed:  'slow', 
		    	timeout: 7000, 
		        pager:      '#nav',
		        pagerEvent: 'mouseover',
		    	next:   '#next2', 
		    	prev:   '#prev2' 
		    });
		});

$(document).ready( function()
{
   PEPS.rollover.init();
});

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\./, '.'); 
   }
};


    $(function(){
      $(".myMenu").buildMenu(
      {
        template:"/js/menuVoices.html",
        additionalData:"pippo=1",
        menuWidth:200,
        openOnRight:false,
        menuSelector: ".menuContainer",
        iconPath:"ico/",
        hasImages:true,
        fadeInTime:100,
        fadeOutTime:300,
        adjustLeft:2,
        minZindex:"auto",
        adjustTop:60,
        opacity:.95,
        shadow:true,
        openOnClick:false,
        closeOnMouseOut:true,
        closeAfter:1000
      });

      $(document).buildContextualMenu(
      {
        template:"/js/menuVoices.html",
        menuWidth:200,
        overflow:2,
        menuSelector: ".menuContainer",
        iconPath:"ico/",
        hasImages:false,
        fadeInTime:100,
        fadeOutTime:100,
        adjustLeft:0,
        adjustTop:0,
        opacity:.99,
        closeOnMouseOut:false,
        onContextualMenu:function(){}, //params: o,e
        shadow:true
      });

    }
            );

    //this function get the id of the element that fires the context menu.
    function testForContextMenu(el){
      if (!el) el= $.mbMenu.lastContextMenuEl;
      alert("the ID of the element is:   "+$(el).attr("id"));
    }






function change(what) {
	var isGas;
	var passedGas; // heh
	var isCommercial;
	var passedCommercial;
    var value = what.options[what.selectedIndex].id;
    
		if (value.indexOf("gas-fired") >= 0 ) 
		{
			isGas	=	'isGas=true';
			//alert('gas chosen');
		}
		else
		{
			isGas	=	'isGas=false';
		}
		//return false;
  		$('.container').html('<p><img src="/images/loadingAnimation.gif" width="208" height="13" /></p>');

		$('.container').load('/products/selector/selectorloop-new.asp?'+isGas, function() {


		MopSliderInitialize();
		PicClicker();

    });

}


	function PicClicker() {
		
		

				$('.pic').click(function() {
				var thepageurlpath = window.location.pathname;

				if ( thepageurlpath.indexOf("products") !== -1 ) {

						var ProdID =  $(this).attr("id").replace("picid-", "");
						ViewPre(ProdID);
					} else {
						var ProdID =  $(this).attr("id").replace("picid-getPreview.asp?s=", "");
						ViewJump(ProdID);
		};



				});
		
	}


    function ViewJump(ProdID){


	//window.location = "/Products/ShowProduct.asp?product=" + ProdID ;
	window.location = ProdID ;


    };





    function ViewPre(ProdID){



  		$('#selectorprods').html('<p><img src="/images/loadingAnimation.gif" width="208" height="13" /></p>');

		$("#selectorprods").load("/products/selector/previews/" + ProdID + ".asp", function(){ 

		}).dialog({
			title: "Preview ",
			autoOpen: false,
			bgiframe: false,
			width: 620,
			height: 420,
			modal: true
			}).dialog('open');

    };
	
	function PicImageHover() {
		
		
		$(".pic img").mouseover(
			
			function(){
				var TheImgID = this.id;
				var TheImgIDName = '#'+TheImgID;
				var TheDescIDName = TheImgIDName.replace('pic-','desc-');
				
				$(TheImgIDName).css("height", "150px");
				$(TheImgIDName).css("margin", "-10px");
				$(TheDescIDName).css("color", "#C42437");
				$(TheDescIDName).css("padding-top", "10px");
				
			}
			
		);
		
		
	}

	function PicImageOut() {
		
		
		$(".pic img").mouseout(
			
			function(){
				var TheImgID = this.id;
				var TheImgIDName = '#'+TheImgID;
				var TheDescIDName = TheImgIDName.replace('pic-','desc-');
				
				$(TheImgIDName).css({height:"128px"});
				$(TheImgIDName).css({margin:"0px"});
				$(TheDescIDName).css({color:"#000000"});
				$(TheDescIDName).css({padding:"0px"});
				
				
				$(TheImgIDName).css("height", "128px");
				$(TheImgIDName).css("margin", "0px");
				$(TheDescIDName).css("color", "#000000");
				$(TheDescIDName).css("padding-top", "0px");
				
			}
			
		);
		
		
	}
	
	
	function MopSliderInitialize() {
		
		
		$("#slider").mopSlider({
			'w':900,
			'h':180,
			'sldW':800,
			'btnW':300,
			'itemMgn':10,
			'indi':"Slide to View All - Click Product to Preview",
			'type':'tutorialzine',
			'shuffle':0
		});
		
	}
