(function ($) {

/**
 * Open Mollom privacy policy link in a new window.
 *
 * Required for valid XHTML Strict markup.
 */
Drupal.behaviors.mollomPrivacy = {
  attach: function (context) {
    $('.mollom-privacy a', context).click(function () {
      this.target = '_blank';
    });
  }
};

/**
 * Attach click event handlers for CAPTCHA links.
 */
Drupal.behaviors.mollomCaptcha = {
  attach: function (context, settings) {
    // @todo Pass the local settings we get from Drupal.attachBehaviors(), or
    //   inline the click event handlers, or turn them into methods of this
    //   behavior object.
    $('a.mollom-switch-captcha', context).click(getMollomCaptcha);
  }
};

/**
 * Fetch a Mollom CAPTCHA and output the image or audio into the form.
 */
function getMollomCaptcha() {
  // Get the current requested CAPTCHA type from the clicked link.
  var newCaptchaType = $(this).hasClass('mollom-audio-captcha') ? 'audio' : 'image';

  var context = $(this).parents('form');

  // Extract the Mollom session id and form build id from the form.
  var mollomSessionId = $('input.mollom-session-id', context).val();
  var formBuildId = $('input[name="form_build_id"]', context).val();

  // Retrieve a CAPTCHA:
  $.getJSON(Drupal.settings.basePath + 'mollom/captcha/' + newCaptchaType + '/' + formBuildId + '/' + mollomSessionId,
    function (data) {
      if (!(data && data.content)) {
        return;
      }
      // Inject new CAPTCHA.
      $('.mollom-captcha-content', context).parent().html(data.content);
      // Update session id.
      $('input.mollom-session-id', context).val(data.session_id);
      // Add an onclick-event handler for the new link.
      Drupal.attachBehaviors(context);
      // Focus on the CATPCHA input.
      $('input[name="mollom[captcha]"]', context).focus();
    }
  );
  return false;
}

})(jQuery);
;
 ( function($) {

 	$(document).ready(
     
 	function(){
    $(".btnDone").click(function(event){
     	 

     	//Grab the Fabric Browser Color attribute numbers and the Fabric Grade attribute number and the price variable from the url that called the view
		var urlQuery = window.parent.document.getElementById('#link');
		var splits = String(urlQuery).split('attribute=');
		var splitagain = String(splits[1]).split('&');
    	var number = splitagain[0];
    	var splitsfabric = String(splitagain[1]).split('fabric_grade=');  	
    	var fabricnumber = splitsfabric[1];
    	var test = '#edit-attributes-'+number;		
		var fabricnumgrade = '#edit-attributes-'+fabricnumber;
		var price_var = String(splitagain[2]).split('price_variable=');  	
    	var price_variable = price_var[1];
		
		//Grab the Fabric Browser Color choice and Fabric Grade selected from the View
		fabric = $(this).attr('href');
		var splits1 = String(fabric).split('=');		
		var swatchandurl = splits1[0];
		var splits2 = String(splits1[0]).split('/');		
		var swatch = splits2[2];
		var fabricgrade = splits2[3];
		
		$('.fabricchoice',top.document).replaceWith('<div class = fabricchoice> <p>Your Fabric Choice: '+swatch+'</p></div>'); //pass back the swatch number
		// Set the Fabric Browser select box 
		$(test+" option:contains('"+ swatch +"')",top.document).attr('selected', 'selected');        
          
        $(fabricnumgrade+" option:contains('"+ fabricgrade +"')",top.document).attr('selected', 'selected');          
      	var price_select = $(fabricnumgrade+" option:selected",top.document).text();
		var split_price = String(price_select).split('$');
		var price = split_price[1];
		var Priceint = (parseInt(price) * price_variable);
		var priceTotal = Priceint.toFixed(2);
		var Pricestring = '$'+ priceTotal;
		if (price_variable =="NULL"){// if price variable is empty do not do anything
       } else {
       	$('.sell-price .uc-price',top.document).replaceWith('<span class = uc-price>'+Pricestring+'</span>'); //pass back the swatch number
		$('.display-price .uc-price',top.document).replaceWith('<span class = uc-price>'+Pricestring+'</span>'); //pass back the swatch number
       };
   		parent.jQuery.fn.colorbox.close();  	
      	return false;	
 		});
 		
 	$(".btnDone2").click(function(event){
     	var urlQuery = window.parent.document.getElementById('#link2');
		var splits = String(urlQuery).split('attribute=');
    	var number = splits[1];
    	var test = '#edit-attributes-'+number;
    	
    	pillow = $(this).attr('href');
		$('.fabricchoice2',top.document).replaceWith('<div class = fabricchoice2> <p>Your Fabric Choice: '+pillow+'</p></div>');
		$(test+" option:contains('"+ pillow +"')",top.document).attr('selected', 'selected');        
        parent.jQuery.fn.colorbox.close();  	
      	return false;	
 		});
 	});
 } ) ( jQuery );

;

