$(document).ready(function(){
  		 

		 /* This is the email form rollover*/
		 $(".subscribe-form .btn-submit").hover(function() {
   			$('.subscribe-form').css('background-image', 'url(images/bg-subscribe-form_ov.gif)');
		 },function() {
   			$('.subscribe-form').css('background-image','url(images/bg-subscribe-form.gif)');
		 });
		
		
		$("#swatchwindow").hide();
		 /* color swatches */
		 $("a.popup").addClass(function() {return $(this).attr('title');});
		
		/* Add swqatches to the items */
		$("fieldset").each(function(index) {	
			var tabClass = $(this).attr('class');
			var colorlist = 'fieldset.' + tabClass +' .catProdAttributeItem select option';
			
			$(colorlist).each(function() { 	
				var colorPlace = 'ul.'+ tabClass;
				if($(this).text() != '-- Please select --') {
				var style = $(this).text().trim();
				var style = style.replace(/([#])/,'');
				var style = style.replace(/([!])/,'');
				var style = style.toLowerCase().replace(/ /g, '-');
				
				$(colorPlace).append('<li><a href="#" class="color-1 popup '+style+'" title="'+$(this).text()+'" alt="swatch">'+$(this).text()+'</a></li>');
				}
				
				
			});		
		 });
	
		/* Move the popup window */
		 $("body").mousemove(function(event){
			 
				$("#swatchwindow").css({left:event.pageX-80, top:event.pageY-250});
		 });
		 
		 /* Get the swatch descriptions */
		 $.ajax({
      url: 'descriptions.json',
      dataType: 'json', 
      cache: false, // 'cache: false' must be present for IE 7 & 8
      success: function(data) {
		 
 			 var catItems = [];
 			$.each(data, function(key, val) {
    			catItems.push('<li id="' + key + '">' + val + '</li>');
 				});
			$('.swatchdesc').html(catItems.join(''));
	  }
		});

		 
		 /* populate popup window */
		 $("a.popup").hover(function () {
			    var type = $(this).attr('title');
				var type = type.replace(/([#])/,'');
				/* Description*/
				var threeword = 'li#'+type;
				var threeword = threeword.replace(/ /g,'');
				var threedesc = $(threeword).html();
				$("#swatchwindow span").html(threedesc);
				/* Image*/
				var img = type.toLowerCase().replace(/ /g, '');
				var img = img.trim();
				var img = img.replace(/[#]/g, '');
				var src = "images/swatches/"+img+".jpg";
				$("#swatchimg").attr("src", src);
				/* Title*/
				var desc = $(this).attr('title');
				$("#swatchwindow strong").html(desc);
				
				$("#swatchwindow").show();
			}, 
			function () {
				$("#swatchwindow").hide();
			}
			);

	

	});
