$jq(function() {

    $jq.fn.equalHeight = function() {
           // find the tallest height in the collection
            tallest = 0;
            this.each(function(){
                thisHeight = $jq(this).height();
                if( thisHeight > tallest)
                    tallest = thisHeight;
            });

            // set each items height to use the tallest value found
            this.each(function(){
                $jq(this).height(tallest);
            });

            tallest = tallest + 11;
            $jq("#outercontainer .scrollable").height(tallest);
            $jq("#prodPageScroll .items").height(tallest);
            $jq("#productDetailContainer").addClass("hideDetails");
            $jq("#productDetailContainerBotEdge").addClass("hideDetails1");
        }

      $jq.fn.itemCount = function() {
                 $jq("#less").show();
                 $jq("#more").show();
                var itemCounter =$jq("#prodPageScroll").children().size();
                if (itemCounter <= 5)
                {
                  $jq("#more").addClass("disabled");
                }                                            
          }



			$jq("#more .next").click( function(){
			  $jq("#prodPageScroll .active").removeClass("active");
			  $jq("#prodPageScroll .hideDetails").removeClass("hideDetails");
        var detailSlot =$jq("#productDetailContainer .detailObjects");
        var detailContent =$jq("#productDetailContainer .productShow");

          if (detailContent.length > 0)
          {
            var theProdDiv = $jq(detailContent.get(0) );
            var theProdId = theProdDiv.attr("id");
            initializeFormElements(theProdId);
           }

          $jq("#productDetailContainerBotEdge").removeClass("productShow1").addClass("hideDetails");
          $jq("#productScrollBotEdge").removeClass("hideDetails").addClass("productShow1");

          $jq(detailSlot.hide());
          $jq("#productDetailContainerBotEdge").hide();
          $jq("#productDetailContainer").hide();
          $jq("#productDetailContainer").removeClass("productShow").addClass("hideDetails");
			  } );



			$jq("#less .prev").click( function(){
			  $jq("#prodPageScroll .active").removeClass("active");
			  $jq("#prodPageScroll .hideDetails").removeClass("hideDetails");
        var detailSlot =$jq("#productDetailContainer .detailObjects");
        var detailContent =$jq("#productDetailContainer .productShow");

          if (detailContent.length > 0)
          {
            var theProdDiv = $jq(detailContent.get(0) );
            var theProdId = theProdDiv.attr("id");
            initializeFormElements(theProdId);
          }

          $jq("#productDetailContainerBotEdge").removeClass("productShow1").addClass("hideDetails");
          $jq("#productScrollBotEdge").removeClass("hideDetails").addClass("productShow1");

  			  $jq(detailSlot.hide());
          $jq("#productDetailContainerBotEdge").hide();
          $jq("#productDetailContainer").hide();
  			  $jq("#productDetailContainer").removeClass("productShow").addClass("hideDetails");
			  } );
			  
			  $jq("#productDetailContainer .closeScroll").click( function(){
			  		//need to reset the qty and drop downs
			  	$jq("#prodPageScroll .active").removeClass("active");
			  	$jq("#prodPageScroll .hideDetails").removeClass("hideDetails");

          var thisProductId = ($jq (this)).parent().parent().attr("id");
          initializeFormElements(thisProductId);

          var detailSlot =$jq("#productDetailContainer .detailObjects");
			    $jq(detailSlot.hide());
			    $jq("#productDetailContainer").removeClass("productShow").addClass("hideDetails");
          $jq("#productDetailContainerBotEdge").removeClass("productShow1").addClass("hideDetails");
          $jq("#productScrollBotEdge").removeClass("hideDetails").addClass("productShow1");
          $jq("#productDetailContainerBotEdge").hide();
          $jq("#productDetailContainer").hide();			    
			  } ); 					  			  

			$jq("#prodPageScroll .productSliders").click( function(){
          //get the ID of div they clicked on
          var currentId = $jq(this).attr("id");
          var updatedId =  currentId;

          //detail container
          var detailContent =$jq("#productDetailContainer .productShow");

          //initialize any input fields and drop downs
         if (detailContent.length > 0)
          {
            var theProdDiv = $jq(detailContent.get(0) );
            var theProdId = theProdDiv.attr("id");
            initializeFormElements(theProdId);
          }

          //is there content in the detail container
          var existingDetail = $jq(detailContent.get(0) );
          var existingProdId = existingDetail.attr("id");
           //hide the existing product
          $jq("#"+existingProdId).removeClass("productShow");

			   //initialize the details text link
        $jq("#prodPageScroll .hideDetails").removeClass("hideDetails");

          //determine if they clicked on a suite or product
          if (currentId.indexOf("suite")== -1 )
          {
           var suiteStripped = currentId.substring(5);
           var updatedId = suiteStripped;
          }
          else{
            var suiteStripped = currentId.substring(5);
            var updatedId = "suiteDetail"+  suiteStripped;
          }

          //hide the details text for the product they clicked on
          var detailDivText = $jq(this).children("div");
          if (detailDivText.length > 1)
          {
            var detailTextId = $jq(this).children("div").get(1).id;
            $jq("#"+detailTextId).addClass("hideDetails");
          }

          var omnitIdCheck = $jq("#"+updatedId).children("div");
          if (omnitIdCheck.length > 0)
          {
            var omnitId = $jq("#"+updatedId).children("div").children("div").get(0).id;                        
            var formatedOmnitureId = omnitId.substring(15)
            var setOmnit = setOmnitureClick(formatedOmnitureId);
          }

          var detailDiv = $jq("#"+ updatedId).addClass("productShow");
          var detailSlot =$jq("#productDetailContainer div.detailObjects");

          $jq("#productDetailContainerBotEdge").show();
          $jq("#productDetailContainer").show();
          $jq("#productDetailContainer").removeClass("hideDetails").addClass("productShow");
          $jq("#productScrollBotEdge").removeClass("productShow1").addClass("hideDetails");
          $jq("#productDetailContainerBotEdge").removeClass("hideDetails1").addClass("productShow1");
          $jq(detailSlot.removeClass("hideDetails").removeClass("productsDetailHidden"));
          $jq(detailSlot.removeClass("productsDetailHidden"));
          $jq(detailDiv.show());
			    $jq(detailSlot.show());
			  } );			  
			  
			  function initializeFormElements(theProdId)
			  {
              if (theProdId.indexOf("suite")== -1 )
              {
                  var dd1Name = theProdId + "DD1";
                  var dd2Name = theProdId + "DD2";
                  var checkDD1 = $jq("select[name$="+  dd1Name + "]");
                  var checkDD2 = $jq("select[name$="+  dd2Name + "]");

                  if (checkDD1.length > 0)
                  {
                    populateDD1(theProdId);
                  }
                  if (checkDD2.length > 0)
                  {
                    populateDD2(theProdId);
                  }

                $jq("#productDetailContainer input[name^='qty']").val("0");
              }
              else{
              var prodIdTrimmed = theProdId.substring(11);
              var suiteChildren = $jq("#product"+prodIdTrimmed).children();
              var previousId;
                 for( var i=0; i < suiteChildren.length; ++i ) {                   
                      var suiteChild = suiteChildren.get(i);
                      var suiteChildId = suiteChild.id;

                       if(previousId == suiteChildId)
                        {
                          break;
                        }
                        var dd1Name = suiteChildId + "DD1";
                        var dd2Name = suiteChildId + "DD2";
                        var checkDD1 = $jq("select[name$="+  dd1Name + "]");
                        var checkDD2 = $jq("select[name$="+  dd2Name + "]");

                        if (checkDD1.length > 0)
                        {
                          populateDD1(suiteChildId);
                        }
                        if (checkDD2.length > 0)
                        {
                          populateDD2(suiteChildId);
                        }
                      previousId =suiteChildId;
                 }
                 $jq("#productDetailContainer input[name^='qty']").val("0");
              }
			  }

$jq("div.scrollable").scrollable({
  size: 5,
 prev:"#less",
 next:"#more"
});

});


  function setOmnitureClick(prodId) {
	var scrollOmn = s_gi(s_account);
	scrollOmn.pageName = 'YMALDetail';
	scrollOmn.prop1 = prodId+ ":YMALDETAIL";
	scrollOmn.channel = 'Misc';
	scrollOmn.products = '';
	scrollOmn.events = '';
	var s_code=scrollOmn.t();if(s_code)document.write(s_code);
  }
