var temp, temp2, temp3, temp4, temp5, working=0;
var currentSet=1;
$(document).ready(function(){
// Form Validation
    $(".validate").each(function() {
        $(this).validate({
           errorClass: "invalid",
           validClass: "success",
           validClass: "success",
           errorPlacement: function(error, element) {
             error.appendTo( element.prev("label") );
           },
           errorElement: "em"
        });
    });
// Change Set
    $("a.changeset").click(function(e) {
       e.preventDefault();
       if(working==0) {
         working=1;
         temp = $(this).attr("rel");
         if(temp!=1) {
           if(currentSet==1) {
             $("#photos div:visible").fadeOut(function() { $("#set4").fadeIn(function(){ currentSet=4; working=0;  }); });
           } else {
            $("#photos div:visible").fadeOut(function(){ $("#set"+(currentSet-1)).fadeIn(function(){ currentSet=currentSet-1; working=0;  });  });
           }
         } else {
            if(currentSet==4) {
              $("#photos div:visible").fadeOut(function() { $("#set1").fadeIn(function(){ currentSet=1; working=0;  });  });
            } else {
              $("#photos div:visible").fadeOut(function() { $("#set"+(currentSet+1)).fadeIn(function(){ currentSet=currentSet+1; working=0; }); });
            }
         }
       }
    });
// Open Div
    $(".showtab").click(function(e){
        e.preventDefault();
        temp3 = $(this);
        temp = $(this).attr("rel");
        temp2 = $(this).attr("rev");
        if (temp2!="") {
            $(temp2).fadeOut("fast", function() {
                $(temp).fadeIn("slow");
            });
        } else {
            $(temp).fadeIn();
        }
        $(".tab").removeClass("active");
        temp3.parent().addClass("active");
    });
// Close Div
    $(".closediv").click(function(e) {
        temp = $(this).attr("rel");
        $("#"+temp).slideUp();
    });
// Colorbox
    $("#photos div a").colorbox();
// DatePicker
    $(".datepicker").datepicker({
      dateFormat: 'yy-mm-dd',
      minDate: new Date(1970, 1, 1),
      maxDate: new Date(2001, 1, 1),
      defaultDate: '-30Y',
      changeMonth: true,
	  changeYear: true
    });
});
