$(document).ready(function () {
	var active = 1;
	var pausa = 1500;
	
	$("#main_image").attr({src: $("#image_1 img").attr("src") });
	
    $("#next").click(function () {
	    $("#forimg").animate({"opacity": "0"}, pausa);
	    $("#text ").animate(
				{"opacity": "0"}, 
				pausa, 
				function() {
					if (active < $("#items li").size()) { active = active + 1;} else { active = 1; }
					$("#text").html($("#items #item_" + active).html());
					$("#main_image").attr({src: $("#image_" + active + " img").attr("src") });
					
					$("#image_" + active + " img").unload( function () { alert("Bye now!"); } );

					$("#active_items").html(active + "/");
					if (active != 1) {
						$("#prev").removeClass("selected");
					}
				}
			);
	    $("#forimg").animate({"opacity": "1"}, pausa);
	    $("#text ").animate({"opacity": "1"}, pausa);
		return false; 
    });	
    $("#prev").click(function () {
	    $("#forimg").animate({"opacity": "0"}, pausa);
	    $("#text ").animate(
				{"opacity": "0"}, 
				pausa, 
				function() {
					if (active > 1) {active = active - 1;} else { active = $("#items li").size(); }
					$("#text").html($("#items #item_" + active).html());
					$("#main_image").attr({src: $("#image_" + active + " img").attr("src") });
					$("#active_items").html(active + "/");
				}
			);
	    $("#forimg").animate({"opacity": "1"}, pausa);
	    $("#text ").animate({"opacity": "1"}, pausa);
		return false; 
    });
	$("#count_items").html($("#items li").size());
	var active = 1;
	var content = $("#items li:first").html();
	$("#text").html(content);
	
    $("#pfscl").click(function () { prevFullscreen(); inhtl(); });
    $(".hnn").click(function () {   prevFullscreen(); inhtl(); });
    $("#title").click(function () {  prevFullscreen(); inhtl();});
	$("#for_read").click(function () { prevFullscreenClose(); });
	$("#for_read div").click(function () { prevFullscreenClose(); });
	
});
function hidAuth () {
	$("#authi").css('display','none');
}
function showAuth () {
	if ($("#authi").css('display') != "block") {
	$("#authi").css('display','block');
	if ($("#search").css('display') == "block") {
			$("#search").css('display','none');
		}
	} else {
		$("#authi").css('display','none');
	}
} 
function hidSearch () {
	$("#search").css('display','none');
}
function showSearch () {
	if ($("#search").css('display') != "block") {
		$("#search").css('display','block');
		
		
		if ($("#authi").css('display') == "block") {
			$("#authi").css('display','none');
		}
	} else {
		$("#search").css('display','none');
	}
}
function prevFullscreen(){
		var wi = document.documentElement.clientWidth || d.documentElement.offsetWidth;
		var hi = document.documentElement.clientHeight || d.documentElement.offsetHeight;
		var hip = hi + 'px';
		
		$("#for_read").css({'top':'0px', 'height': hip, 'visibility': 'visible', 'opacity': '0.7'});
		$("#main_content").css({'display': 'block'});

}
function prevFullscreen_i(){
		var wi = document.documentElement.clientWidth || d.documentElement.offsetWidth;
		var hi = document.documentElement.clientHeight || d.documentElement.offsetHeight;
		var hip = hi + 'px';
		
		$("#for_read").css({'top':'0px', 'height': hip, 'visibility': 'visible', 'opacity': '0.7'});
		$("#main_contenti").css({'display': 'block'});

}

function prevFullscreenClose(){
		$('#for_read').css({'visibility': 'hidden', 'opacity': '0'});
		if ( $('#main_content').css({'display': 'block'}) ) {
			$('#main_content').css({'display': 'none'});
		}
		if ( $('#main_contenti').css({'display': 'block'}) ) {
			$('#main_contenti').css({'display': 'none'});
		}
}
function inhtl0() {
	if ($('#main_content') && $('#all_post')) 
		$('#main_content').html($('#all_post').html());
	
}
function inhtl() {
	if ($('#main_content')) 
		$('#main_content').html($('.content_vis').html());
	
}