$(function () {
	
	// IE6 Png Fixes
	$("#logo, .arrow, #enewsletter_signup .label, #scroll, .slide, #describes_you img").pngFix({blankgif:"images/blank.gif"}); 
	
	$("#main_navigation a").each(function (){
		var link = $(this);
		link.html(link.html().replace(/ /g, "&nbsp;"))
	});
	
	$("#main_navigation > li").hover(
		function () {
			$(this).addClass("hover");
			var ul = $(this).children("ul");
			if (ul.find("li").length > 0) {
				ul.show();
				ul.dropShadow({left:1, top:2});
			}
		}, 
		function () {
			$(this).removeClass("hover");
			var ul = $(this).children("ul");
			if (ul.find("li").length > 0) {
				ul.removeShadow();
				ul.hide();
			}
		}
	);
	
	var default_enewsletter_email_value = $("#enewsletter_email").val();
	$("#enewsletter_signup .label").click(function () {
		$("#enewsletter_email").focus();
	})
	
	$("#enewsletter_email").focus(function () {
		var field = $(this);
		if (field.val() == default_enewsletter_email_value) {
			field.addClass("focused");
			field.val("");
		}
	});
	$("#enewsletter_email").blur(function () {
		var field = $(this);
		if (field.val() == "") {
			field.removeClass("focused");
			field.val(default_enewsletter_email_value);
		}
	});
	
	$("#describes_you img").hover(
		function () {
			var img = $(this);
			img.attr("src", img.attr("src").replace(/\.([^\.])/, "RO.$1"));
		}, 
		function () {
			var img = $(this);
			img.attr("src", img.attr("src").replace("RO.", "."));
		}
	)
	
		$("#describes_you span").hover(
		function () {
			this.style.filter = this.style.filter.replace(".png", "RO.png");
		}, 
		function () {
			this.style.filter = this.style.filter.replace("RO.", ".");
		}
	)
	
	$("#promo_slides").kovlerPromo();
		

		
	$("#video_list").kovlerVideoList();

});


$(window).load(function() {
	$("#verbiage img").not(".arrow").each(style_verbiage_images);
});

var style_verbiage_images = function (){
	if ($("body").hasClass("subpage_aligned_images")) {
		$(this).each(style_verbiage_images_aligned)
	} else {
		$(this).each(style_verbiage_images_right_aligned)
	}
}

var style_verbiage_images_aligned = function() {
	var img = $(this);

	var current_image = img;
	var max_height = parseInt(img.height());
	while ((next_image = current_image.next("img")).length == 1) {
		current_image = next_image;
		if (parseInt(current_image.height()) > max_height) {
			max_height = parseInt(current_image.height());
		}
	}
	if (img == current_image) {
		img.addClass("last")
	}
	
	var current_image = img;
	while ((prev_image = current_image.prev("img")).length == 1) {
	current_image = prev_image;
	if (parseInt(current_image.height()) > max_height) {
		max_height = parseInt(current_image.height());
	}
	}
	if (img == current_image) {
		img.addClass("first")
	}
	
	var height_difference = max_height - parseInt(img.height())
	var new_padding = parseInt(img.css("padding-bottom")) + height_difference
	
	img.css("padding-bottom", new_padding+"px")	
}

var style_verbiage_images_right_aligned = function() {
	var img = $(this);

	img.wrap("<span class='image'></span>");

	var span = img.parent();
	span.width(img.outerWidth());

	var container = span.parent();	
	if ((container.contents().eq(0).get(0) != span.get(0) || container.offset().top != span.offset().top) && span.prev().is("span.image") == false && span.prev().is("sub") == false && span.prev().is("br") == false) span.addClass("paragraph");

	var next = span.next()
	if (next.is("sub")) {
		next.insertAfter(img);
	}
}

var verbiage_updated_callback = function(verbiage) {
	verbiage.find("img").each(style_verbiage_images);
};

var wymeditor_config = {
	containersItems: [
    {'name': 'P', 'title': 'Paragraph', 'css': 'wym_containers_p'},
    {'name': 'H1', 'title': 'Heading_1', 'css': 'wym_containers_h1'},
    {'name': 'H2', 'title': 'Heading_2', 'css': 'wym_containers_h2'},
    {'name': 'H3', 'title': 'Heading_3', 'css': 'wym_containers_h3'},
    {'name': 'H4', 'title': 'Heading_4', 'css': 'wym_containers_h4'},
    {'name': 'H5', 'title': 'Heading_5', 'css': 'wym_containers_h5'}
  ]
};

