$(document).ready(function() {

	$('#search input.text').blur(function() {
		if(this.value=='') {this.value=this.defaultValue; this.className='text';}
	});
	$('#search input.text').focus(function() {
		if(this.value==this.defaultValue) {this.value=''; this.className='active-text';}
	});
	
	$('#search input[type*=image]').hover(function(){
	 $(this).attr('src','i/search-act.gif');
	},function(){
	 $(this).attr('src','i/search.gif');
	});
	
	$('#comments .header div').click(function(){
		if ($('.comment-pull').is(':animated')) {return false} else {
			if ($(this).hasClass('active')) {
				$('.comment-pull').show();
				$('#comments .header div a:first-child').html('');
				$(this).removeClass('active');
				return false
			} else {
				$('.comment-pull').hide();
				$('#comments .header div a:first-child').html('');
				$(this).addClass('active');
				return false
			}
		}
	});
	
	
	
	
	vallidatecomments = function() {
		msg = $('.shown .comment-field textarea').val();
		capture = $('.shown .comment-input input').val();
		if (capture) {
			if ((msg.length > 0) && (capture.length > 0)) {
				$('.shown .comment-send input').removeAttr('disabled','disabled');
				$('.shown .comment-send input').removeClass('disabled');
			}else{
				$('.shown .comment-send input').attr('disabled','disabled');
				$('.shown .comment-send input').addClass('disabled');
			}
		} else {
			if ((msg.length > 0)) {
				$('.shown .comment-send input').removeAttr('disabled','disabled');
				$('.shown .comment-send input').removeClass('disabled');
			}else{
				$('.shown .comment-send input').attr('disabled','disabled');
				$('.shown .comment-send input').addClass('disabled');
			}
			
		}
	}
	
	$('#send-comment-link').click(function(){
		$('.comment-form').hide().removeClass('shown');
		if ($(this).hasClass('active')) {	
			$(this).removeClass('active');			
		}else{
			$('#comments .header div').removeClass('active');
			$('.comment-pull').show();
			$('.comment-answer a').removeClass('active');					
			$(this).addClass('active');	
			$('#respond').show().addClass('shown');
			$('.comment-field textarea').focus();
			vallidatecomments();
			$('.comment-field textarea, .comment-input input').keydown(function(){vallidatecomments();}).blur(function(){vallidatecomments();}).focus(function(){vallidatecomments();});
		}
		return false
	});
	
	
	$('.comment-answer a').click(function(){
		$('.comment-form').hide().removeClass('shown');
		$('#send-comment-link').removeClass('active');	
		if ($(this).hasClass('active')) {	
			$(this).parent().next('.comment-form').hide();
			$(this).removeClass('active');			
		}else{
			$('.comment-answer a').removeClass('active');					
			$(this).addClass('active');	
			$(this).parent().next('.comment-form').show();
			$(this).parent().next('.comment-form').addClass('shown');
			$('.comment-field textarea').focus();
			vallidatecomments();
			$('.comment-field textarea, .comment-input input').keydown(function(){vallidatecomments();}).blur(function(){vallidatecomments();}).focus(function(){vallidatecomments();});
		}
		return false
	});
	
	$('.comment-icons .negative').click(function(){
		currentnum = $(this).parent().parent().children().children().children('span').html() - 0
		if ($(this).hasClass('current')) {} else {
		newnum = currentnum - 1;
		if (newnum>0) {$(this).parent().parent().children().children().children('b').html('+');} else {$(this).parent().parent().children().children().children('b').html('');}
		$(this).parent().parent().children().children().children('span').html(newnum+"");
		}
		
		if ($(this).next().hasClass('current')) {
			$(this).next().removeClass('current');
			$(this).next().children('img').attr('src','i/ico-good.gif');		
			} else {
			$(this).addClass('current');
			$('img',this).attr('src','i/ico-bad-inactive.gif');
		}
		return false
	});
	
	$('.comment-icons .positive').click(function(){
		currentnum = $(this).parent().parent().children().children().children('span').html() - 0
		if ($(this).hasClass('current')) {} else {
		newnum = currentnum + 1;
		if (newnum>0) {$(this).parent().parent().children().children().children('b').html('+')}else{$(this).parent().parent().children().children().children('b').html('')}
		$(this).parent().parent().children().children().children('span').html(newnum+"");
		
		}
		if ($(this).prev().hasClass('current')) {
			$(this).prev().removeClass('current');
			$(this).prev().children('img').attr('src','i/ico-bad.gif');				
			} else {
			$(this).addClass('current');
			$('img',this).attr('src','i/ico-good-inactive.gif');
		}
		return false
	});
	
	
	//$('.login a').click(function(){
	//	$('#enter-here').animate({top:'10px'},300).animate({top:'0px'},100).animate({top:'6px'},100);
	//	$('#overlay').css('height',$('body').height()).show();
	//	$('#enter-login').focus();
	//	return false							
	//});
	
	
	$('#enter-here .close').click(function(){
		$('#enter-here').animate({top:'-300px'},300);
		$('#overlay').hide();
		return false							
	});
	$('#wrapper').prepend('<div id="preloader"><img src="i/search-act.gif" alt=""/></div>');
	
	vallidateenter = function() {
		login = $('#enter-login').val();
		password = $('#enter-password').val();
		if ((login.length > 0) && (password.length > 0)) {
			$('#enter-submit').removeAttr('disabled','disabled');
			$('#enter-submit').removeClass('disabled');
		}else{
			$('#enter-submit').attr('disabled','disabled');
			$('#enter-submit').addClass('disabled');
		}
	}
	//$('#enter-login, #enter-password').keydown(function(){vallidateenter();}).blur(function(){vallidateenter();}).focus(function(){vallidateenter();});
	
	$('.inblog input').each(function(){
        var clip = new ZeroClipboard.Client();   
        var insertflash = $(this);
        clip.glue(insertflash[0]);
        var txt = $.trim($("#clipme").text());
        

        clip.setText(txt);
        clip.addEventListener( 'mouseDown', function(client) {
			document.getElementById('clipme').select();
			document.getElementById('clipme').focus();
							      
	});
	
	$('#enter-submit2').click(function(){
		document.getElementById('clipme').focus();
		document.getElementById('clipme').select();
		var BodyRange = document.body.createTextRange(); 
		BodyRange.moveToElementText(document.getElementById('clipme')); 
		BodyRange.execCommand('Copy');  
	});	        
	});
	
	
	$('#enter-submit2').hover(function(){
		$(this).addClass('hovered');
	},function(){
		$(this).removeClass('hovered');		
	});
	
		if($.browser.mozilla){
		$('.startpage').append('<div class="ff"><div class="drop"><a href="/" onclick="return false;"><img src="/wp-content/themes/news/i/ff.gif" alt="" /></a><span>Перетащи меня</span></div><p>Перетащите и отпустите «Треугольник» на иконку «Дом» в панели инструментов браузера, затем нажмите «Да» во всплывающем окне.<span><img src="/wp-content/themes/news/i/ff.jpg" alt="" /></span></p></div>')
		$('.startpage').children('a').click(function(){
			if ($(this).hasClass('active')){
				$(this).removeClass('active');
				$('.ff').hide();
			} else {
				$(this).addClass('active');	
				$('.ff').show();
			}
			return false
		});
	}
	

}); 

function openNewWindowFeedback (url, width, heigth, scrollbars) {
	var leftPosition = screen ? (screen.width - width) / 2 : width;
	var topPosition = screen ? (screen.height - heigth) / 2 : heigth;
	window.open(url ? url.toString() : "","NewWin", "width=" + width.toString() + ",height=" + heigth.toString() + ",resizable=yes,scrollbars=" + scrollbars + ",status=no,menubar=no,location=no,toolbar=no,left=" + leftPosition.toString() + ",top=" + topPosition.toString());
}


