
var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};


$(document).ready(
	function() {
		ie_hover();
		form_vals();
		form_defaults();
		if(jQuery.browser.msie && jQuery.browser.version < 7) {
			$('#sidebar div.sidebar_block').each(
				function() {
					$(this).append(
						$(jQuery('<img />'))
							.attr({
								src: '/images/clear.gif',
								width: $(this).width(),
								height: 10
							})
							.css({
								filter: $(this).css('filter')
							})
					)
					$(this).css({
						background: 'none',
						filter: ''
					})
				}
			)
		}
	}
)

$(window).load(
	function() {
		equal_columns()
		png_fix()
	}
)

function equal_columns() {
	if($('#main').outerHeight() != $('#sidebar').outerHeight()) {
		tallest = ($('#main').outerHeight() > $('#sidebar').outerHeight() ? $('#main').outerHeight() : $('#sidebar').outerHeight())
		$('#main').height(
			tallest - ($('#main').outerHeight() - $('#main').height())
		)
		$('#sidebar').height(
			tallest - ($('#sidebar').outerHeight() - $('#sidebar').height())
		)
	}
}

function ie_hover() {
	if(!jQuery.browser.msie || (jQuery.browser.msie && jQuery.browser.version >= 7)) {
		return
	}
	var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):hover/i;
	var currentSheet = null;

	parseStylesheets();	

	function parseStylesheets() {
		var sheets = window.document.styleSheets;
		for(var i = 0; i < sheets.length; i++) {
			parseStylesheet(sheets[i])
		}
	}

	function parseStylesheet(sheet) {
		if(sheet.imports) {
			try{
				var imports = sheet.imports;
				for(var i=0; i < imports.length; i++) {
					parseStylesheet(imports[i])
				}
			} catch(securityException) {
			}
		}
		try{
			var rules = sheet.rules;
			currentSheet = sheet;
			for(var x = 0; x <= rules.length; x++) {
				parseCSSRules(rules[x])
			}
		} catch(securityException) {
		}
	}
	
	function parseCSSRules(rule) {
		var select = rule.selectorText;
		var styles = rule.style.cssText;
		if(!csshoverReg.test(select) || !styles) {
			return;
		}

//		$('#debug').append($(jQuery('<p />')).html(select + ' { ' + styles + ' }'))

		var elem = select.replace(/:hover/,'');

		currentSheet.addRule(select.replace(/:hover/,'.psuedohover'), styles)

		$(elem).each(
			function() {
				$(this).hover(
					function() {
						$(this).addClass('psuedohover')
					},
					function() {
						$(this).removeClass('psuedohover')
					}
				)
			}
		)
	}
}

function form_vals() {
	$('input[type=text], textarea').each(
		function() {
			if($(this).val() == '' && $(this).prev('label').size()) {
				$(this).val($(this).prev('label').text())
			}
		}
	)
}

function form_defaults() {
	$('input[type=text], textarea').each(
		function() {
			var text = $(this).val()
			$(this).focus(
				function() {
					if($(this).val() == text) {
						$(this).val('')
					}
				}
			)
			$(this).blur(
				function() {
					if($(this).val() == '') {
						$(this).val(text)
					}
				}
			)
		}
	)
}

function png_fix() {
	if(jQuery.browser.msie && jQuery.browser.version < 7) {
		$('img[src$=png]').each(
			function() {
				var img = $(this).attr('src')
				$(this)
					.css({
						width: $(this).width(),
						height: $(this).height(),
						filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "', sizingMethod='scale');"
					})
					.attr({
						src: '/images/clear.gif'
					})
				if($(this).parent('a').length > 0) {
					$(this).parent('a').css({
						cursor: 'pointer'
					})
				}
			}
		)
	} else {
		return;
	}
}
