/* Community Global.js */
// this global.js removes focus from search field

// remove IE6 image flickering
try {document.execCommand('BackgroundImageCache', false, true);}
catch(e) {}


$(document).ready(function(){
	//text resizer
	$("#txtResizer span").eq(0).css("color", "#666");
	$("#txtResizer span").bind("click", function(){
		var newSize = $(this).prevAll("span").length;
		$("#txtResizer span").css("color", "#036").eq(newSize).css("color", "#666");
		$("#txtResizeArea").css("font-size", (newSize*0.2+1)+"em");
	});
	
	//initialize popup links
	$("a.popup").addClass("pop").attr("title", "[Opens in new window]").bind("click", function(){
		var popup = window.open($(this).attr("href"), "_blank", "height=500,width=600,scrollbars=yes");
		popup.focus();
		return false;
	});
	$("a.popup2").attr("title", "[Opens in new window]").bind("click", function(){
		var popup = window.open($(this).attr("href"), "_blank", "height=500,width=600,scrollbars=yes");
		popup.focus();
		return false;
	});
	
	//don't submit search form with blank query
	$("#sitesearch").submit(function(){
		return ($.trim($(this).find("#searchbox").val()) != "");
	});

	//prints the pages url on screen used on print pages
	$("#linkLocation").html(location.href);
	
	//convert add-this link lists to form
	if ($(".getRSS .getRSSList a").length > 0) {
		var str = "";
		$(".getRSS .getRSSList a").each(function() {
			str += "<option value='" + $(this).attr("href") + "'>" + $(this).text() + "</option>";
		});
		$(".getRSS .getRSSList").after("<form target='_top' action='#' method='post'><table cellspacing='10' summary=''><tr><td><label for='reader'>Add Sunset to:</label></td><td><select name='reader' id='reader'>" + str + "</select></td><td><input type='image' src='http://img4.sunset.com/static/i/btn_add.gif' alt='Add' /></td></tr></table></form>");
		$(".getRSS form").bind("submit", function(){
			$(this).attr("action", $(this).find("option:selected").val());
		});
		$(".getRSS .getRSSList").remove();
	}
	if ($(".addTo .getRSSList a").length > 0) {
		var str = "";
		$(".addTo .getRSSList a").each(function() {
			str += "<option value='" + $(this).attr("href") + "'>" + $(this).text() + "</option>";
		});
		$(".addTo .getRSSList").after("<form target='_top' action='#' method='post'><table cellspacing='4' summary=''><tr><td><label for='reader'>Add Sunset to:</label></td><td><select name='reader' id='reader'>" + str + "</select></td><td><input type='image' src='http://img4.sunset.com/static/i/btn_add.gif' alt='Add' /></td></tr></table></form>");
		$(".addTo form").bind("submit", function(){
			$(this).attr("action", $(this).find("option:selected").val());
		});
		$(".addTo .getRSSList").remove();
	}
});

