    var giftdescriptions = {};
    giftdescriptions['ACC-AIRF-CMOSCK'] = 'Salute the Service - Go Airforce!';
    giftdescriptions['ACC-ARMY-CMOSCK'] = 'Salute the Service - Go Army!';
    giftdescriptions['ACC-MRN-CMOSCK'] = 'Salute the Service - Go Marines!';
    giftdescriptions['ACC-NAVY-CMOSCK'] = 'Salute the Service - Go Navy!';

    giftdescriptions['COC-CARML-PRLNE-COC'] = 'The taste of a sweet New Orleans praline swirls into caramel-drizzled cocoa for a decadent taste like no other. 7.0 oz. 7 Servings per container.Contains milk & soy.';
    giftdescriptions['COC-CHOC-HZLNUT-MCHA'] = 'European chocolate blends with robust, fresh-roasted Arabica coffee and aromatic hazelnut flavor.7oz. 7 Servings per container. Contains milk and soy products.';
    giftdescriptions['COC-CHOC-TRIO-COC'] = 'Chocolate Trio Cocoa. Three times the charm! White, milk, and dark chocolates combine for an over the top cocoa experience! 7 oz. 7 Servings per container.Contains milk and Soy.';
    giftdescriptions['COC-DBL-DRK-CHOC'] = 'Reminiscent of a deep, dark chocolate bar, this bittersweet treat is for the true chocolate connoisseur.7 oz. 7 Servings per container.Contains milk &soy.';


String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

    function selectionTips(descriptions)
    {

        var $this = this;
        this.descriptions = descriptions;

         this.initiate = function(){

 
                    var altdata = '';



      $('a.ui-selectmenu').bt({
                            fill: '#ffffff',
                              strokeStyle: '#666666',
                              shadow: true,
                            shadowOffsetX: 1,
                            shadowOffsetY: 1,
                            shadowBlur: 3,
                            shadowColor: 'rgba(0,0,0,.9)',
                            shadowOverlap: false,
                            noShadowOpts: {strokeStyle: '#B7B7B7', strokeWidth: 2},
                            positions: ['left'],
                              spikeLength: 10,
                              spikeGirth: 10,
                              padding: 8,
                              cornerRadius: 2,
                              cssStyles: {
                                fontFamily: '"lucida grande",tahoma,verdana,arial,sans-serif',
                                fontSize: '11px'},
                              trigger: 'none',
                              preShow: function(box){


                              },
                              contentSelector: function(){

                                  return altdata;
                              },
                              showTip:function(box){

                                $(box).show();


                              },
                               hideTip: function(box, callback) {
                                $(box).hide();

                        },
                              width: 350
    });


    $('a.ui-selectmenu').click(function(){
        var anchor = this;
        var id = $(this).attr('id');
        
        idS = id.split('_');
        var dropId = idS[2];
        var origId = idS[0];
        var parent = $("#"+id);
        $(anchor).data('original',$(anchor).find('span').html());
//console.log(parent)
        $("#"+origId+'_menu_'+dropId).find('a').unbind().mouseover(function(){
                                   

                                    var current = $(this).html();
                                    var fixcurrent = current.trim();
                                    fixcurrent = current.replace(/\(members only\)/i,'',fixcurrent);
                                    altdata = $this.parseTipData(parent,fixcurrent);

                                    if(altdata!='') parent.btOn();
                                    $(anchor).find('span').html(current);
                                }).click(function(){
                                    $(this).unbind('mouseout');
                                    $(anchor).find('span').html($(this).html());
                                    parent.btOff();
                                }).mouseout(function(){
                                    $(anchor).find('span').html($(anchor).data('original'));
                                    parent.btOff();
                                })


    });


  
    }

    this.parseTipData = function(parent,current)
    {
        var html = '';
        
  

       

        $.each(this.descriptions.items, function(i,item){
        
            if(item.name+' ' == current || item.name==current)
            {
                if(item.thumbnail.match(/http\:/)!=null) item.thumbnail = item.thumbnail.replace(/http/,'https');
                html='<div class="omnitip_img"><img src="'+item.thumbnail+'" border="0"></div><div class="omnitip_text"><h4>'+item.name+'</h4><p>'+item.description+'</p>';

            }
        });

        return html;
    }


    }

    $(document).ready(function(){

         var d = getDomain();
         var url = d+'clubProductDetailsAjaxAction.do';
         var $this = this;

         var p = {};
         var descriptions = null;
         if(descriptions==null)
                    {
                 $.ajax({
                       url: url,
                       data:p,
                       dataType: 'jsonp',
                     //  processData: false,
                       success: function (data, textStatus) {
                               descriptions = data;
                                var st = new selectionTips(descriptions);
                                st.initiate();
                        },
                                        error: function(XMLHttpRequest, textStatus, errorThrown){
                        //   ot.responseError(XMLHttpRequest, textStatus, errorThrown)
                        },
                                        beforeSend: function (XMLHttpRequest) {
                          // $($this.form).parents('div.omnitip').append('<div class="omnitip_loading"><div class="omnitip_loader"><img src="/resources/images/ajax-loader.gif" alt="loading" /></div><div class="omnitip_transparency"></div></div>');
                        },
                                        complete: function (XMLHttpRequest) {
                           // $($this.form).parents('div.omnitip').find('.omnitip_loading').fadeOut(800,function(){$(this).remove();})
                        }
                    });
                    }

        $('select[name!="Gift"].coffeeselection').selectmenu({maxHeight: 350,menuWidth:300,width:220,style:'dropdown'});
        $('select[name="Gift"]').selectmenu({maxHeight: 350,menuWidth:300,width:200,style:'dropdown'});

        $('select[name*="Grind"]').selectmenu({maxHeight: 150,menuWidth:100,width:100,style:'dropdown'});
        $('select[name*="Caffeine"]').selectmenu({maxHeight: 150,width:80,style:'dropdown'});
  
        $("#restore").click(function(){

            for(i=1;i<=4;i++){

               var $this =  $('#CoffeeSelection'+i);
               var n = $this.attr('name');

               if(i==1) $this.val('COF-HB-OD-02-8oz');
               if(i==2) $this.val('COF-HB-MIZ-02-8oz');
               if(i==3) $this.val('COF-FC-SS-02-8oz');
               if(i==4) $this.val('COF-FB-BFF-07');
               var sel = $this;
              
               $this.find('option').each(function(){
                  
                  if($(this).val() == sel.val()){

                      sel.parents('td').find('span.ui-selectmenu-status').html($(this).html());
                  }
               });


              

            }

           
          
        });

$("a").each(function(){
              if($(this).attr('role')=='button' && $(this).text()=='Regular'){
                  var id = $(this).attr('id');
                  var idS = id.split('_');
                  var realId = parseInt(idS[2]);
                  $(this).click(function(){
                      var coffee = $(this).parents('tr').find('.coffeeselection');

            var doDecaf = true;
            
            $.each(descriptions.items, function(i,item){
           
            if(item.sku==$(coffee).val() && item.has_decaf=="false")
            {
                doDecaf=false;
            }
            
            });


                       if(doDecaf==false)
                       {
                           
                           $("#_menu_"+realId+" li").each(function(){
                               if($(this).text()=='Decaf') $(this).hide();
                           });
                       }
                       else
                           {
                                $("#_menu_"+realId+" li").each(function(){
                               if($(this).text()=='Decaf') $(this).show();
                           });
                           }
                  })
              }
           })


   



    


 $('.giftinfo').bt({
                            fill: '#ffffff',
                              strokeStyle: '#666666',
                              shadow: true,
                            shadowOffsetX: 1,
                            shadowOffsetY: 1,
                            shadowBlur: 3,
                            shadowColor: 'rgba(0,0,0,.9)',
                            shadowOverlap: false,
                            noShadowOpts: {strokeStyle: '#B7B7B7', strokeWidth: 2},
                            positions: ['right'],
                              spikeLength: 10,
                              spikeGirth: 10,
                              padding: 8,
                              cornerRadius: 2,
                              cssStyles: {
                                fontFamily: '"lucida grande",tahoma,verdana,arial,sans-serif',
                                fontSize: '11px'},
                              trigger: 'hover',
                              preShow: function(box){


                              },
                              contentSelector: function(){

                                   var imageRoot = '/resources/images/giftthumbs/';
                                    var thisID = $(this).attr('id');
                                        var thisID_s = thisID.split('_');
                                        var id = thisID_s[1];
                                        var img = '';
                                        var desc = '';
                                    var title = '';
                                        var selectElement = $(a).parents('td').prev().children('select');
                                      //  console.log(selectElement);
                                        var selected = selectElement.val();


                                        selectElement.children('option').each(function(){
                                                if($(this).val() == selected)
                                                {
                                                        title = $(this).text();
                                                        if(selected.match(/FRAC/)==null) img = '<img width=100 height=100 src="'+imageRoot + title.replace(/\s/g,'')+'.jpg" style="width:100px;height:100px;" />';
                                                        else img = '';
                                                }
                                        });

                                        desc = giftdescriptions[selected];
                                       // console.log(title+':'+desc)
                                        var html = '';

                                        if(img!='') html+= '<div class="omnitip_img">'+img+'</div>';
                                        html+='<div class="omnitip_text" ><h4>'+title+'</h4>';
                                html+='<p>'+desc+'</p>';
                                        html += '</div>';
                                        return html;
                              },
                              showTip:function(box){
                                $(box).fadeIn(500);
                              },
                               hideTip: function(box, callback) {
                                $(box).fadeOut(500);

                        },
                              width: 350
});




    /*
    	var ttHTML = '<div id="tooltip" class="ntt"><div class="tt_top"></div><div class="tt_content"><div class="tt_img"></div><h3></h3><div class="url"></div><div class="transparency"></div></div><div class="tt_bottom"></div></div>';
   		$("body").append(ttHTML);

        $(".view_coffees").click(function(){
            window.open('https://www.bocajava.com/coffee_descriptions.html', 'CoffeeSelector', 'scrollbars=1,scrollbar=yes,toolbar=no,titlebar=no,height=600,width=400,left=25,screenX=25,top=20,screenY=20'); return false;
        });

        $(".view_details").click(function(){
            window.open('https://www.bocajava.com/coffee_descriptions.html', 'Details', 'scrollbars=1,scrollbar=yes,toolbar=no,titlebar=no,height=600,width=400,left=25,screenX=25,top=20,screenY=20'); return false;
        });



	     $(".coffeeinfo").mouseover(function(){

	     	var thisID = $(this).attr('id');
	     	var thisID_s = thisID.split('_');
	     	var id = thisID_s[1];


	     	var selector = $(this);
	     	var selectorPos = selector.offset(); //position of dropdown
	     	var n = ''
	     	var pic = '';
	     	var desc = '';


	     	var selected = $("#CoffeeSelection"+id).val();


	     	$("#CoffeeSelection"+id+ " option").each(function(){
	     		if($(this).val() == selected)
	     		{
	     			n = $(this).text().capitalize();
					pic = imageRoot + n.replace(/\s/g,'');
	     		}
	     	});

	    	desc = coffeedescriptions[selected];

	     	$("#tooltip .tt_img").html('<img src="'+pic+'.jpg" />');
	     	$("#tooltip h3").html('<b>'+n+'</b><br />'+desc);

	     	var ttTop = parseInt(selectorPos.top) - parseInt($("#tooltip").height()) - 5;
	   		var ttLeft = parseInt(selectorPos.left) - parseInt($("#tooltip").width()/2) + 5;

	     	$("#tooltip").bgiframe().css({top:ttTop + "px",left:ttLeft+"px"}).show();



	     });

	     $(".coffeeinfo").mouseout(function(){
	     	$("#tooltip").hide();
	     });
      */
       $(".coffeeselection").each(function(){
    		checkNoDecaf(this);
    	});

    	$(".coffeeselection").change(function(){
    		checkNoDecaf(this);
    	});

    });

    function checkNoDecaf(coffee)
    {
        if($(coffee).attr('name')=='Gift')var decafselect = $("select[name='GiftCaffeine']");
        else var decafselect = $(coffee).parent().next().next().children('select');
                if($(coffee).val() == 'COF-HB-MIZ-02-8oz'  || $(coffee).val() == 'COF-FB-MCM-8oz' || $(coffee).val() == 'COF-SB-RP-8oz' || $(coffee).val() == 'COF-SB-HK-02' || $(coffee).val() == 'COF-SB-BRZL-8oz' || $(coffee).val() == 'COF-SB-ETH-8oz' || $(coffee).val() == 'COF-FB-FS-8oz' || $(coffee).val() == 'COF-SB-BRZL-8oz' || $(coffee).val() == 'COF-FB-CLC-07' || $(coffee).val()== 'COF-FB-DBB-08' || $(coffee).val()=='COF-SB-ETH-8oz' || $(coffee).val()=='COF-HB-MIZ-02-8oz')
    		{

    			decafselect.html('<option value="regular" selected>Regular</option>');
    		}
    		else
    		{
    			decafselect.html('<option value="regular">Regular</option><option value="decaf">Decaf</option>');
    		}
    }






    

