//Alert Debugging
function PopUp() {
	alert("Alert");
}


//Start FancyGallery
function prepFancyGallery() { 
	$(".PortfolioItem a").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true, 'overlayOpacity' : .8 }); 
}
//Thinking Icon Top Right
function startThinking (){
	$('#Menu .Container p').fadeIn('slow');
}
function stopThinking (){
	$('#Menu .Container p').fadeOut('slow');
} 
//Back Button Functionality	
function BackButton() {
	alert("disfunct BackButton");
//	$('a').click(function() {
//		 $.address.value($(this).attr('href').replace(/^http:\/\/www.stephenkiersphotography.com\/2010\//, "").replace(/^#/, ''));
//	});
}
//To Do anytime the page reloads
function ToDoOnLoad () {
	prepFancyGallery();
//	BackButton();
	stopThinking();
	$(".PortfolioItem, .Portfolio").mouseenter(function(){
		$('a span',this).stop(true,true);
		$('a span',this).fadeIn(1000);
	});
	$(".PortfolioItem, .Portfolio").mouseleave(function(){
		$('a span',this).fadeOut(400);
	});
	$(".FormArea input, .FormArea textarea").focus(function() {
		$(this).addClass("selected");
	});
	$(".FormArea input, .FormArea textarea").blur(function() {
		$(this).removeClass("selected");
	});
	
	//LoginArea
	$(".FormArea #shootdate").focus(function(){
		if ($(this).attr("value")=="YYYYMMDD") {
			$(this).attr("value","");
		}
	});
	$(".FormArea #shootdate").blur(function(){
		if ($(this).attr("value")==="YYYYMMDD" || $(this).attr("value")==="" || $(this).attr("value")===" ") {
			$(this).attr("value","YYYYMMDD");
		}
	});
	$(".Growl").fadeIn(1000).animate({opacity: 1.0}, 4000).fadeOut(1000, function() {$(this).remove();});
	$("#StoreArea h4").click(function() {
		$("#StoreArea ul li ul li ul li div.slide").slideUp("slow");
		if (!$(this).next().is(":visible")) { $(this).next().slideDown("slow"); }
	});
	$("#StoreArea h3").click(function() {
		$("#StoreArea ul li ul li ul.slide").slideUp("slow");
		if (!$(this).next().is(":visible")) { $(this).next().slideDown("slow"); }
	});
	
}


//To Do on initial load
$(document).ready(function() {					   
	ToDoOnLoad();
	$("#twitter_update_list").children(':odd').addClass('Odd');
	
	//If not index.asp
	if ( $.address.value() !== "\/" ) {
	window.location = "http://www.stephenkiersphotography.com/2010" + $.address.value();
	}
	//MENU Otherlinks DropDown
	$("#OtherLinks").hover(
		function(){
			$('#OtherLinks ul').stop(true,true);
			$('#OtherLinks ul').fadeIn(600);
		},function(){
			$('#OtherLinks ul').fadeOut(400);
		});
	
	//FAQ Area
	$('#FAQarea div').hide();
	$('#FAQarea h3').click(function () {
		$(this).next('div').slideToggle();
	});
	
//	$(".Container #About").mouseenter(function(){
//		$('#OtherLinks ul').fadeOut(400);
//	});
	
	//Search Bar
	$("#Menu input").attr("value","search portfolio");
	$("#Menu input").focus(function(){
		if ($(this).attr("value")=="search portfolio") {
			$(this).addClass('focus');
			$(this).attr("value","");
		}
	});
	$("#Menu input").blur(function(){
		if ($(this).attr("value")==="search portfolio" || $(this).attr("value")==="" || $(this).attr("value")===" ") {
			$(this).removeClass('focus');
			$(this).attr("value","search portfolio");
		}
	});	
	$('#Menu .Container div input').keyup(function(){
		clearTimeout($.data(this, "timer"));
		var ms = 500; //milliseconds
		var val = this.value;
		var wait = setTimeout(function() {
		  searchInput();
		}, ms);
		$.data(this, "timer", wait);
		//searchInput();
	});
	$('#Menu .Container div input').submit(function(){
		searchInput();
		return false;
	});
});







//AJAX ACTIONS
$.ajaxSetup ({  
	cache: false
});
function ajaxURL(loadUrl, title) {
	
//The AJAX
	var toLoad = loadUrl + " #BodyArea"
	function showContainer () {
		$("#Container").slideDown("slow", ToDoOnLoad);
	}
	function loadContent() {
		$("#Container").load(toLoad, showContainer);
	}
	startThinking();
	$('#Container').slideUp('fast',loadContent);
	//$.address.title($.address.title())
	
//The Address Change
	$.address.value(loadUrl.replace(/^http:\/\/www.stephenkiersphotography.com\/2010\//, "").replace(/^#/, ''));
	if (title === undefined) {
		$.address.title("Designer, Photographer, Pastor - Stephen Kiers");
	} else {
		$.address.title(title + " - Stephen Kiers");
	}
//	alert($.address.title());
	
//Return	
	return false;
	
}

function searchInput () {	
	var tag = $('#Menu .Container div input').attr("value")
	if ( tag ==="search portfolio" || tag ==="" || tag ===" ") {
		startThinking();
		$("#Container").load('http://www.stephenkiersphotography.com/2010/ #BodyArea', '', ToDoOnLoad);
	} else {
		startThinking();
		$("#Container").load('http://www.stephenkiersphotography.com/2010/portfolio.asp?ID=' + tag + ' #BodyArea', '', ToDoOnLoad);
	}
}

