
// OS: // Browser: // IP: 38.107.191.91
	var user_is = 0;
	/*

	Author: SkyKnight
	ver: 0.2-alpha

	*/
	
	// set model
	var re = /\/numer([0-9]+)\/pibi\/([0-9a-z.-]+)/;
	var re2 = /\/numer([0-9]+)-([0-9]+)\/pibi\/([0-9a-z.-]+)/;
	
	// set needed vars
	var Issue;
	var File;
	var TitlePage;
	var justShowOn = 0;
	
	// initiate function
	function IniSet() {
		// if this issue can be comment
		if(CheckIssue()) {
			// create new stylesheet node
			var stylesheet = document.createElement("link");
			stylesheet.setAttribute("rel","stylesheet");
			stylesheet.setAttribute("type","text/css");
			stylesheet.setAttribute("href","/js/zin_bar.css");
			document.getElementsByTagName("head").item(0).appendChild(stylesheet);
			
			// create small icon
		    var icon = document.createElement("div");
	  		icon.onclick = 'CreateWindow()';
	    	icon.className = "zin_icon";
	    	icon.id = "zin_icon";
	    	icon.innerHTML = '<a onclick="CreateWindow()">Komentuj</a>'
	    	document.body.appendChild(icon);
			
			// AdvAJAX for AJAX requests
			IncludeJS("/js/advajax.js");
	  		
	  		// X from Cross-Browser.com for drag'n'drop
	  		// X-core
	  		IncludeJS("/js/x/x_core.js");
	  		
	  		// X-event
	  		IncludeJS("/js/x/x_event.js");
	
			// X-drag
			IncludeJS("/js/x/x_drag.js");
			
			// DOM Tabs
			IncludeJS("/js/domtab.js");
			
			return true;
		} else { // if not, do nothing
			return false;
		}
	
	
	}
	
	// check issue
	function CheckIssue() {
		// check url using model
		var CheckURL = re.exec(location.href);
		var CheckURL2 = re2.exec(location.href);
		
		// if url is ok
		if(CheckURL) {
			// set data about issue
			Issue = CheckURL[1];
			File = CheckURL[2];
			// if issue is not old
			if(Issue > 6) {
				var CA = 1;
				TitleTag = document.getElementsByTagName("title").item(0);
				TitlePage = TitleTag.innerHTML;
				return true;
			} else {
				return false;
			}
		} else {
			if(CheckURL2) {
				Issue = CheckURL2[1]+'-'+CheckURL2[2];
				File = CheckURL2[3];
				TitleTag = document.getElementsByTagName("title").item(0);
				TitlePage = TitleTag.innerHTML;
				return true;
			} else {
				return false;
			}
		}
	}
	
	
	// creating window
	function CreateWindow() {
		// create new javascript nodes
		/*
		// AdvAJAX for AJAX requests
		IncludeJS("/js/advajax.js");
  		
  		// X from Cross-Browser.com for drag'n'drop
  		// X-core
  		IncludeJS("/js/x/x_core.js");
  		
  		// X-event
  		IncludeJS("/js/x/x_event.js");

		// X-drag
		IncludeJS("/js/x/x_drag.js");
		
		// DOM Tabs
		IncludeJS("/js/domtab.js");
		*/
		
		// set contents of window
		var cform = GetCForm();
		var cprofile = 'ccc';
		var cauthor = 'ddd';
		
		// create window
    	var win = document.createElement("div");
    	win.innerHTML = '<div id="d3MaxBtn" class="window_button">&nbsp;</div><div id="d3Bar" class="window_bar">Playback.pl</div><div class="domtab"><ul class="domtabs"><li><a href="#cform">Komentuj</a></li><li><a href="#cshow">Pokaż komentarze</a></li><li><a href="#cprofile">Mój profil</a></li><li><a href="#cauthor">O autorze</a></li></ul><div><h2><a id="cform" name="cform">Dodaj komentarz</a></h2><p id="cform_content">'+cform+'</p></div><div><h2><a id="cshow" name="cshow">Zobacz komentarze innych</a></h2><p id="cshow_content"></p><ul id="cshow_content_"></ul></div><div><h2><a id="cprofile" name="cprofile">Mój profil</a></h2><p>'+cprofile+'</p></div><div><h2><a id="cauthor" name="cauthor">Dane autora</a></h2><p>'+cauthor+'</p></div></div><div id="d3ResizeBtn" class="window_button">&nbsp;</div></div>';
    	win.className = "zin_window";
    	win.id = "zin_window";
    	document.body.appendChild(win);

		// enable tabs
		domtab.init();
		
		// 
		GetCShow();
		
		// enable drag'n'drop
		if(window.xGetElementById) {
			d3Setup();
		} else {
			alert('shit');
		}
		
		// disable creating new window, enable hidden
		icon_ = document.getElementById("zin_icon");
		icon_.innerHTML = '<a onclick="HideWindow()">Ukryj</a>';
	}
	
	// add new script node (include JS file)
	function IncludeJS(src) {
  		var JScript = document.createElement("script");
  		JScript.setAttribute("type","text/javascript");
  		JScript.setAttribute("src",src);
  		document.getElementsByTagName("head").item(0).appendChild(JScript);
	
	}
	
	// get comment form
	function GetCForm() {
		if(user_is == 1) {
			return '<form method="post" action="http://www.playback.pl/?m=zin&amp;mode=cmnt" name="_cform" id="cmnt_form"><label for="_content">Tresc</label><textarea rows="10" cols="28" name="_content" id="_content"></textarea><input type="hidden" name="m" value="zin" /><input type="hidden" name="mode" value="cmnt" /><input type="hidden" name="n" value="'+Issue+'" /><input type="hidden" name="t" value="'+File+'" /><input type="hidden" name="tt" value="'+TitlePage+'" /><br /><input type="button" id="add" onclick="SendComment()" value="Dodaj" /><input type="button" onclick="HideWindow()" value="Anuluj" /></form>';
		} else {
			return 'Nie jestes zalogowany. Zdalne logowanie wkrotce...';
		}
	}
	
	// get comments
	function GetCShow() {
		var cshow = document.getElementById("cshow_content_");
		//cshowBBB.innerHTML = '<>loon jest gupi</b>';
  	advAJAX.get({
      url: "http://www.playback.pl/index.php5?m=zin&mode=show_cmnts&i="+Issue+"&f="+File,
      onSuccess : function(obj) { 
      //alert('hahahaha'+obj.responseText);
      //var bbb = obj.responseText;
      cshow.innerHTML = obj.responseText;
      
      
			if(cshow.innerHTML == 0) {
				cshow.innerHTML = 'Brak komenatarzy';
				//alert(bbb);
			}
				 },
      onError : function(obj) { alert("Error: " + obj.status); }
  });
	}
	
	// hide window
	function HideWindow() {
		var win = document.getElementById("zin_window");
		win.style.visibility = 'hidden';
		icon_ = document.getElementById("zin_icon");
		icon_.innerHTML = '<a onclick="ShowWindow()">Komentuj</a>';
	}
	
	// show hidden window
	function ShowWindow() {
		var win_ = document.getElementById("zin_window");
		win_.style.visibility = 'visible';
		icon_ = document.getElementById("zin_icon");
		icon_.innerHTML = '<a onclick="HideWindow()">Ukryj</a>';
	}	
	
	// send comment
	function SendComment() {
  	document.getElementById("add").disabled = 'true';
  	advAJAX.submit(document.getElementById("cmnt_form"), {
    	  onSuccess : function(obj) { 
				var ccc = obj.responseText;
				if(ccc == 1) {
					alert('Wystapil blad - komentarz nie zostal dodany');
				} else {
					GetCShow();
					var cform = document.getElementById("cform_content");
					cform.innerHTML = 'Komentarz zostal dodany. Mozesz przejsc na <a href="http://www.playback.pl/index.php5?m=zin&amp;mode=show_cmnt&amp;n='+Issue+'&amp;t='+File+'">forum</a>.';
				}
				
				},
    	  onError : function(obj) { alert("Error: " + obj.status); }
  	});
	}
	// X-functions - drag'n'drop
	function d3Setup()
	{
	  var d3 = xGetElementById('zin_window');
	  var rBtn = xGetElementById('d3ResizeBtn');
	  var mBtn = xGetElementById('d3MaxBtn');
	  xMoveTo(d3, 300, 400);
	  d3Paint();
	  xEnableDrag('d3Bar', d3BarOnDragStart, d3BarOnDrag, null);
	  xEnableDrag(rBtn, d3RBtnOnResizeStart, d3RBtnOnResize, null);
	  mBtn.onclick = d3MBtnOnClick;
	  xShow(d3);
	}
	function d3Paint()
	{
	  var d3 = xGetElementById('zin_window');
	  var rBtn = xGetElementById('d3ResizeBtn');
	  var mBtn = xGetElementById('d3MaxBtn');
	  xMoveTo(rBtn, xWidth(d3) - xWidth(rBtn), xHeight(d3) - xHeight(rBtn));
	  xMoveTo(mBtn, xWidth(d3) - xWidth(rBtn), 0);
	}
	function d3BarOnDragStart(ele, mx, my)
	{
	  xZIndex('zin_window', highZ++);
	}
	function d3BarOnDrag(ele, mdx, mdy)
	{
	  xMoveTo('zin_window', xLeft('zin_window') + mdx, xTop('zin_window') + mdy);
	}
	function d3RBtnOnResizeStart(ele, mx, my)
	{
	  xZIndex('zin_window', highZ++);
	}
	function d3RBtnOnResize(ele, mdx, mdy)
	{
	  xResizeTo('zin_window', xWidth('zin_window') + mdx, xHeight('zin_window') + mdy);
	  d3Paint();
	}
	function d3MBtnOnClick()
	{
	  var d3 = xGetElementById('zin_window');
	  if (d3.maximized) {
	    d3.maximized = false;
	    xResizeTo(d3, d3.prevW, d3.prevH);
	    xMoveTo(d3, d3.prevX, d3.prevY);
	    d3Paint();
	  }
	  else {
	    d3.prevW = xWidth(d3);
	    d3.prevH = xHeight(d3);
	    d3.prevX = xLeft(d3);
	    d3.prevY = xTop(d3);
	    xMoveTo(d3, xScrollLeft(), xScrollTop());
	    d3.maximized = true;
	    xResizeTo(d3, xClientWidth(), xClientHeight());
	    d3Paint();
	  }
	}
	// end of X functions
	
	
	
	
	/*
	// main function
	function StartZin(){
		// create new stylesheet node
		var stylesheet = document.createElement("link");
		stylesheet.setAttribute("rel","stylesheet");
		stylesheet.setAttribute("type","text/css");
		stylesheet.setAttribute("href","/js/zin_bar.css");
		document.getElementsByTagName("head").item(0).appendChild(stylesheet);
		
		// check url with model
		var CheckURL = re.exec(location.href);
		
		// if url is ok
		if(CheckURL) {
			//var second_test = CheckURL[0]+CheckURL[1]+CheckURL[2];
			Issue = CheckURL[1];
			File = CheckURL[2];
			// check number of issue
			if(Issue > 6) {
				var CA = 1;
				TitleTag = document.getElementsByTagName("title").item(0);
				TitlePage = TitleTag.innerHTML;
			} else {
				var CA = 0;
			}
		} else {
			//alert('nevermind');
			var CA = 0;
		}
		
		var left_bar;
		var right_bar;
		
		if(CA == 1) {
			left_bar = '<div class="left_bar" id="left_bar"><a href="#" onclick="justShow()">Komentuj</a></div>';
		} else {
			left_bar = '<div class="left_bar" id="left_bar">Niestety, nie mozesz komentowac tego tekstu</div>';
			Issue = '';
			File = '';
		}
		
		if(user_is == 1) {
			right_bar = '<div class="right_bar" id="right_bar">Zalogowany jako '+user_login+' <a href="http://www.playback.pl/index.php5?m=logout&amp;n='+Issue+'&amp;t='+File+'">Wyloguj</a></div>';
		} else {
			right_bar = '<div class="right_bar" id="right_bar">Nie jestes zalogowany <a href="http://www.playback.pl/index.php5?m=login&amp;n='+Issue+'&amp;t='+File+'">Zaloguj</a></div>';
		}
		
		
		
    var container = document.createElement("div");
    container.innerHTML = left_bar+right_bar;
    container.className = "zin_bar";
    document.body.appendChild(container);
	}
	
	function justShow() {
		if(user_is == 1 && justShowOn == 0) {
  		// create new js node (ajax)
  		var aa = document.createElement("script");
  		aa.setAttribute("type","text/javascript");
  		aa.setAttribute("src","/js/advajax.js");
  		document.getElementsByTagName("head").item(0).appendChild(aa);
    	var container_w = document.createElement("div");
    	container_w.innerHTML = '<form id="cmnt_form" action="http://www.playback.pl/index.php5" method="post"><textarea cols="30" rows="10" name="content">Tresc...</textarea><input type="hidden" name="m" value="zin" /><input type="hidden" name="mode" value="cmnt" /><input type="hidden" name="n" value="'+Issue+'" /><input type="hidden" name="t" value="'+File+'" /><input type="hidden" name="tt" value="'+TitlePage+'" /><br /><input type="button" name="sender" value="Dodaj" id="add" onclick="SendCmnt()" /><input type="button" name="cancel" value="Anuluj" onclick="CancelIt()" /></form></div>';
    	container_w.className = "zin_window";
    	container_w.id = "cmnt_window";
    	document.body.appendChild(container_w);
			justShowOn = 1;
		} else { 
			if(user_is == 1 && justShowOn == 2) {
  			//cm = 
  			document.getElementById('cmnt_window').style.visibility = 'visible';
  			justShowOn = 1;
			} else {
				alert('Nie jestes zalogowany, by moc komentowac');
			}
		}
	}
	
	function CancelIt() {
		//bo = document.body;
		//cm = document.getElementById("cmnt_window");
		document.getElementById('cmnt_window').style.visibility = 'hidden';
		justShowOn = 2;
	}
	
	
	function SendCmnt() {
  //  advAJAX.assign(document.getElementById("cmnt_form"), {
  //    onSuccess : function(obj) { alert(obj.responseText); },
  //    onError : function(obj) { alert("Error: " + obj.status); }
  //  });
  document.getElementById("add").disabled = 'true';
  advAJAX.submit(document.getElementById("cmnt_form"), {
      onSuccess : function(obj) { EndThisShit(obj.responseText); },
      onError : function(obj) { alert("Error: " + obj.status); }
  });
	}
	
	
	function EndThisShit(returnString) {
		bo = document.body;
		cm = document.getElementById("cmnt_window");
		throwaway_node = bo.removeChild(cm);
		
		if(returnString == 0) {
			left_side = document.getElementById("left_bar");
			left_side.innerHTML = 'Komentarz zostal dodany. <a href="http://www.playback.pl/index.php5?m=zin&amp;mode=show_cmnt&amp;n='+Issue+'&amp;t='+File+'">Zobacz</a>';
		} else {
			document.getElementById("left_bar").innerHTML = 'Niestety, wystapil blad. Komentarz nie zostal dodany';
		}
		
		justShowOn = 1;
	}
	
  function addEvent(obj, evType, fn){ 
  	if (obj.addEventListener){ 
    	obj.addEventListener(evType, fn, false); 
			return true; 
		} else if (obj.attachEvent){ 
			var r = obj.attachEvent("on"+evType, fn); 
			return r; 
		} else { 
			return false; 
		} 
	}

	addEvent(window, 'load', StartZin);
	*/
	
  function addEvent(obj, evType, fn){ 
  	if (obj.addEventListener){ 
    	obj.addEventListener(evType, fn, false); 
			return true; 
		} else if (obj.attachEvent){ 
			var r = obj.attachEvent("on"+evType, fn); 
			return r; 
		} else { 
			return false; 
		} 
	}

	addEvent(window, 'load', IniSet);

//document.writeln('<'+'scr'+'ipt type="text/javascript" src="http://s2.hit.stat24.com/_'+(new Date()).getTime()+'/script.js?id=bPo1lIdrneBuDpvGEKpNwrPp374yiu8QuN38Tcnw.zn.F7/l=11"></'+'scr'+'ipt>');
	// amen
