function formatText(index, panel) {
	return index + "";
}
var url = location.pathname;

$(document).ready( function() {
    if($('#primaryNav').length){
        $('#primaryNav > li > a').each(function(){
            var linkText = $(this).text().toLowerCase();
            $(this).addClass(linkText);
        });
    }
	// anythingSlider
	if ($('#slideShow').length){
		$('#slideShow').anythingSlider({
			easing: "linear",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			delay: 6500,                    // How long between slide transitions in AutoPlay mode
			animationTime: 800,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Start",             // Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: null       // Details at the top of the file on this use (advanced use)
		});
	}
	
	// portfolio
	if ($('.weddings').length || $('.everyday').length || $('.invitations').length || $('.special-items').length) {
		portfolio();
	}
	// contact
	if ($('#contactForm').length) {
		contactForm();
  }
	$('a.facebook').attr('target', 'blank');
	
}); // end DOC ready

Cufon.set("selector", jQuery);
Cufon.replace("#slideShow h2, #content h1, #tagline", {fontFamily: "England Hand DB", separate: "none", hover: true});
Cufon.replace("#primaryNav", {fontFamily: "BonvenoCF", separate: "none", hover: true});

function contactForm(){
	$('.error').hide();
	$(".button").click(function() {
		// validate and process form here
		$('.error').hide();
		var name = $("input#name").val();
		if (name == "") {
			$("label#name_error").fadeIn();
			$("input#name").focus( function() {
				if ( $("label#name_error").is(":visible") ) {
					$("label#name_error").fadeOut();
				}
			});
			return false;
		}
		var email = $("input#email").val();
		var emailFilter = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		if ( (email == "") || (!emailFilter.test(email)) ) {
			$("label#email_error").fadeIn();
			$("input#email").focus( function() {
				if ( $("label#email_error").is(":visible") ) {
					$("label#email_error").fadeOut();
				}
			});
			return false;
		}
		var phone = $("input#phone").val();
		if (phone == "") {
			$("label#phone_error").fadeIn();
			$("input#phone").focus( function() {
				if ( $("label#phone_error").is(":visible") ) {
					$("label#phone_error").fadeOut();
				}
			});
			return false;
		}
		var comments = $("textarea#comments").val();				
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comments=' + comments;

		$.ajax({
		  type: "POST",
		  url: "/wp-content/themes/custom/form-submission.php",
		  data: dataString,
		  success: function() {
			 $('form#contactForm fieldset').fadeOut();
			 $('form#contactForm').html("<div id='message'></div>");
			 $('#message')
			 .append("<h3>Thank You!</h3><p>Your inquiry has been submitted.</p><p>I'll be in touch soon.</p>")
			 .hide()
			 .fadeIn(1500, function() {
				$('#message')
			 });
		  }
		});
		return false;		  
	});
}

function displayDate() {
	var now = new Date();
	var year = now.getFullYear();
	document.write(year);
}


function portfolio() {
	/* http://www.flickr.com/services/api/explore/ */
	// config
	apiKey				= '2f5f6fa3d2a06c407cd99f9e13f7cc4c';
	photoSetId		= '72157626227586438'; /* test */
	
	// conditional photosets per page
	if ($('.weddings').length)			{ photoSetId	= '72157626227588850'; }
	if ($('.everyday').length)			{ photoSetId	= '72157626227589992'; }
	if ($('.invitations').length)		{ photoSetId	= '72157626227586438'; }
	if ($('.special-items').length)	{ photoSetId	= '72157626102476321'; }

	apiCall	=	'http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=' + photoSetId + '&format=json&jsoncallback=?';
	
	// create nav containers
	$('<ul id="workList"></ul>').appendTo('#content');
	$('<ul id="thumbList"></ul>').appendTo('#content');
	
	$.getJSON(apiCall, function(data){
		// loop through data
		$.each(data.photoset.photo, function(i,photo){
			
			// define large image variables
			imgSrc = 'http://farm' + photo.farm + '.static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '_' + 'z.jpg';
			imgClass = 'img' + photo.id;
			
			// define thumbnail variables
			thumbSrc = 'http://farm' + photo.farm + '.static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '_' + 's.jpg';
			thumbClass = 'thumb' + photo.id;
			
			// populate both lists
			$('<img/>').attr('src', imgSrc).appendTo('#workList').wrap(('<li class="' + imgClass + '"></li>'));
			$('<img/>').attr('src', thumbSrc).appendTo('#thumbList').wrap(('<li class="' + thumbClass + '"></li>')).after('<span></span>');
			
			// hide other work
			var workList = $('#workList');
			workList.find('li').not('li:eq(0)').hide();
			workList.find('li:eq(0)').addClass('selected');
			workList.find('li:eq(1)').addClass('next');
		}); // end .each
		
		$('#thumbList li').find('span').each(function(i){
			
			// populate numbered span tags
			var index = i + 1;
			$(this).text(index);
			$('#thumbList li img').hide();
            $('#thumbList li:eq(0) span').addClass('selected');
			
            // show thumbnail on hover
            $(this).css({cursor: 'pointer'}).hover(function(){
				$(this).parent('li').find('img').stop(true, true).fadeIn();
			}, function(){
				$(this).parent('li').find('img').stop(true, true).fadeOut();
			});
			
			// show corresponding image on click
			$(this).click(function(){
				if(!$(this).find('span').hasClass('selected')){
					$('#thumbList li span').removeClass('selected');
					$('#workList li').removeClass('selected').removeClass('next').removeClass('previous');
					$(this).addClass('selected');
					commonClass = $(this).parent('li').attr('class').replace(/thumb/, 'img');
					$('#workList').find('li').hide();
					$('#workList').find('li.'+ commonClass).fadeIn('slow').addClass('selected').next('li').addClass('next').prev('li').prev('li').addClass('previous');
					if($('#workList li.selected').hasClass('firstChild')){
				        $('#leftArrow').hide();
				        $('#rightArrow').show();
				    }
				    else if($('#workList li.selected').hasClass('lastChild')){
			            $('#rightArrow').hide();
			            $('#leftArrow').show();
			        } else {
		                $('#leftArrow').show();
		                $('#rightArrow').show();
		            }
				}
			});
			
		}); // end .each
		if($('#workList li').length <= 1) {
	        $('#rightArrow').hide();
	    }
	    $('#workList li:eq(0)').addClass('firstChild');
	    $('#workList li').last().addClass('lastChild');
	    $('#leftArrow').hide();
		$('#leftArrow').click(function(){
		    if($('#workList li').length > 1){
	            $('#rightArrow').show();
    		    $('#thumbList li span.selected').removeClass('selected').parent('li').prev('li').find('span').addClass('selected');
    		    $('#workList li.next').removeClass('next');
    		    $('#workList li.selected').hide().removeClass('selected').addClass('next');
    		    $('#workList li.previous').fadeIn('slow').removeClass('previous').addClass('selected').prev('li').addClass('previous');
    		    if($('#workList li.selected').hasClass('firstChild')){
    	            $('#leftArrow').hide();
    	        }
	        }
		});
	    $('#rightArrow').click(function(){
	        if($('#workList li').length > 1){
                $('#leftArrow').show();
    	        $('#thumbList li span.selected').removeClass('selected').parent('li').next('li').find('span').addClass('selected');
    	        $('#workList li.previous').removeClass('previous');
                $('#workList li.selected').hide().removeClass('selected').addClass('previous');
                $('#workList li.next').fadeIn('slow').removeClass('next').addClass('selected').next('li').addClass('next');
                if($('#workList li.selected').hasClass('lastChild')){
                    $('#rightArrow').hide();
                }
            }
	    });
	}); // end .getJSON
		

	
}
function populateValue (selector, defvalue){
  if($.trim($(selector).val()) == ""){
	 $(selector).val(defvalue);
  }
  $(selector).focusin(function(){
	 if($(selector).val() == defvalue){
		$(selector).val("");
	 }
  });
  $(selector).focusout(function(){
	 if($.trim($(selector).val()) == ""){
		$(selector).val(defvalue);
	 }
  });
}






