//Variables
var MODAL_SPEED = 'fast';
var CREDITS_MULTIPLIER = 100000; // credit multiplier
var jsVersion = 1.0;


//Browser Detection Vars
var uagent = navigator.userAgent.toLowerCase();
var uappver = navigator.appVersion.toLowerCase();

var isIE  = (uappver.indexOf("msie") != -1) ? true : false;
var isIE6  = (uappver.indexOf("msie 6") != -1) || (uappver.indexOf("msie 5") != -1) ? true : false;
var isWin = (uappver.indexOf("win") != -1) ? true : false;

var isFirefox = (uagent.indexOf("firefox") != -1) ? true : false;
var isFirefox2 = (uagent.indexOf("firefox/2") != -1) ? true : false;
var isSymbian = (uagent.indexOf("symbianos") != -1) ? true : false;
var isKonqueror = (uagent.indexOf("konqueror") != -1) ? true : false;
var isWMobile = (uagent.indexOf("mini") != -1) || (uagent.indexOf("mobi") != -1 ) || (uappver.indexOf("phone") != -1) || (uagent.indexOf("htc") != -1) || (uappver.indexOf("mobile") != -1) ? true : false;
var isAMobile = (uagent.indexOf("iphone") != -1) || (uagent.indexOf("ipad") != -1 ) || (uappver.indexOf("ipod") != -1) ? true : false ;
var isOpera = (uagent.indexOf("opera") != -1 && !isWMobile) ? true : false;
var isFlash = swfobject.hasFlashPlayerVersion("10") && swfobject.getFlashPlayerVersion().release != 999 && !isKonqueror ? true : false ;
function isWebkit() {if(swfobject.ua.wk != false) return true;else return false;}
function isMobile() {if (isAMobile || isWMobile || isSymbian) return true;else return false;}

//Funkcja trackEvent
function track(category,action,label,value)
{
	//alert("Category:" + category +" Action:" + action +" Label:" + label);
	try{
		if(!value) pageTracker._trackEvent(category,action,label);
		else pageTracker._trackEvent(category,action,label,value);
	}
	catch(e){}
}
//GetFlashMovie
function getFlashMovie(movieName) {
	if (window.document[movieName]) 
	{
		  return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else
	{
		return document.getElementById(movieName);
	}
}


//Funkcje syntezy na Stronie głównej
function sendRecordingForm() {
    var form = document.getElementById('ivonaform');

    form.action="online/index.php";
    form.io_text.value = form.tresc.value;
    form.io_voice.value = getVoice();
    form.submit();

}

function showCharLength()
{
	var form = document.getElementById('ivonaform');
	
    return form.tresc.value.length;
}


function getShopPid(vid) {
	return voices[vid]['pid']+'_1';

}



function sendSubmit( id ) {
	obj = '#' + id;
	jQuery(obj).submit();
}
function backRedir(addr){
	window.location = addr;
	return true;
}
function goToLogin( loginURL )
{
  window.location = loginURL;
}

function ajaxCall ( hash, withHistory ) {
	withHistory=false;
	if (withHistory == undefined)
		withHistory = true;
	if (withHistory){
		jQuery.history.load(hash);
	}
	else
		jQuery.ajax( {data : hash} );
}
//Ajax Functions
function ebookDown (ebook_id, file_name){
  jQuery.ajax( {url: "/ebook.php",  data: ({ebook: ebook_id, file: file_name, add_ebook: "1"}), type: "POST", success: function(msg){
     return true;
   }});
}

function sModalConfirm(message, callback, topval){
	if( topval == undefined ) {
		topval = '15%';
	}
	jQuery('#modConfirm').modal({
			containerCss: {height: '266px', width:'542px', border:'0px', top: topval},
			overlay: (20),
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);
				// if the user clicks "yes"
				dialog.data.find('.yes').click(function () {
					// call the callback
					if (jQuery.isFunction(callback)) {
						callback.apply();
					}
					// close the dialog
					//jQuery.modal.close();
					dialog.data.fadeOut(MODAL_SPEED, function () {
						dialog.container.slideUp(MODAL_SPEED, function () {
							dialog.overlay.fadeOut(MODAL_SPEED, function () {
	  						jQuery.modal.close(); // must call this to have SimpleModal                    
							});
						});
					});
				});
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}

//
function sModalError(message, topval){
	if( topval == undefined ) {
		topval = '15%';
	}
	else if(topval == 'center'){
		topval = getCenterWindows()[1]-150;
	}
	jQuery('#modError').modal({
			containerCss: {height: '155px', width:'385px', border:'0px', top: topval},
			overlay: (20),					
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}

//
function sModalOk(message, topval){
	//alert( topval );
	if( topval == undefined ) {
		topval = '15%';
	}
	jQuery('#modOk').modal({
			containerCss: {height: '155px', width:'385px', border:'0px', top: topval},
			overlay: (20),
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});
}

function voicePopup(message){
	jQuery('#voicePopup').modal({
			containerCss: {height: '155px', width:'385px', border:'0px', top: "0px"},
			overlay: (20),
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});
}

function goBack(){
	history.go(-1);
	}

function htmlspecialchars(str) {
 if (typeof(str) == "string") {
  str = str.replace(/&/g, "&amp;"); /* must do &amp; first */
  str = str.replace(/"/g, "&quot;");
  str = str.replace(/'/g, "&#039;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  }
 return str;
 }

function dhtmlspecialchars(str) {
 if (typeof(str) == "string") {
  str = str.replace(/&gt;/ig, ">");
  str = str.replace(/&lt;/ig, "<");
  str = str.replace(/&#039;/g, "'");
  str = str.replace(/&quot;/ig, '"');
  str = str.replace(/&amp;/ig, '&'); /* must do &amp; last */
  }
 return str;
 }

function validator(string){
	if(string==undefined)
		return false;
	return true;
}

function getCenterWindows(idpopup){
	var IE = (document.all && !window.opera)?true:false;
	var tempsX = 0;
	var tempsY = 0;
	var tempoX = 0;
  var tempoY = 0;	
  var centerX = 0;
	var centerY = 0;
  
	if (IE) {
		tempoX = document.documentElement.clientWidth;
		tempoY = document.documentElement.clientHeight;
		tempsX = document.documentElement.scrollLeft;
		tempsY = document.documentElement.scrollTop;
	}
	else {
		tempoX = window.innerWidth;
		tempoY = window.innerHeight;
		tempsX = window.pageXOffset;
		tempsY = window.pageYOffset;
	}

	centerX = Math.round(tempoX/2)+tempsX-(idpopup?(Math.round(jQuery('#'+idpopup).attr("offsetWidth")/2)):0);
	centerY = Math.round(tempoY/2)+tempsY-(idpopup?(Math.round(jQuery('#'+idpopup).attr("offsetHeight")/2)):0);

	return new Array(centerX,centerY);
}


//
function makePrice(currency, price){
	if('PLN' == currency){
		return ' ' + (String(price)).replace(/\./, ",") + ' zł';
	}
	else if('EUR' == currency){
		return ' &#8364;' + price;
	}
	else{
		return ' $' + price;
	}
	return;
}
//renew php session
function promo(){
	jQuery.post("/se.php", {}, function(data){}, "text");
	setTimeout("promo()", 1200000);
}


function ib()
{
	if(document.location.href.indexOf("beta.ivona.com")!=-1)
	{
		$('#pageTop').css('background','#dd3')
	}
}
/*
REL->NOFOLLOW SAME AS TARGET->_BLANK
*/
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "nofollow" &&
       /ivona\.com/.test(anchor.getAttribute('href'))==false  
       )
     anchor.target = "_blank";
 }
}

var iManager = {
	start : function()
	{
		var f = {};
		var a = {id:"iMan",name:"iMan"};
		var p = {quality: "autohigh",swliveconnect:"true",allowscriptaccess:"always"};
		document.write("<div id=\""+"iMan"+"\"></div>");
		if (isFlash)
		{
			swfobject.embedSWF(STATIC_HOST_COM+"/flash/iManager.swf","iMan", "10", "10", "9.0.0",STATIC_HOST_COM+"/flash/expressInstall.swf", f, p, a);
		}
	},
	enc : function(l)
	{
		try{
		 	return getFlashMovie("iMan").getHash(l);
		}catch(e){
			alert(e)
		}
	}
};
$(document).ready(function(){
	externalLinks();
	ib();
	$(".accessHelp").focus(function(){$(this).css("top","55px")});
	$(".accessHelp").blur(function(){$(this).css("top","-55px")});
	$("#stNav").bind("click",function(){$("#navBegin").focus();$(this).blur()});
	$("#stContent").bind("click",function(){$("#navEnd").focus();$(this).blur()});
	
	$(".mbtn").mouseover(function(){$(".mbtn .spriteClass").hide()});
	$(".accCont").mouseover(function(){$(".accCont .spriteClass").hide()});

	
});

jQuery(function(){jQuery("ul.sf-menu").superfish({hoverClass:'sfHover',pathLevels:1,delay:1000,animation:{opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false,disableHI:true,onInit:function(){if(screen.availWidth<1330){$('#langArrow').text('ˇ');$('#langmenu .sf-vertical').removeClass('sf-vertical');$('#langSpacer').remove()}else{$("#langmenu .sf-vertical ul.rbl").css("top", "-5px")}},onBeforeShow:function(){$('.sfHover').removeClass('sfHover');$('#langmenu .sf-vertical li ul').css('left', $('#langmenu .sf-vertical').attr('offsetWidth'))}});});
function setCookie(c_name,value,expiredays, domain)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/"+((domain==null) ? "" : ";domain="+domain);
}

function eraseCookie(c_name, domain) {
	setCookie(c_name,"",-1, domain);
}

function newsletter_send( lang, configArr ) {

	
	//validate
	var emailFormat = /^[-\w](\.?[-\w])*@[-\w](\.?[-\w])*\.[a-z]{2,4}$/i;
	var email = jQuery('#' + configArr["emailModalFieldId"] ).attr('value');
	if(email==''){
		jQuery('#' + configArr["emailModalFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText1"] );
		return false;
	}										
	if( email.length < 6 || email.length > 80 || !emailFormat.test(email) ){
		jQuery('#' + configArr["emailModalFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText2"] );
		return false;
	}
	var email_confirm = jQuery('#' + configArr["emailModalConfirmFieldId"]).attr('value');
	if( email != email_confirm ){
		jQuery('#' + configArr["emailModalConfirmFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText3"] );
		return false;
	}
	
	//set crc
	var hf = 2*email.charCodeAt(3)+email.charCodeAt(1)+4*email.charCodeAt(6) - 5;
	jQuery('#' + configArr["crcFieldNameId"]).attr("value", hf );
	
	//send post
	var aData = ({p1: email, p2: hf, a:'SUBSCRIBE', l: lang, ap: configArr["newsletterSource"]});
	var aK = configArr['token1'];
	aData[aK] = configArr['token2'];

	response = jQuery.ajax({
	      url: configArr["url"],
	      global: false,
	      type: "GET",
	      data: aData,
	      dataType: "text",
	      async:false,
	      success: function(msg){
	         //alert(msg);
	      }
	}).responseText;
	
	//returns one of OK/ERR_EMAIL_EXISTS/...
	
	var oldFormValue = jQuery('#' + configArr["responseFieldId"]).html();
		
	if( response == 'OK' ) {
		newsletter_switch_box( configArr["boxOKId"], configArr );		
	} else if ( response == 'ERR_EMAIL_EXISTS' ) {
		newsletter_switch_box( configArr["boxExistsId"], configArr );
	} else if ( response == 'ERR_SESS' ) {
		newsletter_switch_box( configArr["boxSessionId"], configArr );
	} else {    
		newsletter_switch_box( configArr["boxErrorId"], configArr );
	}							
							
	return true;
}

function newsletter_switch_box( id, configArr ) {

	jQuery('#' + configArr["boxFormId"]).hide();
	jQuery('#' + configArr["boxOKId"]).hide();
	jQuery('#' + configArr["boxExistsId"]).hide();
	jQuery('#' + configArr["boxErrorId"]).hide();
	jQuery('#' + configArr["boxSessionId"]).hide();		
	jQuery('#' + id).show();
}

function newsletter_modal(configArr) {


		//calculate modalPos relative to subscribe button
		var oElement = jQuery('#' + configArr["subscribeFieldId"])[0];
		var topval = 0;
		var leftval = 0;
		while( oElement != null ) {
			topval += oElement.offsetTop;
			leftval += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
		topval =  topval-136;
		leftval = leftval-5;

		//rewrite e-mail
		var email = jQuery('#' + configArr["emailFieldId"]).attr('value');
		jQuery('#' + configArr["emailModalFieldId"]).attr('value', email);		

		//invoke modal
		jQuery('#newsletter_modal').modal({
			containerCss: {height: '60px', width:'360px', border:'0px', top: topval, left: leftval},
			overlay: (20),
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
						jQuery('#' + configArr["emailModalConfirmFieldId"]).focus();
					});
				});
			},
			onShow: function (dialog) {
				//dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});
}


function trial_send( lang, configArr ) {

	//validate
	var emailFormat = /^[-\w](\.?[-\w])*@[-\w](\.?[-\w])*\.[a-z]{2,4}$/i;
	var email = jQuery('#' + configArr["emailModalFieldId"] ).attr('value');
	if(email==''){
		jQuery('#' + configArr["emailModalFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText1"] );
		return false;
	}										
	if( email.length < 6 || email.length > 80 || !emailFormat.test(email) ){
		jQuery('#' + configArr["emailModalFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText2"] );
		return false;
	}
	var email_confirm = jQuery('#' + configArr["emailModalConfirmFieldId"]).attr('value');
	if( email != email_confirm ){
		jQuery('#' + configArr["emailModalConfirmFieldId"]).focus();
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText3"] );
		return false;
	}
	
	var mrc = jQuery("input[name=trial_modal_checkbox]:checked").length;
	if( mrc == 0 ) {
		jQuery('#' + configArr["modalErrorId"]).html( configArr["validationText4"] );
		return false;	
	}
	
	//set crc
	var hf = 3*email.charCodeAt(2)+2*email.charCodeAt(3)+4*email.charCodeAt(5) - 3;
	jQuery('#' + configArr["crcFieldNameId"]).attr("value", hf );

	//send post
	var aData = ({p1: email, p2: hf, a:'SUBSCRIBE', p3: configArr["installer"], l: lang, ap: configArr["newsletterSource"]});
	var aK = configArr['token1'];
	aData[aK] = configArr['token2'];

	response = jQuery.ajax({
	      url: configArr["url"],
	      global: false,
	      type: "GET",
	      data: aData,
	      dataType: "text",
	      async:false,
	      success: function(msg){
	         //alert(msg);
	      }
	}).responseText;

	
	//returns one of OK/ERR_EMAIL_EXISTS/...
	
	var oldFormValue = jQuery('#' + configArr["responseFieldId"]).html();
		
	if( response == 'OK' ) {
		trial_switch_box( configArr["boxOKId"], configArr );		
	} else if ( response == 'ERR_EMAIL_EXISTS' ) {
		trial_switch_box( configArr["boxExistsId"], configArr );
	} else if ( response == 'ERR_SESS' ) {
		trial_switch_box( configArr["boxSessionId"], configArr );
	} else {
		trial_switch_box( configArr["boxErrorId"], configArr );
	}							
							
	return true;
}

function trial_switch_box( id, configArr ) {

	jQuery('#' + configArr["boxFormId"]).hide();
	jQuery('#' + configArr["boxOKId"]).hide();
	jQuery('#' + configArr["boxExistsId"]).hide();
	jQuery('#' + configArr["boxErrorId"]).hide();
	jQuery('#' + configArr["boxSessionId"]).hide();	
	jQuery('#' + id).show();
}

function trial_modal(configArr, position) {

		if( position == 1 ) {
			var baseElemName = configArr["subscribeFieldId"];
			var vpos = -136;
			var hpos = 100;
		} else if ( position == 2 ) {
			var baseElemName = configArr["subscribeField2Id"];
			var vpos = -136;
			var hpos = 200;					
		} else {
			return false;
		}

		//calculate modalPos relative to subscribe button
		var oElement = jQuery('#' + baseElemName)[0];
		var topval = 0;
		var leftval = 0;
		while( oElement != null ) {
			topval += oElement.offsetTop;
			leftval += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
		topval =  topval+vpos;
		leftval = leftval+hpos;

		//invoke modal
		jQuery('#trial_modal').modal({
			containerCss: {height: '80px', width:'450px', border:'0px', top: topval, left: leftval},
			overlay: (20),
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
						jQuery('#' + configArr["emailModalFieldId"]).focus();
					});
				});
			},
			onShow: function (dialog) {
				//dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});
}
function inputText(a /*selector*/ ,b /*string*/,c/*class*/){
   	$(document).ready(function(){
   		if($(a).val() == ""){
   			$(a).val(b).addClass(c);
   		}
   		$(a).blur(function () {
   			if($(a).val() == ""){
   				$(a).val(b).addClass(c);
   			}
   		});
   		$(a).focus(function () {
   			if($(a).val() == b){
   				$(a).val("").removeClass(c);
   			}
   		});
   	});
   }

//*********** tooltip.js *********** 
/*
 * jQuery Tools v1.2.5 - The missing UI library for the Web
 * http://flowplayer.org/tools/
 * 
 */
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:!1,cancelDefault:!0,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,c,d){b[a]=[c,d]}};var b={toggle:[function(a){var b=this.getConf(),c=this.getTip(),d=b.opacity;d<1&&c.css({opacity:d}),c.show(),a.call()},function(a){this.getTip().hide(),a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};function c(b,c,d){var e=d.relative?b.position().top:b.offset().top,f=d.relative?b.position().left:b.offset().left,g=d.position[0];e-=c.outerHeight()-d.offset[0],f+=b.outerWidth()+d.offset[1],/iPad/i.test(navigator.userAgent)&&(e-=a(window).scrollTop());var h=c.outerHeight()+b.outerHeight();g=="center"&&(e+=h/2),g=="bottom"&&(e+=h),g=d.position[1];var i=c.outerWidth()+b.outerWidth();g=="center"&&(f-=i/2),g=="left"&&(f-=i);return{top:e,left:f}}function d(d,e){var f=this,g=d.add(f),h,i=0,j=0,k=d.attr("title"),l=d.attr("data-tooltip"),m=b[e.effect],n,o=d.is(":input"),p=o&&d.is(":checkbox, :radio, select, :button, :submit"),q=d.attr("type"),r=e.events[q]||e.events[o?p?"widget":"input":"def"];if(!m)throw"Nonexistent effect \""+e.effect+"\"";r=r.split(/,\s*/);if(r.length!=2)throw"Tooltip: bad events configuration for "+q;d.bind(r[0],function(a){clearTimeout(i),e.predelay?j=setTimeout(function(){f.show(a)},e.predelay):f.show(a)}).bind(r[1],function(a){clearTimeout(j),e.delay?i=setTimeout(function(){f.hide(a)},e.delay):f.hide(a)}),k&&e.cancelDefault&&(d.removeAttr("title"),d.data("title",k)),a.extend(f,{show:function(b){if(!h){l?h=a(l):e.tip?h=a(e.tip).eq(0):k?h=a(e.layout).addClass(e.tipClass).appendTo(document.body).hide().append(k):(h=d.next(),h.length||(h=d.parent().next()));if(!h.length)throw"Cannot find tooltip for "+d}if(f.isShown())return f;h.stop(!0,!0);var o=c(d,h,e);e.tip&&h.html(d.data("title")),b=b||a.Event(),b.type="onBeforeShow",g.trigger(b,[o]);if(b.isDefaultPrevented())return f;o=c(d,h,e),h.css({position:"absolute",top:o.top,left:o.left}),n=!0,m[0].call(f,function(){b.type="onShow",n="full",g.trigger(b)});var p=e.events.tooltip.split(/,\s*/);h.data("__set")||(h.bind(p[0],function(){clearTimeout(i),clearTimeout(j)}),p[1]&&!d.is("input:not(:checkbox, :radio), textarea")&&h.bind(p[1],function(a){a.relatedTarget!=d[0]&&d.trigger(r[1].split(" ")[0])}),h.data("__set",!0));return f},hide:function(c){if(!h||!f.isShown())return f;c=c||a.Event(),c.type="onBeforeHide",g.trigger(c);if(!c.isDefaultPrevented()){n=!1,b[e.effect][1].call(f,function(){c.type="onHide",g.trigger(c)});return f}},isShown:function(a){return a?n=="full":n},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return d}}),a.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}})}a.fn.tooltip=function(b){var c=this.data("tooltip");if(c)return c;b=a.extend(!0,{},a.tools.tooltip.conf,b),typeof b.position=="string"&&(b.position=b.position.split(/,?\s/)),this.each(function(){c=new d(a(this),b),a(this).data("tooltip",c)});return b.api?c:this}})(jQuery);
