$(document).ready(function() {
   $('input').keypress(function (event){ return event.keyCode == 13 ? false : true; });
   $("a[rel^='vglightbox']").prettyPhoto();
   //for frontpage tab
   if($("#frontpage_tab_slide").length) {
      $("#frontpage_tab_slide #tab_1").css("opacity","0").animate({ opacity: "1" },2500);
      $("#frontpage_tab_slide .paging").show();
      $("#frontpage_tab_slide .paging span:first,#frontpage_tab_slide .thumbpnum:first,#frontpage_tab_slide .tab_slide_content:first").addClass("active");

      //Paging + Slider Function
      rotate = function(){
         var nowActive = $('#frontpage_tab_slide .paging span.active').attr("rel");
         var triggerID = $active.attr("rel")-1;
         var trigerIDnext = (triggerID+1);
         var DivNext = "#tab_" + trigerIDnext;
         var DivNow = "#tab_" + nowActive;

         $("#frontpage_tab_slide .navslide").removeClass('active');
         $("#tabpnum_"+trigerIDnext).addClass('active');
         $("#thumbpnum_"+trigerIDnext).addClass('active');
         //$("#tabdebug").html("DivNow = "+DivNow+" - DivNext = "+DivNext+" divNowLast"+nowActive); //for debug
         $(DivNow).fadeOut(700,function(){
            $(DivNext).fadeIn(700);
         });
      };

      rotateSwitch = function(){ //Rotation + Timing Event
         play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
            $active = $('#frontpage_tab_slide .paging span.active').next();
            if($active.length === 0) { //If paging reaches the end...
               $active = $('#frontpage_tab_slide .paging span:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
         },4500); //Timer speed in milliseconds (3 seconds)
      };

      rotateSwitch(); //Run function on launch

      //On Hover
      $("#frontpage_tab_slide .image_reel").hover(function() {
         clearInterval(play); //Stop the rotation
      }, function() {
         rotateSwitch(); //Resume rotation
      });

      $("#frontpage_tab_slide .paging span,#frontpage_tab_slide .thumbpnum").click(function() {
         $active = $(this); //Activate the clicked paging
         clearInterval(play); //Reset Timer Stop the rotation
         rotate(); //Trigger rotation immediately
         rotateSwitch(); // Resume rotation
         return false; //Prevent browser jump to link anchor
      });
   } //end for frontpage tab

   //for solution tab
   if($("#box_solution").length) {
      $("#box_solution .tab_solution:first").addClass("active");
      $(".tab_solution_pagenum .sopagenum:first").addClass("active");

      rotate_Solution = function(){
         var nowActive2 = $('.tab_solution_pagenum span.active').attr("rel");
         var triggerID2 = $active2.attr("rel")-1;
         var trigerIDnext2 = (triggerID2+1);
         var DivNext2 = "#tab_solution_" + trigerIDnext2;
         var DivNow2 = "#tab_solution_" + nowActive2;
         $(".tab_solution,.sopagenum").removeClass('active');
         $("#tab_solu_num_"+trigerIDnext2).addClass('active');
         //$("#box_solution #desc").html("DivNow2 = "+DivNow2+" - DivNext2 = "+DivNext2); //for debug
         $(DivNow2).fadeOut(250,function(){
            $(DivNext2).fadeIn(250);
         });
      };

      rotate_SolutionSwitch = function(){ //Rotation + Timing Event
         playnow = setInterval(
            function(){ //Set timer - this will repeat itself every 3 seconds
               $active2 = $('.tab_solution_pagenum span.active').next();
               if($active2.length === 0) { //If paging reaches the end...
                  $active2 = $(".tab_solution_pagenum .sopagenum:first"); //go back to first
               }
               rotate_Solution(); //Trigger the paging and slider function
            }
         ,6400); //Timer speed in milliseconds (3 seconds)
      };

      rotate_SolutionSwitch(); //Run function on launch

      $("#box_solution .tab_solution").hover(function() {
         clearInterval(playnow); //Stop the rotation
      }, function() {
         rotate_SolutionSwitch(); //Resume rotation
      });

      $(".tab_solution_pagenum span").click(function() {
         $active2 = $(this); //Activate the clicked paging
         clearInterval(playnow); //Reset Timer Stop the rotation
         rotate_Solution(); //Trigger rotation immediately
         rotate_SolutionSwitch(); // Resume rotation
         return false; //Prevent browser jump to link anchor
      });

   } //end for tab_content tab

   //for solution tab
   if($("div.tab_content").length) {
      $("div.tab_content:first,span.tabbutton:first").addClass("firstchild active");
      $("div.tab_content:last,span.tabbutton:last").addClass("lastchild");
      $(".tabbutton").click(function() {
         SLDivNext = $(this).attr("rel"); //Activate the clicked paging
         SLDivNow = $('.tabbutton.active').attr("rel");
         $(".tab_content,.tabbutton").removeClass('active');
         $(this).addClass('active');
         $(SLDivNow).fadeOut(150,function(){
            $(SLDivNext).fadeIn(150);
         });
      });
   } //end for tab_content tab

   $(".login_btn,.loginshowhide").hover(function() {
      $('.loginshowhide,.login_btn').toggleClass("active");
  });
/*
   if($("div.findchildnow").length) {
      $("div.findchildnow:last").attr('id','entry_last');
   }
   */
});

function clickclear(thisfield, defaulttext) {
   if (thisfield.value == defaulttext) {
      thisfield.value = "";
   }
}
function clickrecall(thisfield, defaulttext) {
   if (thisfield.value == "") {
      thisfield.value = defaulttext;
   }
}

