jQuery(document).ready(function($){
var h=document;
var l = h.body;
var p = h.documentElement;
//var b = ga();
var link =location.href;
ja = function(a) {
	a = a.getElementsByTagName("script");
	for ( var b = a.length - 1; b >= 0; b--) {
		var c = a[b];
		c.parentNode.removeChild(c)
	}
}
M = function(a, b) {
	for ( var c in a)
		if (a.hasOwnProperty(c))
			b[c] = a[c]
}
w = function(a, b, c) {
				a = h.createElement(a);
				M(b, a);
				M(c, a.style);
				return a
			}

ha = function(a) {
	T(a.target || a.srcElement, true)
}
jQuery.fn.save_data=function(content){
	var url=wp_copy.url+'/wp-copy-ajax.php?my_task=add';
	var nonce=wp_copy.nonce;
	var data='nonce='+nonce;
	data+='&link='+link;
	if(wp_copy.save_content)data+='&content='+content;
	
		$.ajax({
		url:url,
		async:true,
		data:data,
		type:"POST",
		success:function(html){
	}
	});
}
var wa = {
		t : 3,
		p : 6,
		w : 7
	}
//var T = x();//koja je funkcija x
//x = wa[ka(location.href)];
ka = function(
		a) {
	a = a.match(/ixzz=?([^?$#]*)/);
	if (!a)
	return null;
	a = a[1].match(/&([^?$]*)/);
	
	return a[1];
}
ia = function(a) {
	a = a.target || a.srcElement;
	G = a.nodeName == "IMG" ? a : null
}
my_ha = function(){

}
U = function() {
	var a = function(g) {
		return typeof g.pageX == "number" ? {
			x : g.pageX
					- (p.scrollLeft ? p.scrollLeft : l.scrollLeft),
			y : g.pageY - (p.scrollTop ? p.scrollTop : l.scrollTop)
		} : {
			x : g.clientX,
			y : g.clientY
		}
	}, b = function(g) {
		g = a(g);
		return g.x <= 0 || g.y <= 0 || g.x >= l.clientWidth
				|| g.y >= l.clientHeight
	}, c = function(g) {
		g = a(g);
		return g.x <= 0 || g.y <= 0 || g.x >= p.clientWidth
				|| g.y >= p.clientHeight
	}, d = function(g) {
		return g.target.nodeName == "#document"
	}, f = function(g) {
		g = a(g);
		return g.x <= 4 || g.y <= 4 || g.x >= p.clientWidth - 4
				|| g.y >= p.clientHeight - 4
	}, e = function(g) {
		e = navigator.userAgent.match("MSIE") ? !h.compatMode
				|| h.compatMode.indexOf("CSS") == -1 ? b : c
				: navigator.userAgent.match("Firefox") ? d : f;
		e(g)
	};
	return function(g) {
		if (G && e(g)) {
			T(G);
			G = null
		}
		return true
	}
}();	

	var k=1;
	var mouse_down=1;
	var ajax_send=0;
	/*
	if (window.addEventListener) {
		navigator.userAgent.match("Firefox/2")
				|| l.addEventListener("copy", my_ha, false);
		window.addEventListener("mousedown", ia, false);
		window.addEventListener("dragleave", U, false);
		window.addEventListener("dragexit", U, false);
		//h.addEventListener("contextmenu", ta, false)
	} else {
		l.attachEvent("oncopy", my_ha);
		h.getElementsByTagName("html")[0].attachEvent(
				"ondragleave", U);
		l.attachEvent("onmousedown", ia)
	}
	/*
	$(document).bind("copy",function(event){
		add="\n Read more: "+window.location.href;
		if(window.getSelection()){
		txt=window.getSelection();
		}else if(dosument.getSelection()){
		txt=document.getSelection();
		}else if(document.selection){
		txt=document.selection;
		}
		alert("Selection "+txt);
		
		

	});
	*/
	

	//$("*").mouseup(function(event){
	if(wp_copy.ex==0){
	$("body").bind("copy",function(event){
		if(event.target.type&&(event.target.type=='text'||event.target.type=='textarea')){
			//alert('Type '+event.target.type);
	return ;
	}
		//alert(this.id+" "+this.name);	
		if(mouse_down){
			var f,e;
			f = w("div", {}, {
				overflow : "hidden",
				color : "#000000",
				backgroundColor : "transparent",
				textAlign : "left",
				textDecoration : "none",
				border : "none"
			});
			C=false;
			if (!h.selection || !h.selection.createRange) {
				a = getSelection();
				if(!ajax_send){
				ajax_send=1;
				$.fn.save_data(a.toString());
				}
				if (a.toString())
					if (typeof a.setBaseAndExtent != "undefined") {
						//alert('Second if');
						var g = a.getRangeAt(0);
						b = w("span", {
							innerHTML : ""
						});
						
						b.innerHTML += "<br/><br/>"+wp_copy.tag+" <a href=\""+link+"\">"+link+"</a>";
						f.appendChild(g.cloneContents())
						f.appendChild(b);
						
						f.style.width = 0.1;
						f.style.height = 0.1;
						f.style.position = "absolute";
						f.style.top = "-1000px";
						f.style.left = "-1001px";
						f.appendChild(h.createElement("br"));
						b = f.innerText.length;
						l.insertBefore(f, l.firstChild);
						if (f.innerText.length != b)
							f.style.overflow = "";
						a.selectAllChildren(f);
						setTimeout(function() {
							f.parentNode.removeChild(f);
							getSelection().setBaseAndExtent(
									g.startContainer, g.startOffset,
									g.endContainer, g.endOffset);
							C = false
						}, 0);
					}else {
						//alert("second if else");
						e = w("div", {}, {
							height : 0,
							position : "absolute",
							top : "-1000px"
						});
						e.innerHTML = "<br>";
						//if (i.t) {
							//l.insertBefore(e, l.firstChild);
							l.appendChild(e);
							f.innerHTML = "<br><br>"+wp_copy.tag+"<a href=\""+link+"\">"+link+"</a>";
							e.appendChild(f);
							b = h.createRange();
							b.selectNode(f);
							a.addRange(b);
							window.setTimeout(function() {
								e.parentNode.removeChild(e);
								C = false
							}, 0)
					}
			}else {
				//alert("Fisrt if else");
				var k = p.scrollLeft || l.scrollLeft, o = p.scrollTop
				|| l.scrollTop;
		e = w("div", {}, {
			overflow : "hidden",
			position : "absolute",
			left : k + 20 + "px",
			top : o + 20 + "px",
			width : "1px",
			height : "1px"
		});
		l.insertBefore(e, l.firstChild);
		var j = h.selection.createRange();
		f.innerHTML =j.htmlText+"<br><br>"+wp_copy.tag+"<a href=\""+link+"\">"+link+"</a>";
		if(!ajax_send){
			ajax_send=1;
			$.fn.save_data(j.htmlText);
			}
		//alert(f.innerHTML);
		ja(f);
		//alert(f.innerHTML);
		e.appendChild(h.createElement("br"));
		e.appendChild(f);
		b = l.createTextRange();
		b.moveToElementText(f);
		b.select();
		setTimeout(function() {
			l.removeChild(e);
			if (j.text != "") {
				j.select();
				p.scrollLeft = k;
				l.scrollLeft = k;
				p.scrollTop = o;
				l.scrollTop = o
			}
			C = false
		}, 0);
	}
	if(ajax_send)ajax_send=0;		
	//return true	
			}
		
		//mouse_down=0;
	});
	/*
	$("*").mousedown(function(event){
		if(event.which==1)
		mouse_down=1;
	      //$(this).append('');
	    });
	*/
}	}
);

