$(function(){

  // KMB - transform dropdown inputs into links for Size/Color selection
  $(".v_inputs")
    .find("div").addClass("vbLine ItemSizes").end()
    .find("label").prepend("SELECT ").end()
    .find("select").change(function() {
      sel = $(this).val();
      $(this).nextAll("a").remove().end()
        .after($(this).find("option").map(function() {
          v = $(this).attr("value");
          return (v.length > 0 ? '<a href="#" class="'+ (v == sel ? 'selected' : '') + '">' + v + '</a>' : '');
        }).get().join("")).hide();
      $(this).nextAll("a").click(function(e) {
        e.preventDefault();
        $(this).addClass("selected").prevAll("select").val($(this).html()).parent().parent().find("select").trigger("change");
        return false;
      });
    }).trigger("change");
    
  // KMB - show alert if user didn't select a Size/Color
  $("#add_to_cart").click(function (e) {
    if ($(this).parents("form").find("select")) {
      if ($(this).parents("form").find('input[name="options"]').val() == "") {
        alert("Please select an option.");
        e.preventDefault();
        return false;
      }
    }
  });

	$('.cartItem').each(function(){
		color = $(this).find('.option_value').text().replace(/^(.*?)\//,'');
		size = $(this).find('.option_value').text().replace(/\/(.*?)$/,'');
		$(this).find('.selectedcolor').text(color);
		$(this).find('.selectedsize').text(size);
	});
	
	$('a.RemoveItem').click(function(){
		mp = $(this).parent().parent();
		mp.animate({opacity: 0,display:"none"}, 300 );
		mp.animate({height:'0px',margin:'0px',padding:'0px', border:'0'}, 700 );
		
		$.post("cart_remove_item.php", {
		  row_id: $(this).attr('alt')
		});
		
		return false;
	});
	
	$('.openVidPrev').click(function(){			
    openVideo(getUrl('prev'));
  });
  $('.openVidNext').click(function(){			
    openVideo(getUrl('next'));
  });
	
	$('#OpenCart').click(function(){
		if ($('#mycart').css('display') == 'none'){
			$(this).text('CLOSE');
			$('#mycart').css('display','inline');
		}
		else{
			$('#mycart').css('display','none');	
		}
	});
	
	$('.IItemThumbs a').click(function(){
		$('img.item-photo').attr('src',$(this).attr('href'));
		return false;
									   
	});
	
	$('a.RemoveItem').click(function(){
		mp = $(this).parent().parent();
		mp.animate({opacity: 0,display:"none",height:'0px',margin:'0px',padding:'0px'  }, 1000 );
		return false;
	});	
			
});
