//<script>
$(document).ready(
  function(){
  
    var data = "";
    var dataArray;
    var src = "";
    var type = "";
        
    $("#messageBox").hide();
    
    //Ok on the teacher home page, we need to postion the scroller to the center.     
    if($("#scroller").length > 0){
      $("#scroller").scrollLeft(825);
    }

    if($("#myActivities").length > 0){
      //$("#myActivities").scrollTop(30);
    }    
    
    if($("#formData").length > 0){
      data = $("#formData").text();
      dataArray = data.split("_");
      src = dataArray[0];
      type = dataArray[1];    
    }
        
    //This pre-fills the topic box when a user creates a new activity.
    if($("#topicBox").length > 0){
      $("#topicBox").html("<b>loading...</b>");
      $.ajax({
        url: "loadBoxNew.php",
        data: "box=topics&src="+src+"&type="+type,
        cache: false,
        success: function(html){
          $("#topicBox").html(html);
          
          /*$(".selectorTxt").hover(
            function(){
              $(this).css({'background-color' : '#FE430C'});
              $(this).css({'color' : 'white'});
            }, 
            function(){
              $(this).css({'background-color' : 'white'});
              $(this).css({'color' : '#EB3403'});
            }
          );*/
          
          $(".topicBoxSelector").click(
            function(){
              var selected = $(this).attr("name");
              var selectedID = this.id;
              //var data = $("#formData").text()
              //var dataArray = data.split("_");
              //var src = dataArray[0];
              //var type = dataArray[1];
              $("#topicSelected").html("<span>"+selected+"</span><input type=\"hidden\" name=\"topic\" value=\""+selectedID+"\" />");
            
              //if the rightActivities box is there, populate it. 
              if($("#rightActivities").length > 0){
                $.ajax({
                  url: "loadBoxNew.php",
                  data: "box=rightActivities&topicID="+selectedID+"&src="+src+"&type="+type,
                  cache: false,
                  success: function(html){
                    $("#rightActivities").html(html);
                  }
                });
              }
            }             
          );
        }
      });
    }

    //This pre-fills the book box when a user created a new activity.
    if($("#bookBox").length > 0){
      $("#bookBox").html("<b>loading...</b>");
      var selectedBookBox = "";
      $.ajax({
        url: "loadBoxNew.php",
        data: "box=books&src="+src+"&type="+type,
        cache: false,
        success: function(html){
          $("#bookBox").html(html);
          
          /*$(".selectorTxt").hover(
            function(){
              $(this).css({'background-color' : '#FE430C'});
              $(this).css({'color' : 'white'});
            }, 
            function(){
              $(this).css({'background-color' : 'white'});
              $(this).css({'color' : '#EB3403'});
            }
          );*/
          
          $(".bookBoxSelector").click(
            function(){
              //grabs data from a hidden div
              /*var data = $("#formData").text();
              var dataArray = data.split("_");
              var src = dataArray[0];
              var type = dataArray[1];*/
              
              //general information about the item you just selected                                  
              var selected = $(this).attr("name");
              var selectedID = this.id;
              var bookID = selectedID;
              $("#bookSelected").html("<span>"+selected+"</span><input type=\"hidden\" name=\"book\" value=\""+selected+"\" />");
              
              //clear any boxes which have been loaded...
              $("#chapterBox").html("");
              $("#activityBox").html("");
              
              //now fill the chapter box.
              $.ajax({
                url: "loadBoxNew.php",
                data: "box=chapters&book="+selectedID+"&src="+src+"&type="+type,
                cache: false,
                success: function(html){
                  $("#chapterBox").html(html);
                  
                  /*$(".selectorTxt").hover(
                    function(){
                      $(this).css({'background-color' : '#FE430C'});
                      $(this).css({'color' : 'white'});
                    }, 
                    function(){
                      $(this).css({'background-color' : 'white'});
                      $(this).css({'color' : '#EB3403'});
                    }
                  );*/
                  
                  $(".chapterBoxSelector").click(
                    function(){
                      var chapterID = this.id;
                      var selected = $(this).attr("name");
                      //var src = $("#formData").text();
                     /* var data = $("#formData").text()
                      var dataArray = data.split("_");
                      var src = dataArray[0];
                      var type = dataArray[1];*/
                      var selectedID = this.id;
                      
                      $("#chapterSelected").html("<span>"+selected+"</span><input type=\"hidden\" name=\"chapter\" value=\""+selectedID+"\" />");
                      
                      $("#activityBox").html("");
                      //Ok this is the case when a user is searcing for an activity, so we need to fill in
                      //the activity box.
                      if($("#activityBox").length > 0){
                        //alert("click!");
                        $.ajax({
                          url: "loadBoxNew.php",
                          data: "box=activities&book="+bookID+"&chapter="+chapterID+"&src="+src+"&type="+type,
                          cache: false,
                          success: function(html){
                            $("#activityBox").html(html);
                            //activitySelector
                            
                            /*$(".activitySelector").click(
                              function(){
                                var addActivity = this.id;
                                var actName = jQuery.trim($(this).text());
                                var addConfirm = confirm("Did you want to add \""+actName+"\" to your activities?");
                                if(addConfirm == true){
                                  $.ajax({
                                    url: "addActivity.php",
                                    data: "activity="+addActivity,
                                    cache: false,
                                    success: function(html){
                                      alert(html);  
                                    }
                                  });
                                }else{
                                }
                              }
                            );*/  
                          }
                        });
                      }           
                    }
                  );
                }
              });
            }
          );
        }
      });
    }
    
    if($("#messageBox").length > 0 && $("#messageBox").text().length > 5){
      $("#messageBox").show();
      
      if($("#assignActivities").length > 0){
        //window.location = "#assignActivities";  
      }  
    }
   
    
    $(".removeActivity").click(
      function(){
        var id = this.id;
        if(isNumeric(id)){
          var msg = "Are you sure you want to remove this activity?";
          var addConfirm = confirm(msg);
          
          if(addConfirm == true){
            window.location = "TeachersActivities.php?id="+id;
          }
        }
      }
    );

        
    $(".removeActivityFromClass").click(
      function(){
        var id = this.id;
        var msg = "Are you sure you want to remove this activity from your class?\n The report associated with this activity will also be removed.";
        var addConfirm = confirm(msg);
        if(addConfirm == true){
          window.location = "chooseActivities.php?delete="+id+"#classActivitesTop";
        }
      }
    );
    
    $(".assignDueDate").click(
      function(){
        var classID = $(this).attr("classID");
        var classActivityID = $(this).attr("classActivityID");
 
        if($("#dueDateForm" + classActivityID).is(':hidden'))
        {
          $("#dueDateForm" + classActivityID).slideDown("slow");
          $("#datePickerValue" + classActivityID).datepicker();
        }
        else
        {
          $("#dueDateForm" + classActivityID).slideUp("slow");
        }
      }
    );
       
    $(".dateSave").click(
      function(){
        var classID = $(this).attr("classID");
        var classActivityID = $(this).attr("classActivityID");
        var date = $("#datePickerValue" + classActivityID).val();
 
        $("#dueDateForm" + classActivityID).slideUp("slow");
        window.location = "chooseActivities.php?id=" + classID + "&classActivityID=" + classActivityID + "&date=" + date;        
      }
    );
            
    $(".assignToClass").click(
      function(){
        var id = this.id; 
        if($("#classSubBox"+id).is(':hidden'))
          $("#classSubBox"+id).slideDown("slow");
        else
          $("#classSubBox"+id).slideUp("slow");
            
      }
    );    
    


    $("*.msgBox").click(
      function(e){
        if ( $('#messageBox').is(':hidden')) {
          $("#messageBox").show();
        } else {
          $("#messageBox").hide(); 
        }
    	   
        var rmClass = this.id.replace('rmClass_', "");
        //alert(rmClass);
        var position = e.pageY - 300;
        if(isNumeric(rmClass)){
          $("#messageBox").css({
            "margin-top" : position
          });

          var msg = "<strong>Are you sure you want to remove this class?</strong>";
          msg = msg + "<br\> <a href=\"TeachersClasses.php?remove=" + rmClass + "\">Yes</a>";
          msg = msg + " / <span onclick=\"closeMsgBox();\" class=\"aLink\">No</span>";
          $("#messageBox").html(msg);
        }
      }
    );

    var cnt = 1;
    $("#scrollLeft").click(
      function(){
        if(cnt >= 1)
          cnt--;
        $("#scroller")
            .animate({ scrollLeft: $("#scroller").scrollLeft() - 200}, "bounceout");
      }       
    );

    $("#scrollRight").click(
      function(){
        if(cnt <= 13)
          cnt++;
        $("#scroller")
            .animate({ scrollLeft: $("#scroller").scrollLeft() + 200}, "bounceout");
      }       
    );

    $(".studentBox").click(
      function(){
        var id = this.id;
        var showDiv = "#studentSubBox" + id;
        if($(showDiv).is(':hidden')){
          $(showDiv).slideDown("slow");
        }else{
        $(showDiv).slideUp("slow");
        }
      }       
    );

    $(".hideStudentDetails").click(
      function(){
        var id = this.id;
        var showDiv = "#studentSubBox" + id;
        $(showDiv).slideUp("slow");
      }       
    );    
    
    $("#studentRegistration").click(function(){
      $("#teacherRegister").hide();
      $("#studentRegister").slideDown("slow");
    });
        
    $("#teacherRegistration").click(function(){
      $("#studentRegister").hide();
      $("#teacherRegister").slideDown("slow");
    }); 
    
    $(".aLink").hover(
      function(){
        $(this).css("color","#fd8e00");
        $(this).css("text-decoration","bolder");
        $(this).css("font-size","12px");
      }, 
      function(){
        $(this).css("color","#ee3503");
        $(this).css("text-decoration","bold");
        $(this).css("font-size","12px");
      }
    );
 
      
  }
);

