var IE = document.all?true:false;

var shift_presed = 0;
var ctrl_presed = 0;
var f2_presed = 0;

document.onkeydown = KeyRegister; 

function KeyRegister(e){
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   if (KeyID == 16){
		shift_presed = 1;
   }
   if (KeyID == 17){
		ctrl_presed = 1;
   }
   if (KeyID == 113){
		f2_presed = 1;
   }
   checkShortcut();
   //$('test').innerHTML = KeyID;
}


document.onkeyup = KeyUnregister; 

function KeyUnregister(e){
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   if (KeyID == 16){
		shift_presed = 0;
   }
   if (KeyID == 17){
		ctrl_presed = 0;
   }
   if (KeyID == 113){
		f2_presed = 0;
   }
   checkShortcut();
}

function checkShortcut(){
	if (shift_presed == 1 && ctrl_presed == 1 && f2_presed == 1){

		shift_presed = 0;
		ctrl_presed = 0;
		f2_presed = 0;

		varPopup = window.open("", "Variables", "width=500,height=700,scrollbars=yes");
		varPopup.focus();
		varPopup.document.writeln("<h3>Variables:</h3><div id='variable_cont'></div>");
		writetoPopup(varPopup);
	}
	//$('test').innerHTML = shift_presed +';'+ ctrl_presed +';'+ f2_presed;
}


function writetoPopup (){
	if (varPopup.document != null){
		varPopup.document.getElementById('variable_cont').innerHTML = $('variables').innerHTML;
		//setTimeout("writetoPopup(varPopup)",2000);
	}
}



//cathing mouse coordinates
/*
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else { 
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}

	//loadMouse();

	return true;
}
*/

//laku img

function showLak (id){
	if ($('lak_info_cont') && $(id)){
		$('hide_prev').style.display = "none";
		$('lak_info_cont').innerHTML = $(id).innerHTML;
	}
}

//rankenu img

function showHand (id){
	document.getElementById('handle').value = id;
}


/*

function loadMouse(){
	if ($('lak_info_cont_mouse')){
		$('lak_info_cont_mouse').style.top = tempY-200 + 'px';
		$('lak_info_cont_mouse').style.left = tempX+10 + 'px';	
	}
}

function showLakMouse(id){
	if ($('lak_info_cont_mouse')){
		$('lak_info_cont_mouse').style.display = 'block';
		$('lak_info_cont_mouse').innerHTML = $(id).innerHTML;
	}	
}

function hideLakMouse (){
	$('lak_info_cont_mouse').style.display = 'none';
}

*/

// slide vertical / tb functions

mvhalt = false;
mvspeed = 25;

function moveLeft (id){
	if (!mvhalt && $(id).offsetLeft > ($('cont_width').offsetWidth - 770) * -1 ){
		$(id).style.left = ($(id).offsetLeft - mvspeed) + 'px';
		setTimeout("moveLeft('"+id+"')",10);
	}else if ($(id).offsetLeft <= ($('cont_width').offsetWidth - 770) * -1){
		$('move_right').style.display = 'none';
	}
}

function moveRight (id){
	if (!mvhalt && $(id).offsetLeft < 0){
		$(id).style.left = ($(id).offsetLeft + mvspeed) + 'px';
		setTimeout("moveRight('"+id+"')",10);
	}else if ($(id).offsetLeft >= 0){
		$('move_left').style.display = 'none';
	}
}


function startMovingLeft (id){
	$('move_right').style.display = 'block';
	mvhalt = false;
	moveRight (id);
}

function startMovingRight (id){
	$('move_left').style.display = 'block';
	$('move_right').style.background.src = '../images/arrow_right_down.png';
	mvhalt = false;
	moveLeft (id);
}

function stopMoving () {
	mvhalt = true;
}

function showControls (){
	if ($('cont_width').offsetWidth > 770){
		$('move_right').style.display = 'block';
	}
}

function swichTbView (view) {
	if (view == 1){
		createCookie('displayList',1,30);
		$('tb_list').style.display = 'none';
		$('move_left').style.display = 'none';
		$('move_right').style.display = 'none';
		$('product_tb_list').style.display = 'block';
		$('tb_tile_link_1').style.display = 'none';
		$('tb_tile_link_2').style.display = 'block';
	}else{
		createCookie('displayList',2,30);
		$('product_tb_list').style.display = 'none';
		$('tb_list').style.display = 'block';
		$('move_right').style.display = 'block';
		$('tb_list').style.left = '0px';
		$('tb_tile_link_1').style.display = 'block';
		$('tb_tile_link_2').style.display = 'none';
	}
}


/* cookies */


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/*orders page show/hide*/


function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function showRows(name){
	if (IE)
		var $rows =	getElementsByName_iefix('tr', name);
	else
		var $rows = document.getElementsByName(name);
	for (var i=0; i < $rows.length ; i++ ){
		if ($rows[i].style.display == ''){ 
			$rows[i].style.display = 'none';
			$(name+'_div').innerHTML = '>> More';
		}else{ 
			$rows[i].style.display = '';
			$(name+'_div').innerHTML = '>> Show less';
		}
	}
}

