// Для использования необходимо назначить элементу id "click_to_call"

var phone = {
	
	init: function() {
		var div = document.createElement('div');
		var pos = document.getElementById('click_to_call').getBoundingClientRect();	
		div.id = 'popup';
		div.style.display = 'none';
		div.style.position = 'absolute';
		div.style.top = Math.round(pos.top) + 'px';
		div.style.left = Math.round(pos.left) + 'px';
		div.style.zIndex = '1001';
		div.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \
							id="red5phone" width="206" height="206" \
							codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> \
							<param name="movie" value="/flash_phone/red5phone.swf" /> \
							<param name="quality" value="high" /> \
							<param name="bgcolor" value="#869ca7" /> \
							<param name="allowScriptAccess" value="sameDomain" /> \
							<embed src="/flash_phone/red5phone.swf" quality="high" bgcolor="#869ca7" \
								width="206" height="206" name="red5phone" align="middle" \
								play="true" \
								loop="false" \
								quality="high" \
								allowScriptAccess="sameDomain" \
								type="application/x-shockwave-flash" \
								pluginspage="http://www.adobe.com/go/getflashplayer"> \
							</embed> \
						</object>';
		document.body.appendChild(div);
	},
	
	background: function() {
		var div = document.createElement('div');
		div.id = 'background';
		div.style.display = 'none';
		div.style.background = '#000';
		div.style.position = 'absolute';
		div.style.top = '0';
		div.style.left = '0';
		div.style.width = windowWidth() + 'px';
		div.style.height = windowHeight() + 'px';
		div.style.opacity = '0';
		var IE='\v'=='v'; //определяем IE
		if (IE) div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'; //делаем прозрачность для IE
		document.body.appendChild(div);
		div.onclick = function() {
			phone.show();
		}
	},
	
	show: function() {
		var popup = document.getElementById('popup');
		var background = document.getElementById('background');
		popup.style.display = (popup.style.display == 'none') ? 'block' : 'none';
		background.style.display = (background.style.display == 'none') ? 'block' : 'none';
	}
	
}

function windowWidth() {
	var de = document.documentElement;
	return self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
}

function windowHeight() {
	var de = document.documentElement;
	return self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
}

window.onload = function() {
	phone.init();
	phone.background();
	document.getElementById('click_to_call').onclick = function() {
		phone.show();
		return false;
	}
}
