﻿/****************************************************************
(C) 2008 Kishore Nallan for DesignShack
http://www.kishorelive.com
kishore.nc@gmail.com
*****************************************************************/

var keyboardOn = false;
var shifton = false;
	
// toggles the keyboard to show or hide when link is clicked
$("#showkeyboard").click(function() {
		/*var direction = $('#word').attr('dir');
		if(direction == 'ltr' || direction == '')
			$('#word').attr('dir', 'rtl');
		else
			$('#word').attr('dir', 'ltr');*/
});

function toggleKeyboard ()
{
	keyboardOn = !keyboardOn;
	var focus, img;
	if(keyboardOn)
	{
		focus = "";
		img = "keyboard-icon-act.png";
	}
	else
	{
		focus = focusNow;
		img = "keyboard-icon.png";
	}
	document.getElementById('word').onfocus = focus;	
	document.getElementById('keyboard-icon').src = '/img/keyboard/arabic/'+img;
	$('#arabicKeyboard').slideToggle('slow');

}

// 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();
		}
	}
 }

$(document).ready(function() {
	// function thats called when any of the keys on the keyboard are pressed
	$("#arabicKeyboard input").bind("click", function(e) {
									   
		if ($(this).attr('name') == 'backspace') 
		{
			$('#word').replaceSelection("", true);
		}	
		else if ($(this).attr('name') == 'spacebar')
		{
			$('#word').replaceSelection(" ", true);
		}
		else if ($(this).val() == "Shift" ) 
		{
			if(shifton == false) 
			{
				onShift(1);	
				shifton = true;
			}
			else 
			{
				onShift(0);
				shifton = false;
			} 
		}
		else 
		{
			$('#word').replaceSelection($.trim($(this).val()), true);

			if(shifton == true) 
			{
				onShift(0);
				shifton = false;
			}
		}
	});
});
