﻿// JScript File
function loadjscssfile(filename, filetype){
                             if (filetype=="js"){
                              var fileref=document.createElement('script');
                              fileref.setAttribute("type","text/javascript");
                              fileref.setAttribute("src", filename);
                             }
                             else if (filetype=="css"){ //if filename is an external CSS file
                              var fileref=document.createElement("link");
                              fileref.setAttribute("rel", "stylesheet");
                              fileref.setAttribute("type", "text/css");
                              fileref.setAttribute("href", filename);
                             }
                             if (typeof fileref!="undefined")
                              document.getElementsByTagName("head")[0].appendChild(fileref);
                            }
                
function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'>"+$(this).attr('title')+"</div>");
		var my_tooltip = $("#"+name+i);
		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.95, display:"none"}).fadeIn(200);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(200);
		});
	});
}


function hideEnglishWords() {
          $(".envocab").each(function(i){
                this.innerHTML = "show";  
          });  
}


$(document).ready(function(){
      $("table tr:nth-child(even)").addClass("striped"); 
      $("#footermainPan").hide();
	 simple_tooltip(".tt","tooltip");               	 
     
$(".toggleBtn").toggle(function(){    
    if($(this).nextAll(".LessonBlock:first").attr('display') == "none") { $(this).nextAll(".LessonBlock:first").slideDown(500);this.innerHTML = "hide";return};
    this.innerHTML = "show";
    $(this).nextAll(".LessonBlock:first").slideUp(500);
    },function(){
    if($(this).nextAll(".LessonBlock:first").attr('display') == "block") {$(this).nextAll(".LessonBlock:first").slideUp(500); this.innerHTML = "show";return};
    this.innerHTML = "hide";
   $(this).nextAll(".LessonBlock:first").slideDown(500);
    });
        
        $.fn.focusNextInputField = function() {
                    return this.each(function() {
                    var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
                    var index = fields.index( this );
                            if ( index > -1 && ( index + 1 ) < fields.length ) {
                            fields.eq( index + 1 ).focus();
                            }
                    return false;
                    });
        };


  $('.inpFragen').bind('keypress',function trapEnter(event) { 
                    var e = event ? event : window.event;
                     var key = 0;
                     if (e.keyCode) { key = e.keyCode; } else if (typeof(e.which)!= 'undefined') { key = e.which; } 
                     if(key==13) { 
                        $(this).parent().next().slideDown(500);
                         this.disabled="disabled"; 
                        $(this).focusNextInputField();
                         return false;
                         }
  });
   $('.NoClick').bind('keypress',function trapEnter(event) { 
                    var e = event ? event : window.event;
                     var key = 0;
                     if (e.keyCode) { key = e.keyCode; } else if (typeof(e.which)!= 'undefined') { key = e.which; } 
                     if(key==13) { 
                         this.disabled="disabled"; 
                        $(this).focusNextInputField();
                         return false;
                         }
  }); 
  /* $('.inpFragen').bind('blur',function () { $(this).parent().next().slideDown(500); return false; }); */
   
//  $(".toggleBtn:not(#tglmaintext)").click();
  $(".toggleBtn").click();

  
  $(".answer").addClass("LessonText").hide();	 
  
    $(".envocab").each(function(i){
        this.innerHTML = this.title;  
  });

  $("#testVocab").click(function () {
          $(".hideontest").slideUp(500);
          $(".envocab").each(function(i){
                $(this).html('show').css('text-decoration','underline').css('color','blue').bind('click',function(event) {
                    if (!event) event = window.event;
                    var target = (event.target) ? event.target : event.srcElement;
                    $(target).html(target.title).css('text-decoration','none').css('color','black');
                    });
          });  
          return false;
   });

    $(".derdiedas").change(function() 
            { 
                var box = $(this);
                var selectedAnswer = $(this).val();
                $(this).children().each(function() 
                {
                   if ($(this).html() == selectedAnswer) 
                  { 
                    if  ($(this).hasClass("optCorrect")) 
                    { box.parent().append($(this).html() + ' - <img src=\"design/images/m_check.gif \" height=\"18px\" width=\"18px\"/>  '); } 
                    else 
                    { box.parent().append($(this).html() + ' - <img src=\"design/images/m_wrong.gif \" height=\"18px\" width=\"18px\"/>  '); } 
                  }
                });       
            });  
       
    $("#CancelHover").click(function () 
    {
    $("#lessontext span").unbind().css('color','black').css('text-decoration','none').css('font-weight','normal');
    return false; 
    });        
      
});