// ---------------------------- RÓZNE GLÓWNE --------------------------------

$(document).ready(function() {
jQuery(function(){
jQuery("#wysuwanecontent_fb").css("left","-210px");
jQuery("#wysuwanecontent_fb").hover(
function () {
jQuery("#wysuwanecontent_fb").animate({left: "0px"}, 400 );
        jQuery(this).addClass("zamknijcontent_fb");
  },
function () {
jQuery("#wysuwanecontent_fb").animate({left: "-210px"}, 400 );
        jQuery(this).removeClass("zamknijcontent_fb");
  }
);
});

jQuery("#buttneslzap").click(function() {
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: jQuery("#form-newsletter").serialize()+"&ic=zapisznewsletter",
		 beforeSend: function(){
         jQuery("#jsokienko3").show();
         jQuery("#jscontent3").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#jscontent3").html(html);          
         }
    }); 
 
});

});


var empty = new Image(); empty.src = "img/napiszform/fieldempty.png";
var tytul = new Image(); tytul.src = "img/napiszform/tytul.png";
var thumb = new Image(); thumb.src = "img/napiszform/thumb.png";
var tresc = new Image(); tresc.src = "img/napiszform/tresc.png";
var zalacznik = new Image(); zalacznik.src = "img/napiszform/zalacznik.png";
var autor = new Image(); autor.src = "img/napiszform/autor.png";
var email = new Image(); email.src = "img/napiszform/email.png";
var klauzula = new Image(); klauzula.src = "img/napiszform/klauzula.png";
var suma = new Image(); suma.src = "img/napiszform/suma.png";

var haveerrorsnap = 0;
function showImagenap(imagenamenap, imageurlnap, errorsnap) {
document[imagenamenap].src = imageurlnap;
if (!haveerrorsnap && errorsnap) haveerrorsnap = errorsnap;
}

function validateNapisz(f) {
haveerrorsnap = 0;
(f.tytul.value.length < 3 || f.tytul.value == "Tu wpisz tytuł*") 
? showImagenap("tytulerror", "img/napiszform/tytul.png", true)   
: showImagenap("tytulerror", "img/napiszform/fieldempty.png", false);

if(f.thumb.value!="") {
(f.thumb.value.search("[.jpg]") == -1 || f.thumb.value.search("[.gif]") == -1 || f.thumb.value.search("[.png]") == -1)
? showImagenap("thumberror", "img/napiszform/thumb.png", true)
: showImagenap("thumberror", "img/napiszform/fieldempty.png", false);
}

(f.tresc.value.length < 7 || f.tresc.value == "Tu umieść treść*") 
? showImagenap("trescerror", "img/napiszform/tresc.png", true)   
: showImagenap("trescerror", "img/napiszform/fieldempty.png", false);

if(f.zalacznik.value!="") {
(f.zalacznik.value.search("[.zip]") == -1 || f.zalacznik.value.search("[.pdf]") == -1 || f.zalacznik.value.search("[.doc]") == -1 || f.zalacznik.value.search("[.ppt]") == -1 || f.zalacznik.value.search("[.mp3]") == -1)
? showImagenap("zalacznikerror", "img/napiszform/zalacznik.png", true)
: showImagenap("zalacznikerror", "img/napiszform/fieldempty.png", false);
}

(f.autor.value.length < 3 || f.autor.value == "Tu podaj dane autora/autorki i nazwę organizacji*") 
? showImagenap("autorerror", "img/napiszform/autor.png", true)   
: showImagenap("autorerror", "img/napiszform/fieldempty.png", false);

((f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1) && f.email.value == "Tu podaj e-mail autora/autorki*")
? showImagenap("emailerror", "img/napiszform/email.png", true)
: showImagenap("emailerror", "img/napiszform/fieldempty.png", false);

(!f.klauzula.checked)
? showImagenap("klauzulaerror", "img/napiszform/klauzula.png", true)
: showImagenap("klauzulaerror", "img/napiszform/fieldempty.png", false);

(f.suma.value !=21)
? showImagenap("sumaerror", "img/napiszform/suma.png", true)
: showImagenap("sumaerror", "img/napiszform/fieldempty.png", false);

if(haveerrorsnap==0 || haveerrorsnap=="") {
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: jQuery("#form-wyslijnapisz").serialize() + "&ic=zapisznapisz",
		 beforeSend: function(){
         jQuery("#formularzmowieze").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
			 pokazdiv('jsokienko3');
                pokazformularznapisz();
				jQuery("#jscontent3").html(html); 
         }
    });
return false;
} else return (!haveerrorsnap);
}

//pokaż formularz napisz
function pokazformularznapisz(){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "ic=pokazformularznapisz",
		 beforeSend: function(){
         jQuery("#formularzmowieze").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#formularzmowieze").html(html);         
         }
    });
}

function validatePytanie(f) {
haveerrorsnap = 0;

((f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1) && f.email.value == "Tu podaj e-mail*")
? showImagenap("emailerror", "img/napiszform/email.png", true)
: showImagenap("emailerror", "img/napiszform/fieldempty.png", false);

(f.tresc.value.length < 7 || f.tresc.value == "Tu wpisz treść pytania*") 
? showImagenap("trescerror", "img/napiszform/tresc.png", true)   
: showImagenap("trescerror", "img/napiszform/fieldempty.png", false);

(f.suma.value !=21)
? showImagenap("sumaerror", "img/napiszform/suma.png", true)
: showImagenap("sumaerror", "img/napiszform/fieldempty.png", false);

if(haveerrorsnap==0 || haveerrorsnap=="") {
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: jQuery("#form-wyslijpytanie").serialize() + "&ic=wyslijpytanie",
		 beforeSend: function(){
         jQuery("#formularzpytanie").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
			 pokazdiv('jsokienko3');
                pokazformularzpytanie();
				jQuery("#jscontent3").html(html); 
         }
    });
return false;
} else return (!haveerrorsnap);
}

//pokaż formularz pytania
function pokazformularzpytanie(){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "ic=pokazformularzpytanie",
		 beforeSend: function(){
         jQuery("#formularzpytanie").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#formularzpytanie").html(html);         
         }
    });
}

function validateDoprawnika(f) {
haveerrorsnap = 0;

((f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1) && f.email.value == "Tu podaj e-mail*")
? showImagenap("emailerror", "img/napiszform/email.png", true)
: showImagenap("emailerror", "img/napiszform/fieldempty.png", false);

(f.tresc.value.length < 7 || f.tresc.value == "Tu wpisz treść pytania*") 
? showImagenap("trescerror", "img/napiszform/tresc.png", true)   
: showImagenap("trescerror", "img/napiszform/fieldempty.png", false);

(f.suma.value !=21)
? showImagenap("sumaerror", "img/napiszform/suma.png", true)
: showImagenap("sumaerror", "img/napiszform/fieldempty.png", false);

if(haveerrorsnap==0 || haveerrorsnap=="") {
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: jQuery("#form-wyslijdoprawnika").serialize() + "&ic=wyslijdoprawnika",
		 beforeSend: function(){
         jQuery("#formularzdoprawnika").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
			 pokazdiv('jsokienko3');
                pokazformularzdoprawnika();
				jQuery("#jscontent3").html(html); 
         }
    });
return false;
} else return (!haveerrorsnap);
}

//pokaż formularz pytania
function pokazformularzdoprawnika(){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "ic=pokazformularzdoprawnika",
		 beforeSend: function(){
         jQuery("#formularzdoprawnika").html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#formularzdoprawnika").html(html);         
         }
    });
}

$(function() {  
  $(".przyciskudostepniania").click(function() {
jQuery("#okienkoudostepniania").show();
  });  
});

$(function() {  
  $(".zamknijudostepnianie").click(function() {
jQuery("#okienkoudostepniania").hide("slow");
  });  
});



function pokaznewsletter(){
jQuery("#formnewsletter").toggle("slow");
}

//paginacja
function pokazpaging(idd,nnr,uss,querry,ido){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&nnr="+nnr+"&uss="+uss+"&komm="+querry+"&ido="+ido+"&ic=paginacja",
		 beforeSend: function(){
         jQuery("#listapaging"+ido).html('<img src="img/loader.gif" border="0" alt="Trwa ładowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#listapaging"+ido).html(html);         
         }
    });
}

//potwierdzenie adresu newslettera
function potwierdzenieadresu(idd) {
pokazdiv('jsokienko3');
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&ic=potwierdzenieadresu",
		 beforeSend: function(){
         jQuery("#jscontent3").html('<img src="img/loader.gif" border="0" alt="Trwa ladowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#jscontent3").html(html);         
         }
    });
}

//video w okienku
function video_okno(idd){
pokazdiv('jsokienko3');
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&ic=pokazvideo",
		 beforeSend: function(){
         jQuery("#jscontent3").html('<img src="img/loader.gif" border="0" alt="Trwa ladowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#jscontent3").html(html);         
         }
    });
}

//video w boksie
function video_boks(idd){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&ic=pokazvideo",
		 beforeSend: function(){
         jQuery("#video"+idd).html('<img src="img/loader.gif" border="0" alt="Trwa ladowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#video"+idd).html(html);         
         }
    });
}

//video w dokumencie
function video_dokument(idd){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&ic=pokazvideodokument",
		 beforeSend: function(){
         jQuery("#video"+idd).html('<img src="img/loader.gif" border="0" alt="Trwa ladowanie danych..." />');         
                            },
         success: function(html){
                jQuery("#video"+idd).html(html);         
         }
    });
}

//wszystkie tagi
function alltags(){
pokazdiv('jsokienko3');
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "ic=wszystkietagi",
		 beforeSend: function(){
         jQuery("#jscontent3").html('<img src="img/loader.gif" border="0" alt="..." />');         
                            },
         success: function(html){
                jQuery("#jscontent3").html(html);          
         }
    });
}

//formularz komentowania
function komentuj(idd){
jQuery("#formularzkomentowania").toggle();
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&ic=komentuj",
		 beforeSend: function(){
         jQuery("#formularzkomentowania").html('<img src="img/loader.gif" border="0" alt="..." />');         
                            },
         success: function(html){
                jQuery("#formularzkomentowania").html(html);          
         }
    });
}

//weryfikacja komentarza
function weryfikacjakom(idd,nnr) {
jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd="+idd+"&nnr="+nnr+"&ic=weryfikacjakom",
		 beforeSend: function(){
         jQuery("#komentarze"+nnr).html('<img src="img/loader.gif" border="0" alt="..." />');         
                            },
         success: function(html){
                jQuery("#komentarze"+nnr).html(html);          
         }
    });
}

//zamykanie okienka
function zamknijdiv(idk){
jQuery("#"+idk).toggle();
}
//pokazanie elementu
function pokazdiv(idk){
jQuery("#"+idk).show();
}




$(function(){
$(".jestwydarzenie").tipTip({maxWidth: "auto", edgeOffset: 10});
});

function dokalendarza(ile){
    jQuery.ajax({
         type: "POST",
         url: "web/js/php/ajax.php",
         data: "idd=" + ile + "&ic=kalendarzyk",
		 beforeSend: function(){
         jQuery("#callendar").html('<img src="img/loader.gif" border="0" alt="..." />');         
                            },
         success: function(html){
                jQuery("#callendar").html(html);         
         }
    });
	var tipTip = function(selector, options) {
      var elements = jQuery(selector);
      elements.tipTip(options);    // apply tipTips as usual
      $('body').ajaxComplete(function() {
          elements = jQuery(selector); // reselect elements
          elements.tipTip(options);   // and apply again after ajax requests
      });
      return elements;
  }
  // Now use that function instead
  tipTip("a[tiptip]");
}	
	
var Spry;
if(!Spry)
{
	Spry = {};
}
if(!Spry.Widget)
{
	Spry.Widget = {};
}

Spry.Widget.MenuBar = function(element, opts)
{
	this.init(element, opts);
};

Spry.Widget.MenuBar.prototype.init = function(element, opts)
{
	this.element = this.getElement(element);

	// represents the current (sub)menu we are operating on
	this.currMenu = null;

	var isie = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
	if(typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (isie && typeof document.uniqueID == 'undefined'))
	{
		// bail on older unsupported browsers
		return;
	}

	// load hover images now
	if(opts)
	{
		for(var k in opts)
		{
			var rollover = new Image;
			rollover.src = opts[k];
		}
	}

	if(this.element)
	{
		this.currMenu = this.element;
		var items = this.element.getElementsByTagName('li');
		for(var i=0; i<items.length; i++)
		{
			this.initialize(items[i], element, isie);
			if(isie)
			{
				this.addClassName(items[i], "MenuBarItemIE");
				items[i].style.position = "static";
			}
		}
		if(isie)
		{
			if(this.hasClassName(this.element, "MenuBarVertical"))
			{
				this.element.style.position = "relative";
			}
			var linkitems = this.element.getElementsByTagName('a');
			for(var i=0; i<linkitems.length; i++)
			{
				linkitems[i].style.position = "relative";
			}
		}
	}
};

Spry.Widget.MenuBar.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

Spry.Widget.MenuBar.prototype.hasClassName = function(ele, className)
{
	if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)
	{
		return false;
	}
	return true;
};

Spry.Widget.MenuBar.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || this.hasClassName(ele, className))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.MenuBar.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || !this.hasClassName(ele, className))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

// addEventListener for Menu Bar
// attach an event to a tag without creating obtrusive HTML code
Spry.Widget.MenuBar.prototype.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
		{
			element.addEventListener(eventType, handler, capture);
		}
		else if (element.attachEvent)
		{
			element.attachEvent('on' + eventType, handler);
		}
	}
	catch (e) {}
};

// createIframeLayer for Menu Bar
// creates an IFRAME underneath a menu so that it will show above form controls and ActiveX
Spry.Widget.MenuBar.prototype.createIframeLayer = function(menu)
{
	var layer = document.createElement('iframe');
	layer.tabIndex = '-1';
	layer.src = 'javascript:false;';
	menu.parentNode.appendChild(layer);
	
	layer.style.left = menu.offsetLeft + 'px';
	layer.style.top = menu.offsetTop + 'px';
	layer.style.width = menu.offsetWidth + 'px';
	layer.style.height = menu.offsetHeight + 'px';
};

// removeIframeLayer for Menu Bar
// removes an IFRAME underneath a menu to reveal any form controls and ActiveX
Spry.Widget.MenuBar.prototype.removeIframeLayer =  function(menu)
{
	var layers = menu.parentNode.getElementsByTagName('iframe');
	while(layers.length > 0)
	{
		layers[0].parentNode.removeChild(layers[0]);
	}
};

// clearMenus for Menu Bar
// root is the top level unordered list (<ul> tag)
Spry.Widget.MenuBar.prototype.clearMenus = function(root)
{
	var menus = root.getElementsByTagName('ul');
	for(var i=0; i<menus.length; i++)
	{
		this.hideSubmenu(menus[i]);
	}
	this.removeClassName(this.element, "MenuBarActive");
};

// bubbledTextEvent for Menu Bar
// identify bubbled up text events in Safari so we can ignore them
Spry.Widget.MenuBar.prototype.bubbledTextEvent = function()
{
	return (navigator.vendor == 'Apple Computer, Inc.' && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)));
};

// showSubmenu for Menu Bar
// set the proper CSS class on this menu to show it
Spry.Widget.MenuBar.prototype.showSubmenu = function(menu)
{
	if(this.currMenu)
	{
		this.clearMenus(this.currMenu);
		this.currMenu = null;
	}
	
	if(menu)
	{
		this.addClassName(menu, "MenuBarSubmenuVisible");
		if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
		{
			if(!this.hasClassName(this.element, "MenuBarHorizontal") || menu.parentNode.parentNode != this.element)
			{
				menu.style.top = menu.parentNode.offsetTop + 'px';
			}
		}
		if(typeof document.uniqueID != "undefined")
		{
			this.createIframeLayer(menu);
		}
	}
	this.addClassName(this.element, "MenuBarActive");
};

// hideSubmenu for Menu Bar
// remove the proper CSS class on this menu to hide it
Spry.Widget.MenuBar.prototype.hideSubmenu = function(menu)
{
	if(menu)
	{
		this.removeClassName(menu, "MenuBarSubmenuVisible");
		if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
		{
			menu.style.top = '';
			menu.style.left = '';
		}
		this.removeIframeLayer(menu);
	}
};

// initialize for Menu Bar
// create event listeners for the Menu Bar widget so we can properly
// show and hide submenus
Spry.Widget.MenuBar.prototype.initialize = function(listitem, element, isie)
{
	var opentime, closetime;
	var link = listitem.getElementsByTagName('a')[0];
	var submenus = listitem.getElementsByTagName('ul');
	var menu = (submenus.length > 0 ? submenus[0] : null);

	var hasSubMenu = false;
	if(menu)
	{
		this.addClassName(link, "MenuBarItemSubmenu");
		hasSubMenu = true;
	}

	if(!isie)
	{
		// define a simple function that comes standard in IE to determine
		// if a node is within another node
		listitem.contains = function(testNode)
		{
			// this refers to the list item
			if(testNode == null)
			{
				return false;
			}
			if(testNode == this)
			{
				return true;
			}
			else
			{
				return this.contains(testNode.parentNode);
			}
		};
	}
	
	// need to save this for scope further down
	var self = this;

	this.addEventListener(listitem, 'mouseover', function(e)
	{
		if(self.bubbledTextEvent())
		{
			// ignore bubbled text events
			return;
		}
		clearTimeout(closetime);
		if(self.currMenu == listitem)
		{
			self.currMenu = null;
		}
		// show menu highlighting
		self.addClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
		if(menu && !self.hasClassName(menu, "MenuBarSubmenuVisible"))
		{
			opentime = window.setTimeout(function(){self.showSubmenu(menu);}, 250);
		}
	}, false);

	this.addEventListener(listitem, 'mouseout', function(e)
	{
		if(self.bubbledTextEvent())
		{
			// ignore bubbled text events
			return;
		}

		var related = (typeof e.relatedTarget != 'undefined' ? e.relatedTarget : e.toElement);
		if(!listitem.contains(related))
		{
			clearTimeout(opentime);
			self.currMenu = listitem;

			// remove menu highlighting
			self.removeClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
			if(menu)
			{
				closetime = window.setTimeout(function(){self.hideSubmenu(menu);}, 600);
			}
		}
	}, false);
};



(function($){
	$.fn.tipTip = function(options) {
		var defaults = { 
			activation: "hover",
			keepAlive: true,
			maxWidth: "220px",
			edgeOffset: 4,
			defaultPosition: "top",
			delay: 400,
			fadeIn: 200,
			fadeOut: 200,
			attribute: "tiptip",
			content: false, // HTML or String to fill TipTIp with
		  	enter: function(){},
		  	exit: function(){}
	  	};
	 	var opts = $.extend(defaults, options);
	 	
	 	// Setup tip tip elements and render them to the DOM
	 	if($("#tiptip_holder").length <= 0){
	 		var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
			var tiptip_content = $('<div id="tiptip_content"></div>');
			var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
			$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
		} else {
			var tiptip_holder = $("#tiptip_holder");
			var tiptip_content = $("#tiptip_content");
			var tiptip_arrow = $("#tiptip_arrow");
		}
		
		return this.each(function(){
			var org_elem = $(this);
			if(opts.content){
				var org_title = opts.content;
			} else {
				var org_title = org_elem.attr(opts.attribute);
			}
			if(org_title != ""){
				if(!opts.content){
					org_elem.removeAttr(opts.attribute); //remove original Attribute
				}
				var timeout = false;
				
				if(opts.activation == "hover"){
					org_elem.hover(function(){
						active_tiptip();
					}, function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				} else if(opts.activation == "focus"){
					org_elem.focus(function(){
						active_tiptip();
					}).blur(function(){
						deactive_tiptip();
					});
				} else if(opts.activation == "click"){
					org_elem.click(function(){
						active_tiptip();
						return false;
					}).hover(function(){},function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				}
			
				function active_tiptip(){
					opts.enter.call(this);
					tiptip_content.html(org_title);
					tiptip_holder.hide().removeAttr("class").css("margin","0");
					tiptip_arrow.removeAttr("style");
					
					var top = parseInt(org_elem.offset()['top']);
					var left = parseInt(org_elem.offset()['left']);
					var org_width = parseInt(org_elem.outerWidth());
					var org_height = parseInt(org_elem.outerHeight());
					var tip_w = tiptip_holder.outerWidth();
					var tip_h = tiptip_holder.outerHeight();
					var w_compare = Math.round((org_width - tip_w) / 2);
					var h_compare = Math.round((org_height - tip_h) / 2);
					var marg_left = Math.round(left + w_compare);
					var marg_top = Math.round(top + org_height + opts.edgeOffset);
					var t_class = "";
					var arrow_top = "";
					var arrow_left = Math.round(tip_w - 12) / 2;

                    if(opts.defaultPosition == "bottom"){
                    	t_class = "_bottom";
                   	} else if(opts.defaultPosition == "top"){ 
                   		t_class = "_top";
                   	} else if(opts.defaultPosition == "left"){
                   		t_class = "_left";
                   	} else if(opts.defaultPosition == "right"){
                   		t_class = "_right";
                   	}
					
					var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
					var left_compare = (tip_w + left) > parseInt($(window).width());
					
					if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){
						t_class = "_right";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left = -12;
						marg_left = Math.round(left + org_width + opts.edgeOffset);
						marg_top = Math.round(top + h_compare);
					} else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)){
						t_class = "_left";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left =  Math.round(tip_w);
						marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
						marg_top = Math.round(top + h_compare);
					}

					var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
					var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;
					
					if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_top";
						} else {
							t_class = t_class+"_top";
						}
						arrow_top = tip_h;
						marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
					} else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_bottom";
						} else {
							t_class = t_class+"_bottom";
						}
						arrow_top = -12;						
						marg_top = Math.round(top + org_height + opts.edgeOffset);
					}
				
					if(t_class == "_right_top" || t_class == "_left_top"){
						marg_top = marg_top + 5;
					} else if(t_class == "_right_bottom" || t_class == "_left_bottom"){		
						marg_top = marg_top - 5;
					}
					if(t_class == "_left_top" || t_class == "_left_bottom"){	
						marg_left = marg_left + 5;
					}
					tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"});
					tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class);
					
					if (timeout){ clearTimeout(timeout); }
					timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay);	
				}
				
				function deactive_tiptip(){
					opts.exit.call(this);
					if (timeout){ clearTimeout(timeout); }
					tiptip_holder.fadeOut(opts.fadeOut);
				}
			}				
		});
	}
})(jQuery); 



