﻿var instructor = '';
var sourceAjax = 0;
var positionOnce = 0;
function enableClick(fromAjax) {// 0 or 1 if 1 we want this to only fire once because this call has been placed on the onmouseover event.
    //if (sourceAjax == 1) { return; }

    for (var i = 0; i < $(".viewinstructor").not(".gadded").length; i++) {
        $(".viewinstructor").not(".gadded").addClass("gadded");
            $(".viewinstructor").click(function(event) { 
                if ($("#instructorcontainer").length == 0) {
                    $("body").append(instructorctr);

                }
                if ($("#instructorcontainer").css("display") == "none") {
                    instructor = $(this).attr("instructor")
                    $("#instructorcontainer").fadeIn('slow', loadInstructor);

                    // fadedbg();
                    /* $("#closevid").click(function() {
                    hideVideo();
                    }).mouseover(function() { $(this).css("cursor", "pointer"); });*/
                } else {
                    //clearInstructor();
                    instructor = $(this).attr("instructor")
                    $("#instructorcontainer").fadeOut('fast', loadInstructor).empty();
                    //loadInstructor(); 
                }
                event.preventDefault();

            });
            if (fromAjax == 1 && sourceAjax == 0) { sourceAjax = 1; }
     }
      
    
}

$(document).ready(function() { 
    enableClick(); 
    $(window).resize(function(event) {
    if (positionOnce == 1) { placedivXOnly(); return; }   
        if ($("#instructorcontainer").css("display") == "block") { placediv(); }
    }).scroll(function(event) {
    if (positionOnce == 1) { placedivXOnly(); return; }   
        if ($("#instructorcontainer").css("display") == "block") { placediv(); }
    });

});

function placediv() {
               
         var top =  100+ $(window).scrollTop();
         var left = (($(window).width() / 2) - 320) + $(window).scrollLeft();
         $("#instructorcontainer").css("top", top + "px").css("left", left + "px");
         if (sourceAjax == 1) {positionOnce = 1; }
     }

     function placedivXOnly() { 
         var left = (($(window).width() / 2) - 320) + $(window).scrollLeft();
         $("#instructorcontainer").css("left", left + "px");
       
     }
 
     function clearInstructor() { 
                 $("#instructorcontainer").fadeOut('fast').empty();  
     }

     function loadInstructor() {
         placediv()
         $("#instructorcontainer").text("Loading...").load('/canada/techdays/controls/InstructorDetail.aspx?instructor=' + instructor + '&time=' + (new Date()).getTime()).fadeIn('slow')
     }
     function closeInstructor() { 
         $("#instructorcontainer").fadeOut('fast').empty();
     }
    var instructorctr = '  <div id="instructorcontainer" style="display:none;width:660;background-color:white;position:absolute;padding:20px 20px 20px 20px;border:solid 1px black;"></div>' ;
     
 