show = function(id){ document.getElementById(id).style.display=""}
hide = function(id){ document.getElementById(id).style.display="none"}
hide_all = function(tag_name, prefix){ var e = document.getElementsByTagName(tag_name)
for(i=0;i<e.length;i++){var elm = e[i]; if(elm.id.indexOf(prefix) == 0) hide(elm.id)}}
set_class = function(id, value) { var e = document.getElementById(id); e.setAttribute('class', value); e.setAttribute('className', value);}
set_class_to_all = function(tag_name, prefix, value) {var e = document.getElementsByTagName(tag_name)
for(i=0;i<e.length;i++) {var elm = e[i]; if(elm.id.indexOf(prefix) == 0) set_class(elm.id, value)}}
show_tab = function(id){set_class_to_all("li","bkmh_","");set_class("bkmh_"+id, "active");hide_all('div', "bk_"); show("bk_"+id);}

function PrintPopUp(l) {
	window.open(l,'','resizable=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=800,height=600,left=0,top=0');
	return false;
}

function PopUp(l, w, h) {
	w = window.open('','','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');

	d = w.document
	d.writeln('<html>')
	d.writeln('<head>')
	d.writeln('<style type="text/css">body {background-color:0xFFFFFF;margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;}</style>')
	d.writeln('<title>Kliknij na zdjęciu, aby zamknąć okno.</title>')
	d.writeln('</head>')
	d.writeln('<body>')
	d.writeln('<a href="javascript:self.close()"><img alt="Close window" src="'+l+'" border="0"></a>')
	d.writeln('</body>')
	d.writeln('</html>')
	d.close()
	return false;
}

function EmailFriend(l,id){
	w = window.open(abs_path+"templates/html/email-friend.php?id="+id+"&url="+escape(l),'','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=380,height=360,left=0,top=0')
	return false;
}

// AJAX
function getXmlHttpObject(){var xmlHttp = null; try {xmlHttp = new XMLHttpRequest();}
catch(e) { var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){try{ xmlHttp = new ActiveXObject(XmlHttpVersions[i]); } catch (e){}}
}return xmlHttp;}

survey_xmlhttp = getXmlHttpObject();
function Sonda(){
	this.Glosuj = Glosuj
	this.__results = __results
	
	function Glosuj(type){
		survey_xmlhttp.onreadystatechange = this.__results
		//to= document.location;
		survey_xmlhttp.open("POST", abs_path+'/mods/ajax/sonda.php?type='+type, true)
		
		f = document.getElementById('formsond')
		
		checked = -1;
		for(i=0;f.pyt.length;i++){
			if(f.pyt[i].checked){ checked = i; break; }
		}
		if(checked == -1) return;

		post_data = "wybor="+f.pyt[checked].value
		survey_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      	survey_xmlhttp.setRequestHeader("Content-length", post_data.length);
      	survey_xmlhttp.setRequestHeader("Connection", "close");
		survey_xmlhttp.send(post_data);	
	}
	
	function __results(){
		var r = survey_xmlhttp;
		if(r.readyState == 4 || r.readyState == "complete"){
			if(r.status == 200){
				document.getElementById('divsonda').innerHTML = r.responseText;
			}else{}
		}
	}
}


function sendJokeVote(id){
	if(Cookie.get("cjoke_"+id) == false){
		$('jokefrm_'+id).send({
			method: 'post',
			onComplete: function(){
				if(this.response.text == 0){
					Cookie.set('cjoke_'+id, "1");
					$('jokediv_'+id).setText('Twój głos został zapisany! Dziękujemy. ')
				}else{
					$('jokediv_'+id).setText('Twój głos  nie został zapisany! Spróbuj ponownie. ')
				}
			}
		});
	}else{
		alert("Już oceniałeś(aś) ten żart! Można głosować tylko 1 raz.");
	}
}

function sendPhotoVote(id,ocena){
	if(Cookie.get("cphoto_"+id) == false){
		new Ajax(abs_path+"?m=Hanysy&a=photoVote",{
			method: 'post',
			data: { 'photo_id': id, 'ocena': ocena},
			onComplete: function(){
				if(this.response.text == 0){
					Cookie.set('cphoto_'+id, "1");
					$('glosowanie_zd').setText('Twój głos został zapisany! Dziękujemy. ')
				}else{
					$('glosowanie_zd').setText('Twój głos nie został zapisany! Spróbuj ponownie. ')
				}
			}
		}).request();
	}else{
		alert("Już oceniałeś(aś) ten żart! Można głosować tylko 1 raz.");
	}
}
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") == "external") anchor.target = "_blank";}}

NewsTicker = new Class({
	_fx : Class.empty(),
	_timer: null,
	initialize: function(){
		this._fx = new Fx.Style('nt_cnt','top', {duration: 1000, transition: Fx.Transitions.Quart.easeInOut});		
		this._timer = (function() {this._nextMessage();}).periodical(5000,this)
	},
	_nextMessage: function(){
		curr_top = $('nt_cnt').getStyle('top').toInt()
		if(curr_top == -144) curr_top = 16
		this._fx.start(curr_top, curr_top-16)
	}
})

window.addEvent('domready', function(){
	new NewsTicker;
	externalLinks();
})