/*---------------------------------------------------------
[JQuery Scripts]

Project: 		Melissa Zimmerman's portfolio site
Version:		1.0
Author: 		Keith Chu (keith@keithchu.com)
Last Updated:	September 7, 2008

Usage:			Behavioral control on the page.			
-----------------------------------------------------------*/

$(function(){

/* image preloader for backgrounds */
jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
};
$.preloadImages(
	"bgs/images/images_hs0.png",
	"bgs/images/images_hs1.png",
	"bgs/images/images_hs2.png",
	"bgs/images/images_hs5.png",
	"bgs/images/images_hs6.png"
);

/* fade first image */
$('#home #primary_content #photos img:first-child')
	.add('#updates #primary_content #photos img:nth-child(2)')
	.add('#about #primary_content #photos img:nth-child(3)')
	.add('#media #primary_content #photos img:nth-child(4)')
	.add('#contact #primary_content #photos img:nth-child(5)')
	.fadeTo("normal", 0.5);

/* image swap effect */
$("#primary_content #photos img")
	.mouseover(function(){
		$(this).css("cursor","pointer");
	})
	.click(function(){
		// 1. Check for any faded out icons and fade them back in
		$("#primary_content #photos img").fadeTo(10, 1);

		// 2. Fade out this icon
		$(this).fadeTo("normal", 0.5);
	
		// 3. Set #primary_content bg to corresponding image
		var src = $(this).attr("src");
		var imageUrl = "url(bgs/" + src + ")";
	
		$("#primary_content").css({
			backgroundImage: imageUrl,
			backgroundPosition: "top right"
		});
	})
;

/* mouseover effect for home button on homepage */
$(".home a img")
	.mouseover(function(){
		$(this).attr("src","images/home_icon2.png");
	})
	.mouseout(function(){
		$(this).attr("src","images/home_icon4.png");
	})
;

/* mouseover effect for navigation */
$("#navigation li[class!='home'] a")
	.mouseover(function(){
		$(this).css({
			color: "#fff"
		});
		$(this).next().css({
			color: "#cb7a7a"
		});
	})
	.mouseout(function(){
		$(this).css({
			color: "#fff"
		});		
		$(this).next().css({
			color: "#4393c0"
		});
	})
;

/* pdf effect for resume hover */
$("#navigation .resume a")
	.mouseover(function(){
		$("<img src=\"images/pdficon_small.gif\" class=\"pdf\" />")
		.appendTo("#navigation");
	})
	.mouseout(function(){
		$("img.pdf").remove();
	})
;

/* photo gallery size */

/* photo gallery hover info */
$("#g_gallery a")
	.mouseover(function(){
		var title = $(this).attr("title");
		$("#gallery_title")
			.text(title)
			.css("display","block");
	})
	.mouseout(function(){
		$("#gallery_title")
			.text("")
			.css("display","none");
	})
;

/* facebox init */
if(!$.browser.msie){
$('#media_galleries a[rel*=facebox], #updates a[rel*=facebox]')
	.facebox()
;}

}); /* end ready(); */


