/****************************************************************
(C) 2008 Kishore Nallan for DesignShack
http://www.kishorelive.com
kishore.nc@gmail.com
*****************************************************************/



$(document).ready(function(){
    
    	
        
        
$("#close").click(function(){
	$('#keyboard').toggle();
});

	var shifton = false;
	var pole = 0;
	
	// toggles the keyboard to show or hide when link is clicked
	
	
	$("#showkeyboard").click(function(e) {
		var height = $('#keyboard').height();
		var width = $('#keyboard').width();
    pole = 'nazwisko';
		leftVal=e.pageX+0+"px";
		topVal=e.pageY-40+"px";
		$('#keyboard').css({left:leftVal,top:topVal}).slideToggle(300);
	});
	
	$("#showkeyboard2").click(function(e) {
		var height = $('#keyboard').height();
		var width = $('#keyboard').width();
    pole = 'naz';
		leftVal=e.pageX+0+"px";
		topVal=e.pageY-40+"px";
		$('#keyboard').css({left:leftVal,top:topVal}).slideToggle(300);
	});
	
	$("#showkeyboard3").click(function(e) {
		var height = $('#keyboard').height();
		var width = $('#keyboard').width();
		pole = 'imie';
	  leftVal=e.pageX+0+"px";
		topVal=e.pageY-40+"px";
		$('#keyboard').css({left:leftVal,top:topVal}).slideDown(300);
	});

	
	// makes the keyboard draggable
	$("#keyboard").draggable();	
	
	// toggles between the normal and the "SHIFT keys" on the keyboard
	function onShift(e) {
		var i;
		if(e==1) {
			for(i=0;i<4;i++) {
				var rowid = "#row" + i;
				$(rowid).hide();
				$(rowid+"_shift").show();
			}
		}
		else {
			for(i=0;i<4;i++) {
				var rowid = "#row" + i;
				$(rowid).show();
				$(rowid+"_shift").hide();
			}
		}
	 }
	
	// function thats called when any of the keys on the keyboard are pressed
	$("#keyboard input").bind("click", function(e) {
									   
		if( $(this).val() == 'back' ) {
			$('#naz').replaceSelection("", true);
		}
		
		else if( $(this).val() == "Shift" ) {
			if(shifton == false) {
				onShift(1);	
				shifton = true;
			}
			
			else {
				onShift(0);
				shifton = false;
			} 
		}
		
		else {
     	if(pole == 'nazwisko'){
      $('#nazwisko').replaceSelection($(this).val(), true);
			}
			if(pole == 'naz'){
      $('#naz').replaceSelection($(this).val(), true);
			}
			if(pole == 'imie'){
			$('#imie').replaceSelection($(this).val(), true);
			}
			
			if(shifton == true) {
				onShift(0);
				shifton = false;
			}
		}
	});
	
});


