 $(document).ready(function(){
  // Navigation
   $('.primary.navigation li').hover(function(){
		   $('>a',this).css({background: 'white', color: '#224566'});
		   $('ul',this).show();
   }, function(){
		   $('>a',this).css({background: '', color: ''});		   
		   $('ul',this).hide();
   });
  jQuery.ifixpng('assets/images/pixel.gif');
   $('.chef,#featured-content img,.burst,.png').ifixpng();
   
   
   /******* NAPKIN BAND FUNCIONALITY ********************
   /    4" https://www.restaurantdiscountwarehouse.com/showitem.aspx?productID=NBWH&CategoryID=NB
   /	6" https://www.restaurantdiscountwarehouse.com/ShowItem.aspx?productID=NB235&CategoryID=NB
   /
   */
   
   // SKUS
   smallBands = new Object();
   
   smallBands.White = new Object();
   smallBands.White.color = 'WH';
   smallBands.White.sku = '110';

   smallBands.Burgundy = new Object();
   smallBands.Burgundy.color = 'BU';
   smallBands.Burgundy.sku = '115';

   smallBands.Cream = new Object();
   smallBands.Cream.color = 'CR';
   smallBands.Cream.sku = '130';

   smallBands.Red = new Object();
   smallBands.Red.color = 'RED';
   smallBands.Red.sku = '135';

   smallBands.Blue = new Object();
   smallBands.Blue.color = 'BL';
   smallBands.Blue.sku = '125';

   smallBands.Green = new Object();
   smallBands.Green.color = 'GR';
   smallBands.Green.sku = '120';
   
   largeBands = new Object();
   largeBands.White = '210';
   largeBands.Burgundy = '215';
   largeBands.Cream = '230';
   largeBands.Red = '235';
   largeBands.Blue = '225';
   largeBands.Green = '220';
      
   $('#addtocart').click(function(){
   		// Get parameters
   		//console.log('start');
   		//console.log($('#bands :radio:checked').val());
   		cursku = makeDBSku(getSize(),getColor());
   		$('#bands').attr('action','/AddToCart.aspx?productID='+cursku+'&CategoryID=NB');
   		$(this).parents("form:eq(0)").submit();
   		return false;
   });
  
  $('#color a').click(function(){
   		$('#bands #color span').empty().append($(this).attr('color'));
   		$('#color a').removeClass(' active');
   		$(this).addClass('active');
   		$('#NBImage').attr('src','assets/images/product_nb_'+getColor()+'.png');
   		$('#NBImage').ifixpng();
   		
   });
   
   $('.formitem').click(function(){updateProduct();});


   getSize = function(){
   		size = $('#bands :radio:checked').val();
   		return size;
   }
   
   getColor = function(){
   		color = $('#bands #color span').text();
   		return color;
   }
   
   makeSku = function(size,color){
   		if(size.length > 0){
			switch(size)
			{
			case 'small':
				color = $('#bands #color span').text();
				suffix = smallBands[color].sku;
			  break;    
			case 'large':
				color = $('#bands #color span').text();
				suffix = largeBands[color];
			  break;
			default:
				alert('You must select a size.');
			}
			//console.log('suffix: '+suffix);
   		}else{
			alert('You must select a size.');
			return false;
   		}
   		cursku = 'NB'+suffix;
   		return cursku;
   }
   
   makeDBSku = function(size,color){
   		if(size.length > 0){
			switch(size)
			{
			case 'small':
				color = $('#bands #color span').text();
				suffix = smallBands[color].color;
			  break;    
			case 'large':
				color = $('#bands #color span').text();
				suffix = largeBands[color];
			  break;
			default:
				alert('You must select a size.');
			}
			//console.log('suffix: '+suffix);
   		}else{
			alert('You must select a size.');
			return false;
   		}
   		cursku = 'NB'+suffix;
   		return cursku;
   }
   
   
   updateProduct = function(size,color){
   		size = getSize();
   		color = getColor();
   		cursku = makeSku(size,color);
   		$('#sku').empty().append(cursku);
   		$('#modelcolor').empty().append(color);
   }


	//trigger the second color
	$('#color a:eq(1)').trigger('click');
 });
