$(document).ready(function() {
	//Initialization Code
	var currIdea 	= 1;							//current gift idea category							
	var fadeSpeed	= 200;							//global effects speed
	var contactData = $("ul.contactData li");		//CONTACT WIDGET - all contactData elements
	var contactMenu = $("ul.contactMenu li");		//CONTACT WIDGET - all contactMenu elements
	jQuery.easing.def = "easeInOutQuint";			//set default easing
	$("#giftImage h2.callout").css("opacity", .8);	//gift-ideas callouts transparency

	//NEWS WIDGET - JScrollPane Settings
	$(".scrollpane").jScrollPane({
		showArrows:true,
		scrollbarWidth:6						
	});	
	
	//NEWS WIDGET - Set News Story
	$("#newsBox a").click(function() {
		$id = $(this).attr("id").substring(4);
		$("#newsBox h2").hide();
		$("#newsBox .scrollBox").hide();
		$("#newsBox h2[id=date" + $id + "]").show();
		$("#newsBox .scrollBox[id=news" + $id + "]").show();
		return false;
	}).filter(":first").click();
	
	//CONTACT WIDGET - Hide everything on start
	contactData.hide();

	//CONTACT WIDGET - Process hover on/hover off
	$("ul.contactMenu li").hover(function() {
		var idNum = $(this).attr("id").substring(4);
		var element = $("ul.contactData li[id $= " + idNum + "]");
		element.fadeIn(1);
	}, function() {
		var idNum = $(this).attr("id").substring(4);
		var element = $("ul.contactData li[id $= " + idNum + "]");
		element.fadeOut(1);
	});
	
	//GIFT-IDEAS - Change Text and Images
	function setGiftSubMenu(itemID) {
		var newImageObj	= new Image();												//the new image that will go in the image container
		var imageID = "image1";
		var newImageSrc = "../images/gifts/" + currIdea + "-" + itemID + ".jpg";
		$("#giftImage h2.callout").removeClass("on");
		$(".giftSubMenu li a").removeClass("on");
		$("ul.giftSubMenu li a[id=idea" + itemID + "]").addClass("on");
		$("#giftImage h2.callout[id=item" + itemID + "]").addClass("on");							
		$("#giftImage img").fadeOut(400, function callback() {						
			$(newImageObj).load(function () {									
				this.style.display = "none";										//...make the image container "invisible" - we use style.display instead of hide() to fix a bug in Safari.
				$(newImageObj).attr("id", imageID);									//give the image it the same ID as the previous one
				//$(newImageObj).attr("id", imageID);											//give the image it the same ID as the previous one
				$("#" + imageID).replaceWith(this);									//replace the old image with the new one							
				$("#giftImage img").fadeIn(400);									//fade 
			}).attr("src", newImageSrc);											//changes the image path							
		});
		return false;
	};
								
	//GIFT-IDEAS - Fire change function
	$("ul.giftSubMenu li a").click(function() {													
		var itemID	= $(this).attr("id").substring(4);
		setGiftSubMenu(itemID);					
		$(this).blur();					
		return false;
	}).filter(":first").click();
				
	//GIFT-IDEAS - Ajax load for gift titles
	$('body').click(function(event) {
		ajaxContainer 	= $("#giftImage");
		allButtons		= $("ul#giftMenu li a");
		allSubButtons	= $("ul.giftSubMenu li a");
		allButtons.removeClass("on");					
		if ($(event.target).is('a.ajaxLink')) {					
			if ($(event.target).attr("id").substring(4) != currIdea) {
				var linkHref = $(event.target).attr("href");	//Link of new section to load												
				$(event.target).addClass("on");
				currIdea = $(event.target).attr("id").substring(4);					
				ajaxContainer.load(linkHref, function() {									
					$("#giftImage h2.callout").css("opacity", .8);		//gift-ideas callouts transparency
					allSubButtons.removeClass("on");
					$("ul.giftSubMenu li a[id=idea1]").addClass("on");
					ajaxContainer.fadeIn(fadeSpeed);
				})
			}
			return false;
		}//end if
	});//end body.click

});
