(function ($) {
Drupal.behaviors.tristatetile = {
attach: function(context, settings) {

	// If Color box is clicked - click() the radio button
	$('.node-type-tiles-series .tst-color-radios .form-item-attributes-field-tile-colors').click(function(event){
		$(this).children('input[name="attributes[field_tile_colors]"]').attr("checked", "checked").change();
	});

	//Checkout: Replace label for Name
	$('.form-item-customer-profile-billing-commerce-customer-address-und-0-name-line label').replaceWith('<label for="edit-customer-profile-billing-commerce-customer-address-und-0-name-line">Attn. (your name) <span class="form-required" title="This field is required.">*</span></label>');

	//Checkout: Email Address Move
	var emailHTML = $('#account-login-container').html();
	$('#account-login-container').remove();
	$('.field-name-commerce-customer-address').after(emailHTML);

	//Checkout: Append Question Hover
	var helptxt = '<em id="whyWantEmail"><a href="#" alt="">Why do we need your email address?</a></em>';
	var divHelp = '<div id="emailHelp">We need it to send you an order confirmation email.</div>';
	$('.form-item-account-login-mail').append(helptxt+divHelp);
	
	//Checkout: On Hover show divHelp
	$("#whyWantEmail a").attr("href", "javascript:void(0)");
	$('#whyWantEmail a').click(function(event){
		$('#emailHelp').slideToggle();
	});

	//Style Radio Button for tile sizes and finishes
  	//$('input[name="attributes[field_tile_sizes]"]').customRadioCheckbox();

	//Checkout Review: Replace 
	$('#commerce-checkout-form-review input.checkout-continue').attr('value', 'Place sample order');

       //Checkout Review: Replace Billing Information
	$('.pane-title td:contains("Billing information")').html("Your information");



	// If Shipping Link is clicked, show the shipping options
	$("a#rush-shipping-link").attr("href", "javascript:void(0)");
	$('a#rush-shipping-link').click(function(event){
		$('#commerce-checkout-form-checkout .commerce_fieldgroup_pane__group_rush_shipping__7').slideToggle();
	});

	// Change border color of tile thubnails
	$('input[name="attributes[field_tile_colors]"]:checked').each(
		function(){
		$(this).parent().css("border", "2px solid #8DC63F");
		}
	);

       // Color Page - Add Message to top
       var colorMessage = '<div id="messages" style="padding-top:10px;"><div class="messages warning">The color selection from your search may not be represented in the series image below.</div></div>';
       
	if($('.page-node-17 #messages').length == 0){
	$('.page-node-17 .view-content').before(colorMessage);
	}
	
}};})(jQuery);;

