$(function() {
	// preload
    var style_path = "http://www.ufolog.lt/forum/styles/ufologlt";
	(new Image()).src = style_path + "/theme/images/notice.png";
	(new Image()).src = style_path + "/theme/images/quicksearchbg.png";
	(new Image()).src = style_path + "/theme/images/quicksearchbg.png";
	
	//
	// Shadowbox
	//
	$(".attachcontent a").attr('rel', function() {
		if($(this).parents('.postrow').length) {
			group = "" + $(this).parents('.postrow').attr('class').match(/[0-9]+/);
			return "shadowbox[" + group + "];player=img";
		}
	});
	
	if($('a[name=quicklogin]').attr('rel') != 'logout') {
		$('a[name=quicklogin]').attr({
			href: '#quicklogin',			
			rel: 'shadowbox;width=300;height=150;player=inline'
		});
	}
	
	if($('.disclaimer_link a').length == 1) {
		$('.disclaimer_link a').attr({
			href: '#disclaimer',			
			rel: 'shadowbox;width=500;height=90;player=inline'
		});
	}
	
	$('#donate a').attr({
		href: '#donation_box',			
		rel: 'shadowbox;width=500;height=360;player=inline'
	});
	
	Shadowbox.init({enableKeys: false});
	
	$('#donate div').css('width', $('#donate a').html());
	
	
	$(".postrow").hover(
		function () {
			$(this).find(".posttop").css({
				"opacity" : "1.0",
				"filter" : "alpha(opacity=100)"
			});
			$(this).find(".posttools a").css("visibility", "visible");
		},
		function () {
			$(this).find(".posttop").css({
				"opacity": "0.2",
				"filter": "alpha(opacity=20)"
			});
			$(this).find(".posttools a").css("visibility", "hidden");
		}
		
	);
	
	$("#topictools li img").hover(
	function(){
		var iconName = $(this).attr("src");
		var origen = iconName.split(".")[0];
		//$(this).attr({src: "" + origen + "o.gif"});

		$(this).parent().parent().animate({ width: "140px" }, {queue:false, duration:"normal"} );
		$(this).parent().parent().find("span").animate({opacity: "show"}, "fast");
		},
		function(){
		var iconName = $(this).attr("src");
		var origen = iconName.split("o.")[0];
		//$(this).attr({src: "" + origen + ".gif"});

		$(this).parent().parent().animate({ width: "30px" }, {queue:false, duration:"normal"} );
		$(this).parent().parent().find("span").animate({opacity: "hide"}, "fast");
	});
	
	//
	// quick search box
	//
	var searchTimer;
	var isFocused = false;
	$("#searchlink").hover(showSearchbox, 
	function(){
		clearTimeout(searchTimer);
		hideSearchbox();
	});
	
	$("#quicksearchbox").hover(
	function(){
		clearTimeout(searchTimer);
	}, hideSearchbox);
	
	function showSearchbox(){
		clearTimeout(searchTimer);
		searchTimer = setTimeout('$("#quicksearchbox").show()', 250);
	}
	
	function hideSearchbox(){
		if(isFocused == false){
			clearTimeout(searchTimer);
			searchTimer = setTimeout('$("#quicksearchbox").hide()', 800);
		}
	}
	
	$("#quicksearchbox input:text").focus(function(){
		isFocused = true;
	});
	$("#quicksearchbox input:text").blur(function(){
		isFocused = false;
		hideSearchbox();
	});
	
	
	$('.error').fadeTo(2000,1.0);
	
	// quick reply
	$('.quickreply a').click(function() {
		hide_qr(true);
		return false;
	});
	
    
    $('a.poll').click(function() {
    	$('tr.poll').toggle();
        return false;
    });
    $('a.attach').click(function() {
    	$('tr.attach').toggle();
        return false;
    });
	
	$('textarea[name=message]').removeAttr('cols').removeAttr('rows');
	$('textarea[name=message]').autoResize({
	    animateDuration : 300,
	    limit : 3000
	});
	$('textarea[name=message]').trigger('change');
});



