$(window).load(function() {  



/*** NOTES FOR OUTSIDE SCRIPTS YOU WILL NOT FIND HERE **********

HEIGHT MATCHING OF THE MAIN CONTENT AREA AND THE SIDE BAR CONTENT
- I used my ht match code and trigger it AFTER THE BLOG feed is loaded in order to get the height of it's content. This is in embed/rw-xml-blog-feed

***/










/***** ADDS THE PAGE COLOR TO THE CALLOUT BOX BORDER *******/

$('.rw_callout_hold').each(function(index){$(this).addClass(window.rw_my_page_color);})
$('.rw_callout_sc_hold').each(function(index){$(this).addClass(window.rw_my_page_color);})















/*** RW AUTO CROPPER (WORKS WITH PROPERTIES) ***************************/

setTimeout(function(){
	$("#rw_prop_large_pic").each(function(e){
		var t=$(this).children("img");
		var n=t.height();
		var r=t.width();
		console.log(r);
		if(r>365){t.css({width:365+"px"});
			if(t.height()<365){t.css({width:"auto"});
				t.css({height:365+"px"})
			}
		}
		var i=t.height();
		var s=t.width();
		var o=-((i-365)/2);
		var u=-((s-365)/2);
		t.css({"margin-top":o+"px"});
		t.css({"margin-left":u+"px"});
		//$(".rw_loader").fadeOut()
		})
},1000);










/****** On focus reset the other zip code search ********/
$("#rw_prop_zip").focus(function(){$("#rw_prop_zip_keyword").val("");});

$("#rw_prop_zip_keyword").focus(function(){
	$("#rw_prop_zip").val("Choose One");
});















/**** OVERRIDE THE CSS MAIN STYLES FOR THE RELATIVE COLORS ********/



/****** FOR AREAS OF SERVICE - LENGTHEN THE SPACER *********/

var rw_aof_height_get = $('.rw_aof_parent').height() + 80;
$('.rw_aof_spacer').css({'height':rw_aof_height_get+'px'});

/***** FOR ALL HEADER LABELS TILTED ON THEIR SIDES - REMOVE ALL BUT THE FIRST *****/

$('.rw_box_prod_hold .label:gt(0)').html('&nbsp');
$('.rw_profile_hold .label:gt(0)').html('&nbsp');
$('.rw_aof_hold .label:gt(0)').html('&nbsp');
$('.rw_faq_hold .label:gt(0)').html('&nbsp');


/****** AREAS OF SERVICE AOF DYN POS OF CTA BUTT ******/

$('.rw_aof_txt_topDEACTIVATE').each(function(index){ 

	//get this position and height
	//13 is the additional ht for margins. outerHeight(true) doesnt work
	var rw_aof_butt_height = $(this).height() + 13; 
	var rw_aof_butt_width = $(this).width();
	var rw_aof_butt_selfw = $(this).children('a.rw_cta').width();
	var rw_aof_butt_selfh = $(this).children('a.rw_cta').height();
	
	var rw_aof_butt_finalpos_t = rw_aof_butt_height;
	var rw_aof_butt_finalpos_l = rw_aof_butt_width - rw_aof_butt_selfw;
	
	$(this).children('a.rw_cta').css({
			'top':rw_aof_butt_finalpos_t + 'px',
			'margin-left':rw_aof_butt_finalpos_l + 'px'
	});
	//console.log(rw_aof_butt_finalpos_l);
});//close each loop






/*************************
RW Tabbed Module 2
This is a fully functional dynamic tabbed module
This one takes into consideration its relationship from tab to revealer without just looking for ALL on the page
with this relativity, you can place multiple instances of this module on the same page
and they wont conflict
************************/

//init displays
	$(".rw_tab_reveal:first-child").css({"display":"block"});
	$(".rw_tab:first-child").addClass("rw_tab_active");
	$(".rw_tab:first-child").siblings(".rw_tab").addClass("rw_tab_default");
	
	$(".rw_tab").mouseenter(function(){
		if (!$(this).hasClass("rw_tab_active")) {
    			$(this).removeClass("rw_tab_default");
			$(this).addClass("rw_tab_hover");
			$(this).siblings().removeClass("rw_tab_hover");
		};//close if
		
		
	}); //close mousenter
	
	$(".rw_tab").mouseleave(function(){
		if (!$(this).hasClass("rw_tab_active")) {
			$(this).removeClass("rw_tab_hover");
			$(this).siblings().removeClass("rw_tab_hover");
			$(this).addClass("rw_tab_default");
		};//close if
		
	}); //close mouseleave
	
	$(".rw_tab").click(function(){
		//alert($(this).index());
		$(".rw_tab_reveal").css({"display":"none"});
		$(this).siblings().removeClass("rw_tab_active");
		$(this).siblings().addClass("rw_tab_default");
		$(this).removeClass("rw_tab_default");
		$(this).removeClass("rw_tab_hover");
		$(this).addClass("rw_tab_active");
		$(this).parent(".rw_tabs").next("div.rw_tab_reveals").children(".rw_tab_reveal:eq(" + $(this).index() + ")").fadeIn();
		
	});//close click


/*********************************
**** END RW TABBED MODULE v2 *****
*********************************/



/**** RW ROLLOVER CONTROL ******/
$('.rw_img_rollover').hover(function(){
	var src= $(this).attr("src");
	var src_part_one = src.substring(0, src.lastIndexOf("."));
	var src_part_two = src.substring(src.lastIndexOf("."));
	var new_src = src_part_one + "_rollover" + src_part_two;
	$(this).attr('src',new_src);
},function(){
	var src= $(this).attr("src");
	var src_parts = src.split("_rollover");
	var new_src = src_parts[0]+ src_parts[1];
	$(this).attr('src',new_src);
});









/********
START REVEAL OPEN THING
*******/



$(".rw_faq_q").click(function () {$(this).nextAll(".rw_faq_a").first().fadeToggle();});

$(".rw_template_revealer").click(function () {$(this).nextAll(".rw_template_revealed").first().fadeToggle();});
$(".rw_template_new_revealer").click(function () {$(this).nextAll(".rw_template_revealed").first().fadeToggle();});


//ckeditor template 
//$(".rw_revealer").click(function () {$(this).nextAll(".rw_revealed").first().fadeToggle();});

$("body").delegate( ".rw_revealer", "click", function() {$(this).nextAll(".rw_revealed").first().fadeToggle();});





/********
END REVEAL OPEN THING
*******/







/*****************************************************/
/******** RW ALTERNATING TABLE COLORS ****************/

/** This works in conjunction with the styles defined in the CSS file **/
/**  In order for the TR to accept the bg color, we must keep the bg color in the css commented out **/
/** This also works with a thead and tbody in place to retain the traversing **/

$('table.rw_table').each(function(){
		
		var rw_num_of_rows = $('tbody', this).children('tr').length;
		//alert(rw_num_of_rows);
		
		//the following condition ensures that a one row callout box doesn't get affected
		if(rw_num_of_rows>1){
				rw_loop = 0;
				$('tbody', this).children('tr').each(function(){
					
						if(rw_loop == 0){
							$(this).addClass("rw_table_alt_row_header_color_b");
							//$(this).css("background-color", "#bbbbff");
							
							rw_loop++;
						}else if(rw_loop%2){
							$(this).addClass("rw_table_alt_row_header_color_a"); 
							//$(this).css("background-color", "#ccc");
							rw_loop++;
						}else{
							
							//$(this).css("background-color", "#ccc");
							$(this).addClass("rw_table_alt_row_header_color_b"); 
							
							rw_loop++;
						}
						//alert(rw_num_of_rows);
					});
		};//close if condition
		
		
	});


/*****************************************************/
/*****************************************************/




/***** SET TABLE ALIGNS TO TOP ********/
$('td').attr('valign', 'top');







/*******************************************************************************/
/******** RW ALTERNATING TABLE COLORS VERSION THAT USES THE SUMMARY ATTRIBUTE ****************/

/** This works in conjunction with the styles defined in the CSS file **/
/**  In order for the TR to accept the bg color, we must keep the bg color in the css commented out **/
/** This also works with a thead and tbody in place to retain the traversing **/

$('table[summary="rw_table"]').each(function(){
		
		$(this).addClass('rw_table');
		
		//alert('rw test')
		
		var rw_num_of_rows = $('tbody', this).children('tr').length;
		//alert(rw_num_of_rows);
		
		//the following condition ensures that a one row callout box doesn't get affected
		if(rw_num_of_rows>1){
				rw_loop = 0;
				$('tbody', this).children('tr').each(function(){
					
						if(rw_loop == 0){
							$(this).addClass("rw_table_alt_row_header_color_b");
							//$(this).css("background-color", "#bbbbff");
							
							rw_loop++;
						}else if(rw_loop%2){
							$(this).addClass("rw_table_alt_row_header_color_a"); 
							//$(this).css("background-color", "#ccc");
							rw_loop++;
						}else{
							
							//$(this).css("background-color", "#ccc");
							$(this).addClass("rw_table_alt_row_header_color_b"); 
							
							rw_loop++;
						}
						//alert(rw_num_of_rows);
					});
		};//close if condition
		
		
	});


/*****************************************************/
/*****************************************************/




















/***************************** 
RW MATCH HEIGHTS OF DIVS  
******************************/


var rw_collect_hts = new Array();

//collect and push all heights of the divs with the rw_ht_match class

$('.rw_ht_match').each(function(index){
	//alert($(this).height());
	rw_collect_hts.push($(this).height());
	});

//Math.max will only apply to numbers in a comma delimited list. An array is of type array and will not work
//to get around that, use the following to APPLY the math.max function to an array type
var rw_highest_number = Math.max.apply(Math, rw_collect_hts); 


	
$('.rw_ht_match').css("min-height",rw_highest_number+'px');
	
	

/***************************** 
CLOSE RW MATCH HEIGHTS OF DIVS  
******************************/




/*********** HANDLING FOR SIDEBAR VS PAGE LENGTH **********************/

/*****
var rw_pg_length = $('#rw_sub_contents').height();
//alert(rw_pg_length);
if(rw_pg_length < 600){$('#rw_sub_contents').css({'min-height':900+'px'});
};//close if
****/






});//close window load



function cleanXML(xml_string){
	var clean_string = xml_string.replace(/\+/g, " ");
	clean_string = clean_string.replace(/%92/g,"'");
	clean_string = clean_string.replace(/%24/g,"&#36;");
	clean_string = clean_string.replace(/%27/g,"'");
	clean_string = clean_string.replace(/%26/g,"&amp;");
	clean_string = clean_string.replace(/%21/g,"!");
	clean_string = clean_string.replace(/%28/g,"(");
	clean_string = clean_string.replace(/%29/g,")");
	clean_string = clean_string.replace(/%2C/g,",");
	clean_string = clean_string.replace(/%3F/g,"?");
	clean_string = clean_string.replace(/%93/g,'"');
	clean_string = clean_string.replace(/%94/g,'"');
	clean_string = clean_string.replace(/%3A/g,':');
	clean_string = clean_string.replace(/%3B/g,';');
	clean_string = clean_string.replace(/%85/g,'...');

	return clean_string;
}
