/**
 * @author Fernando
 */

function mostrar() { 
   $("#pop").fadeIn('slow'); 
} //checkHover

$(document).ready(function (){

   var img_w = 414 + 10; 
   var img_h = 652 + 28; 
    
   $("#pop").css('width', img_w + 'px'); 
   $("#pop").css('height', img_h + 'px'); 
    
   $("#pop").hide();
   
   var w = $(this).width(); 
   var h = $(this).height(); 
    
   w = (w/2) - (img_w/2); 
   h = (h/2) - (img_h/2); 
   $("#pop").css("left",w + "px"); 
   $("#pop").css("top",h + "px");
   
   setTimeout("mostrar()",1500);
   
   $("#cerrar").click(function (){ 
      $("#pop").fadeOut('slow'); 
   });
   $(".blogEntryFirst").mouseover(function (){
		$('#topfpost').addClass("topfirstpostover");
		$('#middlefpost').addClass("middlefirstpostover");
		$('#downfpost').addClass("downfirstpostover");
		$(this).css("cursor", "hand");
   });
   $(".blogEntryFirst").mouseout(function (){
		$('#topfpost').removeClass("topfirstpostover"); 
		$('#middlefpost').removeClass("middlefirstpostover"); 
		$('#downfpost').removeClass("downfirstpostover"); 
		$(this).css("cursor", "pointer");
   });
   $(".blogEntryList").mouseover(function (){
		$(this).addClass("blogEntryListOver"); 
		$(this).css("cursor", "hand");
   });
   $(".blogEntryList").mouseout(function (){
		$(this).removeClass("blogEntryListOver"); 
		$(this).css("cursor", "pointer");
   });
   $(".blogEntryFirst").click(function (){
	   $("#sender").attr('action',$("#imagebl"+$(this).attr("id")).attr('href'));
   	   $("#sender input").attr('value',$(this).attr("id"));
	   $("#sender").submit();
//		location.replace($("#"+$(this).attr("id")+" a:first").attr('href'));
   });
   $(".blogEntryList").click(function (){
	   $("#sender").attr('action',$("#imagebl"+$(this).attr("id")).attr('href'));
   	   $("#sender input").attr('value',$(this).attr("id"));
	   $("#sender").submit();
//		location.replace($("#"+$(this).attr("id")+" a:first").attr('href'));
   });
   $(".bg_father").click(function (){
		location.replace($(".bg_father a:first").attr('href'));
   });
   $(".bg_father").mouseover(function (){
		$(this).css("cursor", "hand");
   });
   $(".bg_father").mouseout(function (){
		$(this).css("cursor", "pointer");
   });
   $(".bg_sons").click(function (){
		location.replace($(".bg_sons a:first").attr('href'));
   });
   $(".bg_sons").mouseover(function (){
		$(this).css("cursor", "hand");
   });
   $(".bg_sons").mouseout(function (){
		$(this).css("cursor", "pointer");
   });
   $(".bg_husbands").click(function (){
		location.replace($(".bg_husbands a:first").attr('href'));
   });
   $(".bg_husbands").mouseover(function (){
		$(this).css("cursor", "hand");
   });
   $(".bg_husbands").mouseout(function (){
		$(this).css("cursor", "pointer");
   });
   $(".bg_workers").click(function (){
		location.replace($(".bg_workers a:first").attr('href'));
   });
   $(".bg_workers").mouseover(function (){
		$(this).css("cursor", "hand");
   });
   $(".bg_workers").mouseout(function (){
		$(this).css("cursor", "pointer");
   });
   var lval=1;
   $("#navigation img").mouseover(function (){
		var image=$(this).attr('src');
   		if (image.search(/_over.gif/)<0) {
			var large = image.length;
			var start = 0;
			var stop = large - 4;
			image = image.substring(start, stop);
			image += '_over.gif';
			$(this).attr('src', image);
		}else{
			lval=0;
		}
   });
   $("#navigation img").mouseout(function (){
		var image=$(this).attr('src');
   		if (lval==1) {
			var large = image.length;
			var start = 0;
			var stop = large - 9;
			image = image.substring(start, stop);
			image += '.gif';
			$(this).attr('src', image);
		}else{
			lval=1;
		}
   });
   $("#radvertise img").mouseover(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-4;
		image=image.substring(start,stop);
		image+='_over.gif';
		$(this).attr('src',image);
   });
   $("#radvertise img").mouseout(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-9;
		image=image.substring(start,stop);
		image+='.gif';
		$(this).attr('src',image);
   });
   
   $("#nextexc").mouseover(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-4;
		image=image.substring(start,stop);
		image+='_over.png';
		$(this).attr('src',image);
   });
   $("#nextexc").mouseout(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-9;
		image=image.substring(start,stop);
		image+='.png';
		$(this).attr('src',image);
   });
   $("#chapexc").mouseover(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-4;
		image=image.substring(start,stop);
		image+='_over.png';
		$(this).attr('src',image);
   });
   $("#chapexc").mouseout(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-9;
		image=image.substring(start,stop);
		image+='.png';
		$(this).attr('src',image);
   });
   $(".registernow img").mouseover(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-4;
		image=image.substring(start,stop);
		image+='_over.jpg';
		$(this).attr('src',image);
   });
   $(".registernow img").mouseout(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-9;
		image=image.substring(start,stop);
		image+='.jpg';
		$(this).attr('src',image);
   });
   
   $("#popbook").mouseover(function (){
		$('#booktitle').attr('src','images/titles/thebook_title_over.gif');
		$(this).css("cursor", "hand");
   });
   $("#popbook").mouseout(function (){
		$('#booktitle').attr('src','images/titles/thebook_title.gif');
		$(this).css("cursor", "pointer");
   });
   $("#popbook").click(function (){
	   $("#popbook form").submit();		
   });
   $("#popdocumentary").mouseover(function (){
		$('#doctitle').attr('src','images/titles/thedocumentary_title_over.gif');
		$(this).css("cursor", "hand");
   });
   $("#popdocumentary").mouseout(function (){
		$('#doctitle').attr('src','images/titles/thedocumentary_title.gif');
		$(this).css("cursor", "pointer");
   });
   $("#popdocumentary").click(function (){
	   $("#popdocumentary form").submit();		
   });
   $("#popcompanion").mouseover(function (){
		$('#comptitle').attr('src','images/titles/companionset_title_over.gif');
		$(this).css("cursor", "hand");
   });
   $("#popcompanion").mouseout(function (){
		$('#comptitle').attr('src','images/titles/companionset_title.gif');
		$(this).css("cursor", "pointer");
   });
   $("#popcompanion").click(function (){
	   $("#popcompanion form").submit();		
   });
   
   $("#nextexcerpt").click(function (){
		var dir='http://www.goodmenbook.org/library/excerpt_ajax.php';
		var datasend='category='+category+'&id='+nextexcerpt;
		$.ajax({
			type: "POST",
			url: dir,
			data: datasend,
			dataType: 'json',
			success: function(data){
				$('.excerpt_list_title').removeClass('excerpt_list_title_active');
				$('#excerpt_'+nextexcerpt).addClass('excerpt_list_title_active');
				for (x in data){
					nextexcerpt=data[x].next;
					$('.bg_excerpt_content').fadeOut("slow",function(){
						$(this).html(data[x].content);
						$(this).fadeIn('slow');
					});
				}
			}
		});
		return false;
   });
   $(".excerpt_list_title").click(function (){
	   	nextexcerpt=$(this).attr('id').substring(8); 
		var dir='http://www.goodmenbook.org/library/excerpt_ajax.php';
		var datasend='category='+category+'&id='+nextexcerpt;
		$.ajax({
			type: "POST",
			url: dir,
			data: datasend,
			dataType: 'json',
			success: function(data){
				$('.excerpt_list_title').removeClass('excerpt_list_title_active');
				$('#excerpt_'+nextexcerpt).addClass('excerpt_list_title_active');
				for (x in data){
					nextexcerpt=data[x].next;
					$('.bg_excerpt_content').fadeOut("slow",function(){
						$(this).html(data[x].content);
						$(this).fadeIn('slow');
					});
				}
			}
		});
		return false;
   });
   
   $(".revdocbook img").mouseover(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-4;
		image=image.substring(start,stop);
		image+='_over.gif';
		$(this).attr('src',image);
   });
   $(".revdocbook img").mouseout(function (){
		var image=$(this).attr('src');
		var large=image.length;
		var start=0;
		var stop=large-9;
		image=image.substring(start,stop);
		image+='.gif';
		$(this).attr('src',image);
   });
});