function normalBreak(str){
	str = new String(str);//cast for ie
	
	return(str.replace(/<br(\/)?>/gi, "<br />"));
}


function headerReplace(obj,header){
	htext = $(obj).html();
	htext = normalBreak(htext);
	$(obj).text('');
	parts = htext.split('<br />');
	img = "";
	for(i=0;i<parts.length;i++){
		img+='<img src="/'+header+'/?text='+parts[i]+'" />';
	}
	$(obj).html(img);
}



//alert(normalBreak("Text<br>Not<BR>Another<br/>This<br />"));




$(document).ready(function() {
	// Preload all rollovers
	$("#post a img:not(:first)").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.png$/ig,"_on.png");
		$("<img>").attr("src", rollON);
	});
	// Navigation rollovers
	$("#post a:has(img):not(:first)").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_on.png/);
		// don't do the rollover if state is already ON
		if (!matches) {
		imgsrcON = imgsrc.replace(/.png$/ig,"_on.png"); // strip off extension
		$(this).children("img").attr("src", imgsrcON);
		}

	});
	$("#post a:has(img):not(:first)").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
	// Preload all rollovers
	// $("#page_navigation a img").each(function() {
	// 	// Set the original src
	// 	rollsrc = $(this).attr("src");
	// 	rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
	// 	$("<img>").attr("src", rollON);
	// });
	// // Navigation rollovers
	// $("#page_navigation a:has(img)").mouseover(function(){
	// 	imgsrc = $(this).children("img").attr("src");
	// 	matches = imgsrc.match(/_on.gif/);
	// 	// don't do the rollover if state is already ON
	// 	if (!matches) {
	// 	imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
	// 	$(this).children("img").attr("src", imgsrcON);
	// 	}
	// 
	// });
	// $("#page_navigation a:has(img)").mouseout(function(){
	// 	$(this).children("img").attr("src", imgsrc);
	// });
	// $("h2").each(function(){
	// 	headerReplace(this,'header');
	// });
	// $("h3,h4,a.header_link").each(function(){
	// 	headerReplace(this,'header2');
	// });
	// $("th").each(function(){
	// 	headerReplace(this,'table_header');
	// });
	$("#page_navigation a img, #whiteness h1 img").each(function() {
		if (navigator.userAgent.indexOf("MSIE 6")!=-1){
			$(this).attr("src", $(this).attr("src").replace(/\?text\=/, "?format=gif&text="));
		}
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/header/ig,"header_on");
		$("<img>").attr("src", rollON);
	});
	$("#page_navigation a:not(.sub_on)").mouseover(function(){
		$(this).children("img").each(function(){
			imgsrc=	$(this).attr("src");
			matches = imgsrc.match(/gifheader_on/ig);
			// don't do the rollover if state is already ON
			if (!matches) {
				imgsrcON = imgsrc.replace(/header/ig,"header_on"); // strip off extension
				$(this).attr("src", imgsrcON);
			}
		});
	})
	$("#page_navigation a:not(.sub_on)").mouseout(function(){
		$(this).children("img").each(function(){
			$(this).attr("src", imgsrc);
		});
	});

});

function popup(slug){
	window.open('/popup/'+slug,"pop", 'width=595,height=612,scrollbars=1');
	return false;
}
