function avoidLastChildIE(parent){
	if($.browser.msie) $(parent).children(':last-child').addClass('last');
}
function runPopup(elem, divId, holderW, top){
	var _holder = jQuery('<div id="' + divId + '"></div>');
	$('.close').live('click', function(){
		_holder.fadeOut('slow').empty();
		jQuery.unblockUI();
	});
	$(elem).click(function(){
			$('body').append(_holder);
			if(_holder.html() == ''){
				var url = $(this).attr('href');
				jQuery.blockUI({
					message:_holder,
					css: {
						top: top,
						left: ($(window).width() - holderW) /2 + 'px',
						width: holderW + 'px',
						cursor: 'default',
						textAlign: 'left'
					}
				});
				_holder.append('<span class="close">X</span>');
				jQuery.get(url,{},
					function(response){
						_holder.append(response).fadeIn('slow');
						$('.btn_close').click(
							function(){
								_holder.fadeOut('slow').empty();
								$.unblockUI();
							}
						);
						$('.btn_submit').click(
							function(){
								_holder.fadeOut('slow').empty();
								$.unblockUI();
							}
						);
					}
				);
			}
			else{
				_holder.fadeIn('slow');
				jQuery.blockUI({
					message:_holder,
					css: {
						top: top,
						left: ($(window).width() - holderW) /2 + 'px',
						width: holderW + 'px',
						cursor: 'default',
						textAlign: 'left'
					}
				});
			}
			$('.blockOverlay').attr('title','').click(
				function(){
					_holder.fadeOut('slow').empty();
					jQuery.unblockUI();
				}
			);
			return false;
		}
	);
}
function replyReplace(){
	$('.comment-reply-link').addClass('button').wrapInner('<span />');
}
function replaceButton(elem, _class){
	var _el = $(elem);
	_el.data('val', _el.val());
	$(elem).replaceWith('<button type="submit" class="'+_class+'"><span>' + _el.data('val') + '</span></button>');	
}
$(document).ready(function(){
	avoidLastChildIE('.top_nav table tr');
	runPopup('.video_block .video_holder a', 'videoPopup', '480', '25%');
	replyReplace();
	replaceButton('.form-submit input[type="submit"]', 'button');
	replaceButton('#searchsubmit', 'button');
});
