/* Author: 

*/



$(window).scroll(function () {
  var inview = '#' + $("#content > section > h1:in-viewport:first").parent().attr('id'),
      $link = $('nav a').filter('[hash=' + inview + ']');

  if ($link.length && !$link.is('.selected')) {
    $('nav a').removeClass('selected');
    $link.addClass('selected');
  }
});


$(function () {

  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
    var top = $('nav').offset().top - parseFloat($('nav').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('nav').addClass('fixed');
      } else {
        // otherwise remove it
        $('nav').removeClass('fixed');
      }
    });
  }  
});


$(document).ready(function() {
	$.localScroll();
});

$(document).ready(function() {
	$('#coda-slider-1').codaSlider({
		dynamicTabsPosition:"bottom",
		
	});
});



$(document).ready(function() {
	$("a[rel='cumulus']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='lynda']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='swan']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='start']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='drift']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='experience']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='photoBook']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
	$("a[rel='posters']").colorbox({transition:"fade", maxWidth:"990px", maxHeight:"800px"});
});




$(function() {
  $('input.text-input').css({backgroundColor:"transparent"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"transparent"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"transparent"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
	/*	if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    } */
		var email = $("input#email").val();
		/*if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }*/
		var messageSubject = $("input#messageSubject").val();
		/*
		if (messageSubject == "") {
		      $("label#messageSubject_error").show();
		      $("input#messageSubject").focus();
		      return false;
		    }*/
		
		var messageBody = $("textarea#messageBody").val();
		/*
		if (messageBody == "") {
		      $("label#messageBody_error").show();
		      $("textarea#messageBody").focus();
		      return false;
		    }*/
		
		
		var dataString = 'name='+ name + '&email=' + email + '&messageSubject=' + messageSubject + '&messageBody=' + messageBody;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
		$('#contact_form').css("background:none;");
        $('#contact_form').html("<div id='message'></div>");
        $('#contact_form').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          
        });
      }
     });
    return false;
	});
});





this.label2value = function(){	

	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	$("label").each(function(){		
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			$(obj).addClass(inactive);			
			var text = $(this).text();
			$(this).css("display","none");			
			$(obj).val(text);
			$(obj).focus(function(){	
				$(this).addClass(focused);
				$(this).removeClass(inactive);
				$(this).removeClass(active);								  
				if($(this).val() == text) $(this).val("");
			});	
			$(obj).blur(function(){	
				$(this).removeClass(focused);													 
				if($(this).val() == "") {
					$(this).val(text);
					$(this).addClass(inactive);
				} else {
					$(this).addClass(active);		
				};				
			});				
		};	
	});		
};
$(document).ready(function(){	
	label2value();	
});




	
	// // Set up PhotoSwipe 
	// document.addEventListener('DOMContentLoaded', function(){
	// 
	// 	Code.photoSwipe('a', '#content', { loop: false });
	// 
	// }, false);	
	// 


