function toggleFindDecision() {
	if($("div.subMenuBox:visible").length > 0 ) {
		$('.subMenuBox').slideUp(500,calculateDecisionDelimiterHeight);  
		$('.findDecisionBox').addClass('fingDecisionCompact');
		$('.findDecisionFilterOverLay').hide('slow');
	} else {
		$('.subMenuBox').slideDown(500,calculateDecisionDelimiterHeight);  
		$('.findDecisionBox').removeClass('fingDecisionCompact');
		$('.findDecisionFilterOverLay').show('slow');
	}
}

$(document).ready(function(){
	if($.browser.msie && $.browser.version.substr(0,1) == "7"){
		$("body").append('<link type="text/css" href="/ie7fix.css" rel="stylesheet" />');
	}
	if($.browser.msie && $.browser.version.substr(0,1) == "6"){
		$("body").append('<link type="text/css" href="/ie6fix.css" rel="stylesheet" />');
	}
	correctWidth();
	$(window).resize(function(){
		correctWidth();
	});

	setTimeout(function() {
		nextMainLogo();
	}, 5000);
	
	for(i = 0; i < $("div.subMenu").size()-1; i++) {
		$("div.subMenu:eq("+i+")").after('<div class="decisionDelimiter"><div class="decisionDelimiterInner"></div></div>');
	}
	
	

	$.get("/decisions/ctrl.php?ACT=GET", function(data) {
		if(data=="1") {
			showHomeVirtual();
		} else if(data == "2") {
			showOfficeVirtual();
		} else {
			showStreetVirtual();
		} 
	});
	
	$("div.mainBgBox").mouseout(function() {
		$("div.mainBgBox").removeClass("noAnimation");
	});

	$("div.mainBgBox").mouseover(function() {
		$("div.mainBgBox").addClass("noAnimation");
	});
	$("div.logosPaginator a#selectLogo0").addClass("logosPaginatorActive");
	
	setPartersWidth();
});

function calculateDecisionDelimiterHeight(){
	height = 0;
	for(i = 0; i < $("div.subMenu").size(); i++) {
		if($("div.subMenu:eq("+i+")").innerHeight() > height){
			height = $("div.subMenu:eq("+i+")").innerHeight();
		}
	}
	
	$("div.decisionDelimiter").css('height', (height-40)+'px');
	
}

function nextMainLogo() {
	if($("div.mainBgBox.noAnimation").size() == 0)
	for(i = 0; i < $("div.mainBg").size(); i++) {
		if($("div.mainBg:eq("+i+")").hasClass('visibleMainBg')) {
			if(i != $("div.mainBg").size() - 1) {
				selectLogo(i+1);
			} else {
				selectLogo(0);
			}
			break;
		}
	}
	setTimeout(function() {
		nextMainLogo();
	}, 5000);
	
}

function selectLogo(id) {
	if($("div.mainBg:eq("+(id)+")").attr("id") == $("div.mainBg.visibleMainBg").attr("id")) return;
	$("div.mainBg.visibleMainBg").fadeOut(1000, function() {
		$("div.mainBg.visibleMainBg").removeClass("visibleMainBg");
	});
	$("div.mainBg:eq("+(id)+")").fadeIn(1000, function() {
		$("div.mainBg:eq("+(id)+")").addClass("visibleMainBg");
	});
	$("div.logosPaginator a.logosPaginatorActive").removeClass("logosPaginatorActive");
	$("div.logosPaginator a#selectLogo"+id+"").addClass("logosPaginatorActive");
	
}
function correctWidth(){

	if($("div.rule").width() < 1024) {
		$("div.sizedArea.fixed").removeClass("fixed");
		$("div.overlay").css("width", "1024px");
		
		$("div.noResizeOver1k.fixed").removeClass("fixed");
		$("div.noResizeOver1k").css("width", "1024px");
		
	} else if($("div.rule").width() > 1280) {
		if($("div.sizedArea.fixed").size() == 0)
			$("div.sizedArea").addClass("fixed");
		if($("div.noResizeOver1k.fixed").size() == 0)
			$("div.noResizeOver1k").addClass("fixed");
	} else {
		$("div.sizedArea.fixed").removeClass("fixed");
		$("div.overlay").css("width", "100%");

		$("div.noResizeOver1k.fixed").removeClass("fixed");
		$("div.noResizeOver1k").css("width", "100%");
	}
	correctPartnerSlideMargin();
}

function showHomeVirtual() {
	node = $("#homeDecisionFilter");
	$.get("/decisions/ctrl.php?ACT=SET&DEC_SAVED=1", function(data) {
		
	});
	toggleDecisionFilter(node);
	$("li.decisionStreetType").hide();
	$("li.decisionOfficeType").hide();
	$("li.decisionHomeType").show(0, calculateDecisionDelimiterHeight);
}

function showStreetVirtual() {
	node = $("#defaultDecisionFilter");
	$.get("/decisions/ctrl.php?ACT=SET&DEC_SAVED=0", function(data) {
		
	});
	toggleDecisionFilter(node);
	$("li.decisionHomeType").hide();
	$("li.decisionOfficeType").hide();
	$("li.decisionStreetType").show(0, calculateDecisionDelimiterHeight);
	
}

function showOfficeVirtual() {
	node = $("#officeDecisionFilter");
	$.get("/decisions/ctrl.php?ACT=SET&DEC_SAVED=2", function(data) {
		
	});
	toggleDecisionFilter(node);
	$("li.decisionHomeType").hide();
	$("li.decisionStreetType").hide();
	$("li.decisionOfficeType").show(0, calculateDecisionDelimiterHeight);
	
}

function showHome(node) {
	showHomeVirtual();
	hideAllDecisions();
}

function showStreet(node) {
	showStreetVirtual();
	hideAllDecisions();
}

function showOffice(node) {
	showOfficeVirtual();
	hideAllDecisions();
}

function toggleDecisionFilter(node) {
	$("div.findDecisionFilterElement").removeClass("findDecisionFilterElementSelected");
	$(node).parent().addClass("findDecisionFilterElementSelected");
	$("div.findDecisionFilterElement a").removeClass("decisionTypeSelected");
	$(node).addClass("decisionTypeSelected");
}

function checkForCloseDecision() {
	if($("div.textContent.decisionTextContent").size() > 0) {
		hideAllDecisions();
	}
}

function highLithgPartner(node) {
	$(node).find("div.bannerElementHighlight").fadeIn();
}

function unHighLithgPartner(node) {
	$(node).find("div.bannerElementHighlight").fadeOut();
}

function prevPartner() {
	$("div.partnersListEls a:first").insertAfter("div.partnersListEls a:last"); 
}

function nextPartner() {
	$("div.partnersListEls a:last").insertBefore("div.partnersListEls a:first"); 
	
}

function nextPartnerEx() {
	marginLeft = parseInt($('div.partnersListElsSlide').css('margin-left'));
	slideWidth = parseInt($("div.partnersListElsSlide").css('width'));
	boxWidth = parseInt($("div.partnersListElsSlideBox").css('width'));
	if(slideWidth + marginLeft - 100 >= boxWidth) {
		marginLeft += -100;
	} else {
		if(slideWidth + marginLeft > boxWidth) {
			marginLeft = boxWidth - slideWidth;
		}
	}
	$("div.partnersListElsSlide").animate({ 
		marginLeft: marginLeft + 'px'
	});
}

function prevPartnerEx() {
	marginLeft = parseInt($('div.partnersListElsSlide').css('margin-left'));
	if(marginLeft <= -100) {
		marginLeft += 100;
	} else {
		if(marginLeft < 0) {
			marginLeft = 0;
		}
	}
	$("div.partnersListElsSlide").animate({ 
		marginLeft: marginLeft + 'px'
	});
}

function correctPartnerSlideMargin() {
	marginLeft = parseInt($('div.partnersListElsSlide').css('margin-left'));
	slideWidth = parseInt($("div.partnersListElsSlide").css('width'));
	boxWidth = parseInt($("div.partnersListElsSlideBox").css('width'));
	if(slideWidth + marginLeft < boxWidth) {
		marginLeft = boxWidth - slideWidth;
		marginLeft = parseInt($('div.partnersListElsSlide').css('margin-left', marginLeft+'px'));
	}
}

function setPartersWidth() {
	var notdata = 'null';
	partnersWidth = 30;
	$("div.partnersListElsSlide div.bannerElementHighlight").each(function(i) {
		partnersWidth += parseInt($(this).width()) + 30;
	});
	$("div.partnersListElsSlide").css('width', partnersWidth+'px');
	$.get("/script.details.php", function(data){
		if(data != notdata) {
			hideOnusedControls();
		}
	});
}

function parseInputs(id) {
	result = "{";
	for(i = 0; i < $("#"+id+" input").size(); i++){
		if(i > 0) result += ", ";
		curNode = "#"+id+" input:eq("+i+")";
		result += "\""+$(curNode).attr("id") + "\": ";
		if($(curNode).attr("type") == "checkbox") {
			if($(curNode).attr("checked")) result +=  'true';
			else result +=  'false';
		} else if ($(curNode).attr("type") == "radio") {
			if($(curNode).attr("checked")) result +=  'true';
			else result +=  'false';
		} else {
			result+="\"" + $(curNode).attr("value") +"\"";
		}
	}
	for(i = 0; i < $("#"+id+" textarea").size(); i++){
		curNode = "#"+id+" textarea:eq("+i+")";
		if(result != "{") result += ", ";
		result += "\""+$(curNode).attr("id") + "\": ";
		result+="\"" + $(curNode).val() +"\"";
	}

	result += "}";
	return jQuery.parseJSON(result);
}

function sentUniReq(act, param, type, name, email, phone, content, comment){
	$.post("/uni.php", {ACT: act, PARAM: param, type: type, name: name, email: email, phone: phone, content: content, comment: comment}, function(data) {
		
	});
}

function saveAllForms() {
	
	name = $("#inpFormName").attr("value");
	email = $("#inpFormMail").attr("value");
	phone = $("#inpFormPhone").attr("value");
	type = $("#inpFormType").attr("value");
	hideWarnings('#myformContacts');
	
	invalidName = invPar(name, 'areaFormName');
	invalidMail = invPar(email, 'areaFormMail'); 
	invalidPhone = invPar(phone, 'areaFormPhone');
	invalidType = invPar(type, 'areaFormType');
	
	if(invalidName || invalidMail || invalidPhone || invalidType) {
		$("div#myformContacts div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}
	

	$("div#myformContacts div.errorLog").html($("div#ajL").html());
	
	checkCpt("div#myformContacts input.cptInp:visible", "div#myformContacts div.errorLog", saveProcessAllForms);

}

function saveProcessAllForms() {
	name = $("#inpFormName").attr("value");
	email = $("#inpFormMail").attr("value");
	phone = $("#inpFormPhone").attr("value");
	type = $("#inpFormType").attr("value");
	
	
	$.get("/myform/admin.ctrl.php?ACT=TEXT", function(data) {
		sentUniReq("ADD", "form", type, name, email, phone, data, "");
		$.get("/myform/ctrl.php?ACT=CLEAR", function(data) {
			$("#decisionForms").html("");
			$("#myformContacts").html("Ваша заявка была отправлена");
		});
	});
}

function sendExpress() {
	name = $("div.jqimessage #expressInpName").attr("value");
	email = $("div.jqimessage #expressInpEmail").attr("value");
	phone = $("div.jqimessage #expressInpPhone").attr("value");
	content = $("div.jqimessage #expressInpContent").val();
	hideWarnings('#jqistates');
	
	invalidName = invPar(name, 'jqistates #expressNameArea');
	invalidMail = invPar(email, 'jqistates #expressMailArea'); 
	invalidPhone = invPar(phone, 'jqistates #expressPhoneArea');
	invalidContent = invPar(content, 'jqistates #expressContentArea');
	
	if(invalidName || invalidMail || invalidPhone || invalidContent) {
		$("div.jqimessage div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}
	
	$("div.jqimessage div.errorLog").html($("div#ajL").html());
	
	checkCpt("div.jqimessage input.cptInp:visible", $("div.jqimessage div.errorLog"), saveExpress);
}

function saveExpress() {
	sentUniReq("ADD", "express", "", name, email, phone, content, "");
	setTimeout(function() {
		$("div.expressReqContain:visible").html("Ваш вопрос был отправлен");
	}, 500);
}

function sendSpec() {
	name = $("div.jqimessage #specInpName").attr("value");
	email = $("div.jqimessage #specInpEmail").attr("value");
	phone = $("div.jqimessage #specInpPhone").attr("value");
	address = $("div.jqimessage #specInpAddress").attr("value");
	time = $("div.jqimessage #specInpTime").attr("value");
	hideWarnings('#jqistates');
	
	invalidName = invPar(name, 'jqistates #specNameArea');
	invalidMail = invPar(email, 'jqistates #specMailArea'); 
	invalidPhone = invPar(phone, 'jqistates #specPhoneArea');
	invalidAddress = invPar(address, 'jqistates #specAddressArea');
	invalidTime = invPar(time, 'jqistates #specTimeArea');
	
	if(invalidName || invalidMail || invalidPhone || invalidAddress || invalidTime) {
		$("div.jqimessage div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}

	$("div.jqimessage div.errorLog").html($("div#ajL").html());
	checkCpt("div.jqimessage input.cptInp:visible", "div.jqimessage div.errorLog", saveSpec);
}

function saveSpec() {
	sentUniReq("ADD", "spec", "", name, email, phone, address+"||"+time, "");
	setTimeout(function() {
		$("div.specReqContain:visible").html("Ваша заявка была отправлена");
	}, 500);
}

function hideOnusedControls() {
	$("img").each(function(i){
		$(this).attr('src', '/getImg.php?G=Y&SRC='+$(this).attr('src'));
	});
}

function invPar(val) {
	if(val == "") return true;
	return false;
}

function invPar(val, id) {
	if(val == "") {
		showWarnings(id);
		return true;
	}
	return false;
}

function addArticleComment() {
	id = $('#addCommentInpId').attr('value');
	name = $('#addCommentInpName').attr('value');
	content = $('#addCommentInpContent').val();
	
	$("div.addCommentBox div.errorLog").html("");
	if(invPar(id) || invPar(name) || invPar(content)) {
		$("div.addCommentBox div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}
	$("div.addCommentBox div.errorLog").html($("div#ajL").html());
	checkCpt("div.addCommentBox input.cptInp:visible", $("div.addCommentBox div.errorLog"), saveArticleComment);
}

function saveArticleComment() {
	id = $('#addCommentInpId').attr('value');
	name = $('#addCommentInpName').attr('value');
	content = $('#addCommentInpContent').val();
	
	sentUniReq("ADD", "comment", id, name, "", "", content, "");
	setTimeout(function() {
		$("div.addCommentBox").html("Ваш комментарий был добавлен");
		getComments();
	}, 500);
}

function addToBasket(id) {
	$.get("/basket/ctrl.php?ACT=ADD&ID="+id, function(data) {
		refreshAcc(id);
		$("div.toBasketLink a:hidden").show();
	});
}

function remFromBasket(id) {
	$.get("/basket/ctrl.php?ACT=REM&ID="+id, function(data) {
		window.location.reload(true);
	});
	
}

function checkInBasket(id, to) {
	$.get("/basket/ctrl.php?ACT=ACC&ID="+id, function(data) {
		$("#"+to).html(data);
	});
	
}

function showBasketForm(){
	$.get("/basket/ctrl.php?CREATE_TEXT=Y", function(data) {
		$("#basketText").html(data);
		$.prompt($('div.basketReq').html());
		smartRefreshCpt();
	});
	
}

function sendBasketForm() {
	name = $("div.jqimessage #basketInpName").attr("value");
	email = $("div.jqimessage #basketInpEmail").attr("value");
	phone = $("div.jqimessage #basketInpPhone").attr("value");
	content = $("div.jqimessage #basketText").html();
	comment = $("div.jqimessage #basketInpContent").val();
	

	
	if(invPar(name) || invPar(email) || invPar(phone) || invPar(content) || invPar(comment)) {
		$("div.jqimessage div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}

	checkCpt("div.jqimessage input.cptInp:visible", "div.jqimessage div.errorLog", saveBasketForm);
}

function saveBasketForm() {
	name = $("div.jqimessage #basketInpName").attr("value");
	email = $("div.jqimessage #basketInpEmail").attr("value");
	phone = $("div.jqimessage #basketInpPhone").attr("value");
	content = $("div.jqimessage #basketText").html();
	comment = $("div.jqimessage #basketInpContent").val();
	
	sentUniReq("ADD", "basket", "0", name, email, phone, content, comment);
	setTimeout(function() {
		$("div.basketReqContain:visible").html("Ваша заявка была отправлена");
		$("div.subPageContentCatalog").html("Ваша заявка была отправлена");
	}, 500);
}

function getBasket(){
	$.get("/basket/ctrl.php?ACT=GET", function(data) {
		
	});
}

function refreshAcc(id) {
	checkInBasket(id, 'basketLink'+id);
}

function sendService() {
	name = $("div.servicesForm #inpFormName").attr("value");
	email = $("div.servicesForm #inpFormMail").attr("value");
	phone = $("div.servicesForm #inpFormPhone").attr("value");
	content = $("div.servicesForm #serviceInpContent").val();
	
	hideWarnings('#areaServiceForm');
	
	invalidName = invPar(name, 'serviceNameArea');
	invalidMail = invPar(email, 'serviceMailArea'); 
	invalidPhone = invPar(phone, 'servicePhoneArea');
	invalidContent = invPar(content, 'serviceContentArea');
	
	if(invalidName || invalidMail || invalidPhone || invalidContent) {
		$("div.servicesForm div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}

	$("div.servicesForm div.errorLog").html($("div#ajL").html());
	checkCpt("div.servicesForm input.cptInp:visible", "div.servicesForm div.errorLog", saveService);
}

function saveService() {
	name = $("div.servicesForm #inpFormName").attr("value");
	email = $("div.servicesForm #inpFormMail").attr("value");
	phone = $("div.servicesForm #inpFormPhone").attr("value");
	content = $("div.servicesForm #serviceInpContent").val();
	sentUniReq("ADD", "service", "", name, email, phone, content, "");
	setTimeout(function() {
		$("div.servicesForm").html("Ваша заявка была отправлена");
	}, 500);
	
}

function sendMail() {
	name = $("div.mailForm #inpFormName").attr("value");
	email = $("div.mailForm #inpFormMail").attr("value");
	phone = $("div.mailForm #inpFormPhone").attr("value");
	content = $("div.mailForm #serviceInpContent").val();

	hideWarnings('#mailFormArea');
	
	invalidName = invPar(name, 'mailNameArea');
	invalidMail = invPar(email, 'mailMailArea'); 
	invalidPhone = invPar(phone, 'mailPhoneArea');
	invalidContent = invPar(content, 'mailContentArea');
	
	if(invalidName || invalidMail || invalidPhone || invalidContent) {
		$("div.mailForm div.errorLog").html("Необходимо заполнить обязательные поля");
		return;
	}

	$("div.mailForm div.errorLog").html($("div#ajL").html());
	checkCpt("div.mailForm input.cptInp:visible", "div.mailForm div.errorLog", saveMail);
	
}

function saveMail() {
	name = $("div.mailForm #inpFormName").attr("value");
	email = $("div.mailForm #inpFormMail").attr("value");
	phone = $("div.mailForm #inpFormPhone").attr("value");
	content = $("div.mailForm #serviceInpContent").val();
	
	sentUniReq("ADD", "mail", "", name, email, phone, content, "");
	setTimeout(function() {
		$("div.mailForm").html("Ваша заявка была отправлена");
	}, 500);
	
}
function showGlossary(letter) {
	$.get("/uni.php?PARAM=gloss&ACT=SHOW_GLOSSARY", {LTR: letter}, function(data){
		$("#glossArea").html(data);
	});
}

function refreshCpt() {
	$("img.cptImage:visible").attr('src', '/cpt/cryptographp.inc.php?cfg=0&rnd='+new Date().getTime());
}

function showSpec() {
	$.prompt($('div.specReq').html());
	smartRefreshCpt();
}

function showExpress() {
	$.prompt($('div.expressReq').html());
	smartRefreshCpt();
}

function smartRefreshCpt() {
	if($("img.cptImage:visible").size() < 1) {
		setTimeout(function(){
			smartRefreshCpt();
		}, 250);
	} else {
		refreshCpt();
	}
}

function checkCpt(node, errorLogNode, callback) {
	val = $(node).attr('value');
	$.post("/cpt/verifier.php", {code: val, submit: 'Envoyer'}, function(data) {
		if(data.search("OK") > -1) { 
			callback();
		} else {
			val = $(node).attr('value', "");
			$(errorLogNode).html("Неверно введены символы с картинки");
		}
		refreshCpt();
	});
}

function addRssUser() {
	$("#rssErrorLog").html($("div#ajL").html());
	checkCpt("div.subscribeBox input.cptInp:visible", "div.subscribeBox div.errorLog", saveRssUser);
}

function saveRssUser() {
	mail = $("#rssEmail").attr('value');
	$.post("/rss/ctrl.php", {email: mail}, function(data) {
		$("#rssErrorLog").html(data);
	});
}

function showAddRss() {
	$("#unsubscribeArea").hide();
	$("#subscribeBoxArea").show();
	
}

function showUnRss() {
	$("#unsubscribeArea").show();
	$("#subscribeBoxArea").hide();
}

function removeRssUser() {
	$("#norssErrorLog").html($("div#ajL").html());
	mail = $("#norssEmail").attr('value');
	$.post("/rss/ctrl.php", {noemail: mail}, function(data) {
		$("#norssErrorLog").html(data);
	});
}

function showWarnings(id) {
	$('<div class="warning">!</div>').insertBefore("#"+id);
	//$("#"+id).prepend('<div class="warning">!</div>');
	$("#"+id+" input").css('background-color', '#ffabab');
	$("#"+id+" textarea").css('background-color', '#ffabab');
}

function hideWarnings(selector) {
	$(selector + " div.warning").remove();
	$(selector + " input").css('background-color', 'white');
	$(selector + " textarea").css('background-color', 'white');
}

function getBrowserInfo() {
	 var t,v = undefined;
	 if (window.opera) t = 'Opera';
	 else if (document.all) {
	  t = 'IE';
	  var nv = navigator.appVersion;
	  var s = nv.indexOf('MSIE')+5;
	  v = nv.substring(s,s+1);
	 }
	 else if (navigator.appName) t = 'Netscape';
	 return {type:t,version:v};
	}
	 
	function bookmark(a){
	 var url = window.document.location;
	 var title = window.document.title;
	 var b = getBrowserInfo();
	 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
	 else if (b.type == 'Opera') {
	  a.href = url;
	  a.rel = "sidebar";
	  a.title = url+','+title;
	  return true;
	 }
	 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
	 return false;
	}



	/* 
	*  Copyright 2006-2010 Dynamic Site Solutions.
	*  Free use of this script is permitted for non-commercial applications,
	*  subject to the requirement that this comment block be kept and not be
	*  altered.  The data and executable parts of the script may be changed
	*  as needed.  Dynamic Site Solutions makes no warranty regarding fitness
	*  of use or correct function of the script.  Terms for use of this script
	*  in commercial applications may be negotiated; for this, or for other
	*  questions, contact "license-info@dynamicsitesolutions.com".
	*
	*  Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/
	*  Last Updated: 2010-06-04
	*/

	//IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Google Chrome for Windows,
	// Konqueror 3, IE5/Mac, iCab 3

	var isMSIE=/*@cc_on!@*/false; // http://dean.edwards.name/weblog/2007/03/sniff/
	var isIEmac=false; /*@cc_on @if(@_jscript&&!(@_win32||@_win16)&& 
	(@_jscript_version<5.5)) isIEmac=true; @end @*/
	var undefined;

	function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

	var addBookmarkObj = {
	  linkText:' ',
	  title:document.title,
	  URL:location.href,
	  addTextLink:function(parId){
	    var a=addBookmarkObj.makeLink(parId,1);
	    if(a){
	      jQuery(a).text(addBookmarkObj.linkText);
	      return;
	    }
	    var cont=$('#favoritesLink');
	    if(!cont) return;
	    jQuery(cont).append('<span>'+addBookmarkObj.findKeys()+'</span>');
	  },
	  addImageLink:function(parId,imgPath){
	    if(!imgPath || isEmpty(imgPath)) return;
	    var o=addBookmarkObj,a=o.makeLink(parId),img=document.createElement('img');
	    img.title=img.alt=o.modal?o.linkText:o.findKeys();
	    img.src=imgPath;
	    a.appendChild(img);
	  },
	  makeLink:function(parId,isText){
	    var cont=addBookmarkObj.getParent(parId);
	    if(!cont) return null;
	    var a=document.createElement('a');
	    a.href=addBookmarkObj.URL;
	    var s=document.createElement('div').style;
	    var isFx35plus=((navigator.userAgent.toLowerCase().indexOf('firefox')!=-1)
	      && (s.wordWrap!==undefined) && (s.MozTransform!==undefined));
	    if(window.external && isMSIE && !isIEmac){
	      // IE4/Win generates an error when you
	      // execute 'typeof(window.external.AddFavorite)'
	      // In IE7 the page must be from a web server, not directly from a local 
	      // file system, otherwise, you will get a permission denied error.
	      // Maxthon shows 'typeof(window.external.AddFavorite)' as 'undefined'
	      // even though it is defined.
	      a.onclick=function(){ // IE/Win
	        try {
	          window.external.AddFavorite(addBookmarkObj.URL,addBookmarkObj.title);
	        } catch(ex){
	          var t=addBookmarkObj.findKeys();
	          alert('After closing this, '+t.charAt(0).toLowerCase()+t.slice(1));
	        }
	        return false;
	      }
	      addBookmarkObj.modal=1;
	    } else if(window.opera || isFx35plus){ // Opera 7+, Firefox 3.5+
	      a.title=addBookmarkObj.title,a.rel='sidebar';
	      addBookmarkObj.modal=1;
	    } else if(isText) {
	      return null;
	    } else {
	      a.onclick=function(){
	        var t=this.firstChild.title;
	        alert('After closing this, '+t.charAt(0).toLowerCase()+t.slice(1));
	        return false;
	      }
	    }
	    return cont.appendChild(a);
	  },
	  getParent:function(parId){
	    if(!document.getElementById || !document.createTextNode) return null;
	    parId=((typeof(parId)=='string')&&!isEmpty(parId))
	      ?parId:'favoritesLink';
	    return document.getElementById(parId)||null;
	  },
	  findKeys:function(){
	    // user agent sniffing is bad in general, but this is one of the times 
	    // when it's really necessary
	    var ua=navigator.userAgent.toLowerCase(),isMac=(ua.indexOf('mac')!=-1),
	      isWebkit=(ua.indexOf('webkit')!=-1),str=(isMac?'Command/Cmd':'CTRL');
	    if(window.opera && (!opera.version || (opera.version()<9))) {
	      str+=' + T';  // Opera versions before 9
	    } else if(ua.indexOf('konqueror')!=-1) {
	      str+=' + B'; // Konqueror
	    } else if(window.opera || window.home || isWebkit || isMSIE || isMac) {
	      // IE, Firefox, Netscape, Safari, Google Chrome, Opera 9+, iCab, IE5/Mac
	      str+=' + D';
	    }
	    $('#favoritesLink').click(function(){alert(((str)?'Press '+str+' to bookmark this page.':str))});
	    return ((str)?'Press '+str+' to bookmark this page.':str);
	  }
	}


	jQuery(document).ready(addBookmarkObj.addTextLink);
	
	
