var zingaya_img_folder = "http://www.zingaya.com/img/widget/";
var link_pos = 0;
var close_pos = 1;
var zingaya_addfunction_called = false;

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	// kill the timer
	if (_timer) clearInterval(_timer);
	// do stuff
	if (typeof (ZINGAYA_PARAMS) != 'undefined') {
		if (!zingaya_addfunction_called) {
			if (ZINGAYA_PARAMS.timeout != undefined) setTimeout(function() {addZingayaWidget(ZINGAYA_PARAMS);}, ZINGAYA_PARAMS.timeout);
			else addZingayaWidget(ZINGAYA_PARAMS);
		}
	}
}

function getUserAgent(ua) {
		// Useragent RegExp
		rwebkit = /(webkit)[ \/]([\w.]+)/;
		ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
		rmsie = /(msie) ([\w.]+)/;
		rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;
	
		ua = ua.toLowerCase();

		var match = rwebkit.exec( ua ) ||
			ropera.exec( ua ) ||
			rmsie.exec( ua ) ||
			ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
			[];

		return { browser: match[1] || "", version: match[2] || "0" };
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  if (script != null) script.onreadystatechange = function() {
    if (this.readyState == "complete") {
		if (!zingaya_addfunction_called) {
			if (typeof (ZINGAYA_PARAMS) != 'undefined') {
				if (ZINGAYA_PARAMS.timeout != undefined) setTimeout(function() {addZingayaWidget(ZINGAYA_PARAMS);}, ZINGAYA_PARAMS.timeout);
				else addZingayaWidget(ZINGAYA_PARAMS);
			}
		}
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = init;

function loadZingayaCss(css) {
	var style_str = 'z-index: 9999;'
	+ 'position: '+css.widget_position+';'
	+ 'float: left;'
	+ 'clear: both;' 
	+ 'background: #333;'
	+ 'border: solid 1px #fff;'
	//+ 'outline: solid 1px #333;'
	+ '-moz-box-shadow: 0 0 10px #000000;'
	+ '-webkit-box-shadow: 0 0 10px #000000;'
	+ 'box-shadow: 0 0 10px #000000;';
	
	if (css.background_color != undefined) style_str += 'background:'+css.background_color+';';
	if (css.border_color != undefined) style_str += 'border: solid 1px '+css.border_color+';';
	if (css.outline_color != undefined)  style_str += 'outline: solid 1px '+css.outline_color+';';
	
	ua = getUserAgent(navigator.userAgent);
	if (ua.browser == "msie") {
		if (ua.version <= 6) style_str += "//position: absolute;";
		else {
			var DOCTYPE = document.all[0].text;//gets doctype, works in ie
			if (typeof(DOCTYPE) == 'string') {
				if (DOCTYPE.toUpperCase() == '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">' || DOCTYPE.toUpperCase() == '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">') {
					style_str += "//position: absolute;";
				}
			} else style_str += "//position: absolute;";
		}
	}
	
	zingaya_widget = document.getElementById("zingaya_widget");
	zingaya_widget.style.cssText = style_str;
	
	if (css.color != undefined) color_str = 'color:'+css.color+';';
	else color_str = 'color: #aaa;';

	zingaya_widget.children[link_pos].style.cssText = 'background: url('+zingaya_img_folder+'phone_dark.png) no-repeat 5px 4px;'
	+ 'text-decoration: none;'
	+ 'font-size: 13px;'
	+ 'font-weight: bold;'
	+ 'font-family: Helvetica, Arial, sans-serif;'
	+ 'text-align: center;'
	+ 'display: block;'
	+ 'padding: 5px;'
	+ 'padding-left: 25px;'
	+ color_str
	+ 'float: left;'
	+ 'line-height: 16px;'
	+ 'height: 16px;'
	+ 'outline: none;';
	
	zingaya_widget.children[close_pos].style.cssText = 'text-indent: -9999px;'
	+ 'display: block;'
	+ 'float: left;'
	+ 'width: 12px;'
	+ 'height: 12px;'
	+ 'line-height: 12px;'
	+ 'background: url('+zingaya_img_folder+'close_button_dark.png) no-repeat;'
	+ 'margin-top: 7px;'
	+ 'margin-right: 5px;'
	+ 'outline: none;';
	
	if (typeof(css.load_dropdown_css) != 'undefined') if (css.load_dropdown_css) {
		if (ZINGAYA_PARAMS.submenu_default_css == true || ZINGAYA_PARAMS.submenu_default_css == undefined) {
			if (css.color != undefined) li_color = css.color;
			else li_color = "#AAA";
		
			var link_style = 'text-decoration: none;'
			+ 'color:'+li_color+';'
			+ 'display: block;'
			+ 'font-family: Helvetica, Arial, sans-serif;'
			+ 'font-size: 13px;'
			+ 'text-decoration: none;';
		
			dropdown = document.getElementById("zingaya_widget_dropdown");
			for(var i=0;i<dropdown.children.length;i++) {
				document.getElementById("zingaya_widget_dropdown").children[i].style.padding = "2px 0px";
				dropdown_link = document.getElementById("zingaya_widget_dropdown").children[i].children[0];
				dropdown_link.style.cssText = link_style;
			}
		}
	}
}

function dlinkMouseOver(e) {
	if (typeof(ZINGAYA_PARAMS.hover_color) != 'undefined') {
		e.style.cssText += ";color: "+ZINGAYA_PARAMS.hover_color+" !important;";
	}
    else {
		if (theme == "light") e.style.color = '#000';
		else e.style.color = '#fff';
	}
}

function dlinkMouseOut(e) {
	if (typeof(ZINGAYA_PARAMS.color) != 'undefined') li_color = ZINGAYA_PARAMS.color;
	else li_color = "#AAA";
	if (typeof(ZINGAYA_PARAMS.hover_color) != 'undefined') e.style.cssText += ";color: "+li_color+" !important;";
    else e.style.color = li_color;
}

function addZingayaWidget(params) {
	zingaya_addfunction_called = true; 
	if (ZINGAYA_PARAMS.show_widget != undefined) { // if standard widget doesn't work for company
		if (!ZINGAYA_PARAMS.show_widget) return;
	}
	ua = getUserAgent(navigator.userAgent);
	if (ZINGAYA_PARAMS.label != undefined) zingaya_label = ZINGAYA_PARAMS.label;
	else zingaya_label = "Free web call";	
	if (ZINGAYA_PARAMS.tooltip != undefined) zingaya_tooltip = ZINGAYA_PARAMS.tooltip;
	else zingaya_tooltip = "You can call us for free directly from your browser";
	widget_css = new Object();
	if (ZINGAYA_PARAMS.background_color != undefined) widget_css.background_color = ZINGAYA_PARAMS.background_color;
	if (ZINGAYA_PARAMS.border_color != undefined) widget_css.border_color = ZINGAYA_PARAMS.border_color;
	if (ZINGAYA_PARAMS.outline_color != undefined) widget_css.outline_color = ZINGAYA_PARAMS.outline_color;
	if (ZINGAYA_PARAMS.color != undefined) widget_css.color = ZINGAYA_PARAMS.color;
	if (ZINGAYA_PARAMS.hover_color != undefined) widget_css.hover_color = ZINGAYA_PARAMS.hover_color;
	if (ZINGAYA_PARAMS.widget_position != undefined) widget_css.widget_position = ZINGAYA_PARAMS.widget_position;
	else widget_css.widget_position = "fixed";
	if (typeof(ZINGAYA_PARAMS.custom_widget) == 'undefined') ZINGAYA_PARAMS.custom_widget = false;
	var zingayaFunctionName = "zingayaWebCall2";
	if (ZINGAYA_PARAMS.custom_widget) zingayaFunctionName = "zingayaWebCall";
	
	if (typeof(params.id) == "string") {
		zingaya_widget=document.createElement('div');
		zingaya_widget.id = "zingaya_widget";
		if (typeof(ZINGAYA_PARAMS.collect_usage) != 'undefined') {
			if (ZINGAYA_PARAMS.collect_usage && typeof(ZINGAYA_PARAMS.extra) == "string") zingaya_widget.innerHTML = '<a href="javascript:'+zingayaFunctionName+'(\''+params.id+'\', true, \''+ZINGAYA_PARAMS.extra+'\');" class="zingaya_main" title="'+zingaya_tooltip+'">'+zingaya_label+'</a><a href="javascript:removeZingayaWidget();" class="zingaya_close">x</a>';
			else zingaya_widget.innerHTML = '<a href="javascript:'+zingayaFunctionName+'(\''+params.id+'\', true);" class="zingaya_main" title="'+zingaya_tooltip+'">'+zingaya_label+'</a><a href="javascript:removeZingayaWidget();" class="zingaya_close">x</a>';
		}
		else {
			if (typeof(ZINGAYA_PARAMS.extra) == "string") zingaya_widget.innerHTML = '<a href="javascript:'+zingayaFunctionName+'(\''+params.id+'\', null, \''+ZINGAYA_PARAMS.extra+'\');" class="zingaya_main" title="'+zingaya_tooltip+'">'+zingaya_label+'</a><a href="javascript:removeZingayaWidget();" class="zingaya_close">x</a>';
			else zingaya_widget.innerHTML = '<a href="javascript:'+zingayaFunctionName+'(\''+params.id+'\');" class="zingaya_main" title="'+zingaya_tooltip+'">'+zingaya_label+'</a><a href="javascript:removeZingayaWidget();" class="zingaya_close">x</a>';
			
		}
		document.body.appendChild(zingaya_widget);
	}
	else if (typeof(params.id) == "object") {
		if (params.id instanceof Array) {
			zingaya_widget=document.createElement('div');
			zingaya_widget.id = "zingaya_widget";
			zingaya_widget.innerHTML = '<a href="javascript:void(0);" class="zingaya_main" title="'+zingaya_tooltip+'">'+zingaya_label+'</a><a href="javascript:removeZingayaWidget();" class="zingaya_close" title="Close">x</a>';
			document.body.appendChild(zingaya_widget);
			if (params.pos1 == "top" || params.pos1 == "left" || params.pos1 == undefined) zingaya_widget.innerHTML += '<div style="clear: both; float: none;"></div><ul id="zingaya_widget_dropdown"></ul>';
			else zingaya_widget.innerHTML = '<ul id="zingaya_widget_dropdown"></ul><div style="clear: both; float: none;"></div>'+zingaya_widget.innerHTML;
			var dropdown_style = 'display: none;'
			+ 'list-style: none;'
			+ 'padding: 0;'
			+ 'margin: 0;';
			if (ua.browser == "msie") if (ua.version <= 6) dropdown_style += 'width: auto;';
			document.getElementById("zingaya_widget_dropdown").style.cssText = dropdown_style;
			for(var i=0;i<params.id.length;i++) {
				if (typeof(ZINGAYA_PARAMS.collect_usage) != 'undefined') {
					if (ZINGAYA_PARAMS.collect_usage && typeof(ZINGAYA_PARAMS.extra) == "string") document.getElementById("zingaya_widget_dropdown").innerHTML += '<li class="zingaya_widget_li"><a href="javascript:'+zingayaFunctionName+'(\''+params.id[i].id+'\', true, \''+ZINGAYA_PARAMS.extra+'\');">'+params.id[i].label+'</a></li>';
					else document.getElementById("zingaya_widget_dropdown").innerHTML += '<li class="zingaya_widget_li"><a href="javascript:'+zingayaFunctionName+'(\''+params.id[i].id+'\', true);">'+params.id[i].label+'</a></li>';
				}
				else {
					if (typeof(ZINGAYA_PARAMS.extra) == "string") document.getElementById("zingaya_widget_dropdown").innerHTML += '<li class="zingaya_widget_li"><a href="javascript:'+zingayaFunctionName+'(\''+params.id[i].id+'\', null, \''+ZINGAYA_PARAMS.extra+'\');" onmouseover="dlinkMouseOver(this);" onmouseout="dlinkMouseOut(this);">'+params.id[i].label+'</a></li>';
					else document.getElementById("zingaya_widget_dropdown").innerHTML += '<li class="zingaya_widget_li"><a href="javascript:'+zingayaFunctionName+'(\''+params.id[i].id+'\');" onmouseover="dlinkMouseOver(this);" onmouseout="dlinkMouseOut(this);">'+params.id[i].label+'</a></li>';
				}
			}
			for(i=0;i<params.id.length;i++) {
				document.getElementById("zingaya_widget_dropdown").children[i].style.textAlign = "center";
				document.getElementById("zingaya_widget_dropdown").children[i].children[0].style.display = "block";
				document.getElementById("zingaya_widget_dropdown").children[i].children[0].style.padding = "2px 0px";
			}
			zingaya_widget.onmouseover = function () {  
		        //show its submenu  
				/*if (jQuery.browser.msie) { if (jQuery.browser.version <= 7) $('#zingaya_widget_dropdown').show(); }
	            else $('#zingaya_widget_dropdown').slideDown(100); */ 
				document.getElementById("zingaya_widget_dropdown").style.display = "block";
		    } 
		    zingaya_widget.onmouseout = function () {  
		        //hide its submenu  
				/*if (jQuery.browser.msie) { if (jQuery.browser.version <= 7) $('#zingaya_widget_dropdown').hide(); }
	            else $('#zingaya_widget_dropdown').slideUp(100); */
	          	document.getElementById("zingaya_widget_dropdown").style.display = "none";
		    }  
			if (params.pos1 != "top" && params.pos1 != "left" && params.pos1 != undefined) {
				link_pos = zingaya_widget.children.length - 2;
				close_pos = zingaya_widget.children.length - 1;
			}
			widget_css.load_dropdown_css = true;
		}
		else return; // wrong data passed
	}
	else return; // wrong data passed
	// if page is using https - load images using https
	if (window.location.protocol == 'https:') zingaya_img_folder = zingaya_img_folder.replace("http:", "https:");

	loadZingayaCss(widget_css);
	
	if (typeof(params.pos1) != 'undefined') pos1 = params.pos1;
	else pos1 = "top";
	if (typeof(params.pos2) != 'undefined') pos2 = params.pos2;
	else pos2 = "center";
	if (typeof(params.margin) != 'undefined') widget_margin = params.margin;
	else widget_margin = 0;
	if (typeof(params.theme) != 'undefined') theme = params.theme;
	else theme = "dark";
	
	img_ext = 'png';
	if (ua.browser == "msie") if (ua.version <= 6) img_ext = 'gif';
		
	if (theme == "light") {
		zingaya_widget.children[link_pos].style.background = 'url('+zingaya_img_folder+'phone_light.'+img_ext+') no-repeat 5px 4px';
		zingaya_widget.children[close_pos].style.background = 'url('+zingaya_img_folder+'close_button_light.'+img_ext+') no-repeat';
		current_color = zingaya_widget.children[link_pos].style.color;		
	} else if (theme == "dark") {
		zingaya_widget.children[link_pos].style.background = 'url('+zingaya_img_folder+'phone_dark.'+img_ext+') no-repeat 5px 4px';
		zingaya_widget.children[close_pos].style.background = 'url('+zingaya_img_folder+'close_button_dark.'+img_ext+') no-repeat';
		current_color = zingaya_widget.children[link_pos].style.color;
	}
	zingaya_widget.children[link_pos].onmouseover = function(){
		zingaya_widget.children[link_pos].style.backgroundPosition = '5px -44px';
		if (widget_css.hover_color != undefined) {
			zingaya_widget.children[link_pos].style.cssText += ";color: "+widget_css.hover_color+" !important;"; 
		}
        else {
			if (theme == "light") zingaya_widget.children[link_pos].style.color = '#000';
			else zingaya_widget.children[link_pos].style.color = '#fff';
		}
	}
	zingaya_widget.children[link_pos].onmouseout = function(){
			zingaya_widget.children[link_pos].style.backgroundPosition = '5px 4px';
			if (widget_css.hover_color != undefined) {
				zingaya_widget.children[link_pos].style.cssText += ";color: "+current_color+" !important;";
			}
	        else zingaya_widget.children[link_pos].style.color = current_color;
	}
	
	zingaya_widget.children[close_pos].onmouseover = function(){
	 	zingaya_widget.children[close_pos].style.backgroundPosition = '0px -12px';
	}
	zingaya_widget.children[close_pos].onmouseout = function(){
		zingaya_widget.children[close_pos].style.backgroundPosition = '0px 0px';
	};

 	switch (pos1) {
		default:
		case "top":
			if(ua.browser == "mozilla") zingaya_widget.style.outline = 'none';
			zingaya_widget.style.top = 0;
			switch (pos2) {
				default:
				case "center":
					zingaya_widget.style.left = '50%';
					zingaya_widget.style.marginLeft = (-parseInt(zingaya_widget.offsetWidth)/2 + widget_margin) + 'px';
				break;
				case "left":
					zingaya_widget.style.left = 0;
					zingaya_widget.style.marginLeft = widget_margin + 'px';
				break;
				case "right":
					zingaya_widget.style.right = 0;
					zingaya_widget.style.marginRight = widget_margin + 'px';
				break;
			}
			zingaya_widget.style.borderTop = 'none';
		break;
		
		case "bottom":
			if(ua.browser == "mozilla") zingaya_widget.style.outline = 'none';
			zingaya_widget.style.bottom = 0;
			switch (pos2) {
				default:
				case "center":
					zingaya_widget.style.left = '50%';
					zingaya_widget.style.marginLeft = (-parseInt(zingaya_widget.offsetWidth)/2 + widget_margin) + 'px';
				break;
				case "left":
					zingaya_widget.style.left = 0;
					zingaya_widget.style.marginLeft = widget_margin + 'px';
				break;
				case "right":
					zingaya_widget.style.right = 0;
					zingaya_widget.style.marginRight = widget_margin + 'px';
				break;
			}
			zingaya_widget.style.borderBottom = 'none';
		break;
		case "left":
			if(ua.browser == "mozilla") zingaya_widget.style.outline = 'none';
			if (ua.browser == "msie" && ua.version < 9) {
				zingaya_widget.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
				zingaya_widget.style.left = 0;
				switch (pos2) {
					default:
					case "center":
						zingaya_widget.style.top = '50%';
						zingaya_widget.style.marginTop = (-parseInt(zingaya_widget.offsetHeight)/2 + widget_margin) + 'px';
					break;
					case "top":
						zingaya_widget.style.top = 0 + widget_margin + 'px';
					break;
					case "bottom":
						zingaya_widget.style.bottom = 0 + widget_margin + 'px';
					break;
				}				
				zingaya_widget.style.borderTop =  'none';
			} else {
				zingaya_widget.style.cssText += '-webkit-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-moz-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-o-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-ms-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-moz-box-shadow: none;';				
				switch (pos2) {
					default:
					case "center":
						zingaya_widget.style.top = '50%';
						zingaya_widget.style.left = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';
						zingaya_widget.style.marginTop = -parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
					break;
					case "top":
						zingaya_widget.style.top = parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
						zingaya_widget.style.left = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';	
					break;
					case "bottom":
						zingaya_widget.style.bottom = parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
						zingaya_widget.style.left = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';
					break;
				}
				zingaya_widget.style.borderTop =  'none';
			}
		break;
		case "right":
			if(ua.browser == "mozilla") zingaya_widget.style.outline = 'none';
			if (ua.browser == "msie" && ua.version < 9) {
				var DOCTYPE = document.all[0].text;//gets doctype, works in ie
				if (typeof(DOCTYPE) == 'string' && ua.version >= 8) {
					var w = parseInt(zingaya_widget.offsetWidth);
					var h = parseInt(zingaya_widget.offsetHeight);
					zingaya_widget.style.width = w;
					zingaya_widget.style.height = w;
					zingaya_widget.children[link_pos].style.backgroundColor = widget_css.background_color;
					zingaya_widget.children[link_pos].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";
					zingaya_widget.style.marginRight = -w + h + 'px';
					zingaya_widget.children[link_pos].style.marginTop =  18 + 'px';
					zingaya_widget.children[close_pos].style.marginLeft =  -w + h - 2 + 'px';
					zingaya_widget.children[close_pos].style.marginTop = 4 + 'px';
					zingaya_widget.style.borderRight = 'none';					
				} else {					
						w = parseInt(zingaya_widget.offsetWidth);
						h = parseInt(zingaya_widget.offsetHeight);
						zingaya_widget.children[link_pos].style.backgroundColor = widget_css.background_color;
						zingaya_widget.children[link_pos].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";
						zingaya_widget.children[close_pos].style.marginLeft =  -h/2 - 4 + 'px';
						zingaya_widget.children[close_pos].style.marginTop = 4 + 'px';
						zingaya_widget.children[link_pos].style.marginTop = 16 + 'px';
						zingaya_widget.style.borderRight = 'none';					
				}				
				zingaya_widget.style.right = 0;
				switch (pos2) {
					default:
					case "center":
						zingaya_widget.style.top = '50%';
						zingaya_widget.style.marginTop = -parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
					break;
					case "top":
						zingaya_widget.style.top = 0 + widget_margin + 'px';
					break;
					case "bottom":
						zingaya_widget.style.bottom = 0 + widget_margin + 'px';
					break;
				}
			} else {
				zingaya_widget.style.cssText += '-webkit-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-moz-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-o-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-ms-transform: rotate(-90deg);';
				zingaya_widget.style.cssText += '-moz-box-shadow: none;';				
				switch (pos2) {
					default:
					case "center":
						zingaya_widget.style.top = '50%';
						zingaya_widget.style.right = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';
						zingaya_widget.style.marginTop = -parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
					break;
					case "top":
						zingaya_widget.style.top = parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
						zingaya_widget.style.right = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';	
					break;
					case "bottom":
						zingaya_widget.style.bottom = parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2 + widget_margin + 'px';
						zingaya_widget.style.right = -(parseInt(zingaya_widget.offsetWidth)/2 - parseInt(zingaya_widget.offsetHeight)/2) + 'px';
					break;
				}
				if (ua.browser != "webkit") zingaya_widget.style.borderBottom = 'none';
			}
		break;
	}
}

function removeZingayaWidget() {
	zingaya_widget = document.getElementById("zingaya_widget");
	zingaya_widget.parentNode.removeChild(zingaya_widget);
}

function getZingayaWebCallLink(id, collectUsage, extra) {
	var window_url = 'http://zingaya.com/widget/'+id;
	window_url += "?referrer="+escape(window.location.href);
	
	if (typeof(collectUsage) != 'undefined') {
		if (collectUsage) window_url += "&collectUsage=1";	
	} 
	if (typeof(extra) != 'undefined') {
		var values = extra.split(";");
		for (var k = 0; k < values.length; ++k) {
			var nv = values[k].split(":");
			if (nv[0]+'' == "poll" && nv[1]+'' == "true") extra += ";poll_id:"+zingayaRandomString(36);
		}
		window_url += "&extra="+escape(extra);
	}
	if(typeof(ZINGAYA_PARAMS) != 'undefined') { 
		if (typeof(ZINGAYA_PARAMS.headers) != 'undefined') {
			var sip_headers = "";
			for (i in ZINGAYA_PARAMS.headers) {
				sip_headers += i+":"+ZINGAYA_PARAMS.headers[i]+";";
			}
			window_url += "&headers="+escape(sip_headers);
		}
	}
	
	return window_url;
}

function zingayaWebCall(id, collectUsage, extra) {
	var zingaya_window =  window.open(getZingayaWebCallLink(id, collectUsage, extra),'_blank','width=236,height=220,resizable=no,toolbar=no,menubar=no,location=no,status=no');
	if (window.focus) if(zingaya_window != null) zingaya_window.focus();
}

function zingayaWebCall2(id, collectUsage, extra) {
	if (typeof(ZINGAYA_PARAMS.color) != 'undefined') clr = ZINGAYA_PARAMS.color.replace('#', '');
	else clr = 'aaaaaa';
	if (typeof(ZINGAYA_PARAMS.background_color) != 'undefined') fill_color = ZINGAYA_PARAMS.background_color.replace('#', '');
	else fill_color = '333333';
	if (typeof(ZINGAYA_PARAMS.hover_color) != 'undefined') hover_color = ZINGAYA_PARAMS.hover_color.replace('#', '');
	else hover_color = 'ffffff';
	
	var window_url = 'http://zingaya.com/widget/'+id+'?fill_color='+fill_color+
	'&text_color='+clr+
	'&hover_color='+hover_color+
	'&border_color='+fill_color;	
	
	if (typeof(collectUsage) != 'undefined') {
		if (collectUsage) window_url += "&collectUsage=1";
	}
	if (typeof(extra) != 'undefined') {
		var values = extra.split(";");
		for (var k = 0; k < values.length; ++k) {
			var nv = values[k].split(":");
			if (nv[0]+'' == "poll" && nv[1]+'' == "true") extra += ";poll_id:"+zingayaRandomString(36);
		}
		window_url += "&extra="+escape(extra);
	}
	window_url += "&referrer="+escape(window.location.href);
	if(typeof(ZINGAYA_PARAMS) != 'undefined') { 
		if (typeof(ZINGAYA_PARAMS.headers) != 'undefined') {
			var sip_headers = "";
			for (i in ZINGAYA_PARAMS.headers) {
				sip_headers += i+":"+ZINGAYA_PARAMS.headers[i]+";";
			}
			window_url += "&headers="+escape(sip_headers);
		}
	}
	
	var zingaya_window =  window.open(window_url,'_blank','width=236,height=220,resizable=no,toolbar=no,menubar=no,location=no,status=no');
	if (window.focus) if (zingaya_window != null) zingaya_window.focus();
}

function zingayaRandomString(length) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
    
    if (! length) {
        length = Math.floor(Math.random() * chars.length);
    }
    
    var str = '';
    for (var i = 0; i < length; i++) {
        str += chars[Math.floor(Math.random() * chars.length)];
    }
    return str;
}
