jQuery(document).ready(function($){
	
	$("#wzrd-btn").click( function() {
		self.location = '/index?showhint';
	});
	
	$(".post").mouseup( function (e) {
		var qText = '';
		if (window.getSelection) {
			qText = window.getSelection();
		}
		else if (document.selection) {
			qText = document.selection.createRange().text;
		}
		if(qText != '') {
			$("#pasteQuotedTextMsg .popupInner").html('<input type="button" class="input_submit" onclick="frq_quote(\'' + $(this).attr('authorname') + '\',\'' + $(this).attr('postid') + '\'); window.scrollTo(0, jQuery(\'#editor_fast-reply\').offset().top); jQuery(\'#pasteQuotedTextMsg\').fadeOut(\'fast\');" value="Цитировать" /> <input type="button" class="input_submit alt" onclick="jQuery(\'#pasteQuotedTextMsg\').fadeOut(\'fast\');" value="X" />');
			$("#pasteQuotedTextMsg").css({'left': (e.pageX - 120) + 'px', top: (e.pageY - 70) + 'px'});
			$("#pasteQuotedTextMsg").fadeIn('fast');
		}
		return false;
	});
	
	
	$(".bbc_img").each(
		function (i) {
			$(this).css('max-width', '600px');
			if( !$(this).parent().is('a') )
				$(this).wrap("<a href='" + $(this).attr("src") + "' class='LBimg'></a>");
		}		
	);
	
	$(".personal_info .photo").each(
		function (i) {
			$(this).css('max-width', '200px');
			$(this).wrap("<a href='" + $(this).attr("src") + "' class='LBimg'></a>");
		}		
	);
	
	$(".LBimg").fancybox({
		autoScale: true, 
		overlayShow: true,
		overlayOpacity: 0.5,
		overlayColor: '#000'
	});
	
	/*$(".LBimg").lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: '/public/js/3rd_party/lightbox/loading.gif',
		imageBtnClose: '/public/js/3rd_party/lightbox/close.gif',
		imageBtnPrev: '/public/js/3rd_party/lightbox/prev.gif',
		imageBtnNext: '/public/js/3rd_party/lightbox/next.gif',
		imageBlank: '/public/js/3rd_party/lightbox/blank.gif',
		containerResizeSpeed: 350,
		txtImage: 'Картинка',
		txtOf: 'из поста'
	});*/
	
	
	
	$(".sp-header").click(function(){
		$(this).next(".sp-body").slideToggle(500)
		$(this).toggleClass("sp-header-active"); return false;
	});
							
	$("#show_login").click(function(){
		$("#ipbwrapper").fadeOut();
		$("#quick_login").fadeIn(0);
		return false;
	});
	
	$("#close_login").click(function(){
		$("#ipbwrapper").fadeIn();
		$("#quick_login").fadeOut();
		return false;
	});
	
	$(".forum_name").hover(function() {
			$(this).next(".forum_desc_pos").stop()
			.animate({left: "0", opacity:1}, "fast")
			.css("display","block")
		
		}, function() {
			$(this).next(".forum_desc_pos").stop()
			.animate({left: "10", opacity: 0}, "fast", function(){
			$(this).hide();
		})
	});
	
	
	$(".rounded-avatar2 img").load(function() {
		$(this).wrap(function(){
		  return '<span class="rounded-img" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
		});
		$(this).css("opacity","0");
	  });
	
	$(".rounded-avatar img").each(function() {
		$(this).wrap(function(){
		  return '<span class="rounded-img" style="background:url(' + $(this).attr('src') + ') no-repeat center center;" />';
		});
		$(this).css("opacity","0");
	  });
	
	$("input[placeholder]").each(function(){
	
	var inputtext = $(this).attr("placeholder");
	$(this).attr('value', inputtext);
	$(this).addClass('inactive_input');
	
	var clearMePrevious = '';
	
	$(this).focus(function(){
	
	if($(this).val()==$(this).attr('placeholder'))
	{
	clearMePrevious = $(this).val();
	$(this).val('').removeClass('inactive_input');
	}
	
	});
	
	$(this).blur(function(){
	if($(this).val()=='')
	{
	$(this).val(clearMePrevious).addClass('inactive_input');
	}
	});
	
	
	});
	
	
	$("#postingform .input_rte").focus(function(){
	
	var topicDescInput = $("#topic_desc").val();
	var topicDescPlace = $("#topic_desc").attr('placeholder');
	
	if(topicDescInput == topicDescPlace){
	$("#topic_desc").val('');
	}
	
	});

});

function switch_sidebar()
{
	if( jQuery(".side_column").width() != 38 ) {
		toggle_sidebar(1);
	} else {
		toggle_sidebar(0);
	}
}

function toggle_sidebar(state)
{
	if( state == 1 )
	{
		jQuery(".side_column").css({'width': '38px'});
		jQuery(".side_column_top").css({'background-position': '-170px 0px'});
		jQuery(".side_column_bg").css({'background-position': '-170px 0px'});
		jQuery("#toggle-sidebar-btn").html("&rarr;");
		jQuery.cookie('minimizeSidebar', 1, { expires: 365, path: '/' });
	} else {
		jQuery(".side_column").css({'width': '210px'});
		jQuery(".side_column_top").css({'background-position': '0px 0px'});
		jQuery(".side_column_bg").css({'background-position': '0px 0px'});
		jQuery("#toggle-sidebar-btn").html("&larr; спрятать меню");
		jQuery.cookie('minimizeSidebar', 0, { expires: 365, path: '/' });
	}
}
 
/*function switch_performance()
{
	if( jQuery("#body-bg-img").css('position') == 'fixed' ) {
		if( confirm("Если сайт немного подтормаживает, можно отключить некоторые графические эффекты. Попробуем?") )
		{
			toggle_performance(1);
		}
	} else {
		if( confirm("Для отключения режима высокой производительности необходимо обновить страницу, соотв. все несохранённые данные в текстовых полях будут потеряны. Продолжить?" ) )
		{
			toggle_performance(0);
		}
	}
}

function toggle_performance(state)
{
	if( state == 1 )
	{
		jQuery("*").css('box-shadow', 'none');
		jQuery("*").css('-webkit-box-shadow', 'none');
		jQuery("*").css('-moz-box-shadow', 'none');
		jQuery("#body-bg-img").css('position', 'absolute');
		jQuery("#toggle-performance-btn").attr('src', '/public/style_images/gravity-green/speed_off.png');
		jQuery.cookie('boostPerformance', 1, { expires: 365, path: '/' });
	} else {
		jQuery.cookie('boostPerformance', 0, { expires: 365, path: '/' });
		window.location = window.location;
	}
}*/
