 w = screen.width * .9;
 h = screen.height * .7;
 x = (screen.width - w) * 0.8;
 y = (screen.height - h) * .1;

var winProps = "toolbar=yes,location=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,componentbar=no,navigationbar=no";
var args = "width=" + w + ",height=" + h
      + "," + winProps
      + ",screenx=" + x + ",screeny=" + y
      + ",left=" + x + ",top=" + y;

function popwin(url)
{
	winhandle=window.open(url,'',args);
	winhandle.focus();
	return true
}

$(document).ready(function(){

	$.fn.appendVal = function(txt) {
		return this.each(function(){
			this.value += txt;
		});
	};
	
	$('div.comment_div b span').click(function (){
		$(this).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		var new_text = "\r\n" + "> " + $(this).html() + ' (' + $('#' + this.id + '_data').html() + ')' + "\r\n";
		$('#comment_text').appendVal(new_text);
		$('#comment_text').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		destination1 = $(this).offset().top;
		destination = $('#comment_text').offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $('#comment_text').offset().top}, 1300 ).animate({ scrollTop: $(this).offset().top-300}, 1300 );
		$(this).parent().parent().parent().addClass("active_comment_div");
	});

	$('img#secure').click(function(){
		$(this).attr('src', '/turing.php?temp='+Math.round((Math.random()* 1000000)));
		$('#comment_turing').val('');
	});

	$('#comment_text').change(function()  {
		$('img#secure').attr('src', '/turing.php?temp='+Math.round((Math.random()* 1000000)));
		$('#comment_turing').val('');
	});


	if ($("a[rel=photo_album]").length > 0)
		$("a[rel=photo_album]").colorbox({photo:true});

	//{photo:true, slideshow:true}


	$('#arhive_form').submit(function(){
		var module = $('#arhive_form input[name="module"]').val();
		var category = $('#arhive_form input[name="category"]').val();
		var month = $('#arhive_form select[name="Date_Month"]').val();
		var year = $('#arhive_form select[name="Date_Year"]').val();
		var url = '/'+module+'/';
		if (category !== '') url += category+'/';
		window.location.href = url+year+'/'+month+'/1/';
	});
});


function comment_validator ()
{
	if ($('#comment_name').val().length > 0 && $('#comment_text').val().length > 0 && $('#comment_turing').val().length == 4){
		return true;
	} else {
		$('#comment_name').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		$('#comment_text').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		$('#comment_turing').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		return false;
	}
}

