$(document).ready(function() {  
	var subheader_width = $("#rw_layer_sub_pic_text").innerWidth();
	$("#headline-above-text").innerWidth(subheader_width);



/********* Resize Interior Height based on Sidebar Height ******/
	var sidebar_height = $("#rw_sub_sidebar").height();
	sidebar_height = sidebar_height +100;
	var interior_height = $(".rw_sub_internal").height();
	var new_interior_height = sidebar_height+50;
	
	if(sidebar_height > interior_height){$(".rw_sub_internal").css("height",new_interior_height+"px");}
	
/**********
Close Resize Interior Height based on Sidebar Height
***********/




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



/****** Search Script *****/
$(".header_search").click(function(){
	var search_href = $(this).attr("href");
	var keyword = $(this).parent().siblings(".keywords").val();
	if(keyword){
		search_href += "?rw_keyword_passed="+keyword;
	}else{
		return false;
	}
	$(this).attr("href",search_href);
});
/**************************/










/********
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
*******/





/***** 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);});




/********* Read More or Less ***********/
$(".ab_read_more").each(function(){
	var divHTML = $(this).parent().html();
	var htmlArray = divHTML.split('<a class="ab_read_more" href="#">Read More</a>');
	// console.log(htmlArray);

	newHTML = htmlArray[0] + "<span class='callout_reveal_more'>"+htmlArray[1]+"</span><br /><br /><div class='callout_reveal_click'>Read More</div>";
	$(this).parent().html(newHTML);
});

setTimeout(function(){
	$(".callout_reveal_click").click(function(){
		var hidden = $(this).siblings('.callout_reveal_more').css("display");
		var clickedTag = $(this);
		console.log(hidden);
		if(hidden == "none"){
			$(this).siblings('.callout_reveal_more').fadeIn( "slow", function() {
				clickedTag.text("Read Less");
			});
			// $(this).text("Read Less");
		}else{
			$(this).siblings('.callout_reveal_more').fadeOut( "slow" , function() {
				clickedTag.text("Read More");
			});
			//$(this).text("Read More");
		}
		// $(this).siblings('.callout_reveal_more').toggle();
	});

},500);









/**** RW ROLLOVER CONTROL ******/
$('.rw_img_rollover, .rw_img_rollover_png').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);
});



















/*** 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");
});




/******* Amenities Revealers **********/
$(".amenities_revealers").click(function(){$(this).next(".ab_amenities_revealed").toggle();});


setTimeout(function(){
	$(".ab_amenities_revealed").css("left","0px");
	$(".ab_amenities_revealed").css('position','relative');
	$(".ab_amenities_revealed").hide();
},1500);

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



});//close doc ready








