var family = {

	enlargeThumb: function(){
		
		$("div.thumbnail").click(function(){
			info = $(this).find("input").attr("value");
			info = info.split(",");
			
			thumb = info[0];
			width = info[1];
			height = info[2];
			
			_page_size = family.getPageSize();
			_page_scroll = family.getPageScroll();
			
			_max_size = _page_size[3] - 50;
			
			if(height > width){
				if(height > _max_size){
					ratio = width / height;
					height = _max_size;
					width = Math.round(Math.abs(_max_size * ratio));
				}
			}else{
				if(width > _max_size){
					ratio = height / width;
					width = _max_size;
					height = Math.round(Math.abs(_max_size * ratio));
				}
			}
			
			$("body").prepend("<div id=\"image-popup-container\"></div><div id=\"image-popup\"><div id=\"image-close\"></div><img id=\"image-popup-img\" style=\"float: left\" alt=\"\" /></div>");
			$("img#image-popup-img").attr("src", thumb + "&w=" + width + "&h=" + height);
			
			$("div#image-popup-container").css({
				backgroundColor: "#000",
				opacity: 0.3,
				width: _page_size[0] + "px",
				height: _page_size[1] + "px",
				margin: 0,
				left: 0,
				top: 0
			});
			
			$("div#image-popup").css("position","absolute");
			$("div#image-popup").css("top", ( $(window).height() - height ) / 2 + $(window).scrollTop() + "px");
			$("div#image-popup").css("left", ( $(window).width() - width ) / 2 + $(window).scrollLeft() + "px");
			
			$("div#image-close").click(function(){
				family.close();
			});
		});
	},
	
	close: function(){
		$("div#image-popup-container").remove();
		$("div#image-popup").remove();
	},
	
	getPageSize: function(){
		var xScroll, yScroll;
		if(window.innerHeight && window.scrollMaxY){
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		}else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if(self.innerHeight){ // all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			}else{
				windowWidth = self.innerWidth;
			}
			
			windowHeight = self.innerHeight;
		}else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}else if(document.body){ // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		}else{ 
			pageHeight = yScroll;
		}
		
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		}else{
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight,windowWidth,windowHeight];
	},
	
	getPageScroll: function(){
		var xScroll, yScroll;
		if(self.pageYOffset){
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		}else if(document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		}else if (document.body){ // all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		return [xScroll,yScroll];
	},

};

var sifrMinimize = {
	
	init: function(fi){
		if($(fi).hasClass("page-heading-archive")){
			$(fi).next("div.section").find("h1.archives-minus").toggle();
			$(fi).next("div.section").find("h1.archives-plus").toggle();
			$(fi).next("div.section").find("div.minimize-list").slideToggle();
		}else if($(fi).hasClass("page-heading-category")){
			$(fi).next("div.section").find("h1.categories-minus").toggle();
			$(fi).next("div.section").find("h1.categories-plus").toggle();
			$(fi).next("div.section").find("div.minimize-list").slideToggle();
		}
		
	}
	
};

var blog = {
	
	expand: function(){
		$(".blog-remainder").hide();
		$(".blog-remainder-expand").click(function(){
			var clicked = this;
			$(this).parent().prev(".blog-remainder-container").find(".blog-remainder").slideToggle("slow", function(){
				if($(this).css("display") == "block"){
					$(clicked).find("div").attr("class", "minus");
				}else{
					$(clicked).find("div").attr("class", "plus");
				}
			});
		});
	}
	
};

var topIcons = {
	
	hover: function(){
	
		$("div#top-icons img").each(function(){
			$(this).css("opacity",".2");
			$(this).hover(function(){
				$(this).css("opacity",".5");
			},function(){
				$(this).css("opacity",".2");
			});
		});
	
	}
	
};

var fadeimg = {

	init: function(){
	
		$("img.fadeimage").each(function(){
				$(this).css("opacity", "0.4");
				$(this).hover(function(){
					$(this).css("opacity","1");
				},function(){
					$(this).css("opacity","0.4");
				});
			});

	}
	
};

var topnav = {

	init: function(){
	
		$("ul#top-bar-navigation li").hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none'); }
		);

	}
	
};
