﻿var flag=false;
var shift_x;
var shift_y;
var current=getClientWidth()/2 + 150;
var coefficient=2;
var dragable;


function mail(){
	document.getElementById('submailform').style.display='block';
	document.getElementById('mailform').style.display='block';
	document.getElementById('cont').disabled=true;
	}


function unmail(){
	document.getElementById('submailform').style.display='none';
	document.getElementById('mailform').style.display='none';
	document.getElementById('cont').disabled=false;
	}


function checkKeys(e){
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch(KeyID){
		case 27:
			unmail();
			break;
		}
	}


function getClientWidth(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	}


function start_drag(itemToMove,e){
	if(!e) e = window.event;
	flag=true;
	shift_x = e.clientX-parseInt(itemToMove.style.left);
	shift_y = e.clientY-parseInt(itemToMove.style.top);
	
	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	if(e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	dragable=true;
	}

function end_drag(){
	flag=false;
	dragable=false;
	}

function dragIt(itemToMove,e){
	if (dragable){
		if (!flag) return;
		current=e.clientX-shift_x + 150;
		coefficient=getClientWidth()/current;
		if (!e) e = window.event;
		itemToMove.style.left = (e.clientX-shift_x) + "px";
		itemToMove.style.top = (e.clientY-shift_y) + "px";
		if(e.stopPropagation) e.stopPropagation();
		else e.cancelBubble = true;
		if(e.preventDefault) e.preventDefault();
		else e.returnValue = false;
		}
	}


function ini(){
	document.getElementById("submailform").style.left = (getClientWidth()/2)-150+'px';
	document.getElementById("mailform").style.left = (getClientWidth()/2)-150+'px';
	current=getClientWidth()/2 + 150;
	coefficient=2;
	window.onresize = resize;
	Image0= new Image();
	Image0.src= "http://tsekhan.com/images/close.png";
	Image1= new Image();
	Image1.src= "http://tsekhan.com/images/close_light.png";
	Image2= new Image();
	Image2.src= "http://tsekhan.com/images/close_down.png";
	Image3= new Image();
	Image3.src= "http://tsekhan.com/images/mailwindow.png";
	document.onkeyup = checkKeys;
	}


function resize(){
	current = getClientWidth()/coefficient;
	document.getElementById("submailform").style.left = current - 150 + 'px';
	document.getElementById("mailform").style.left = current - 150 + 'px';
	}