$(document).ready(function(){

	$(function() {
		$('a[rel=lightbox]').lightBox();
	});
	
	$('img.capimg').click(function(){
		d = new Date();
		this.src = "/app/captcha.php?"+d.getTime();
	;})
	
	$("p.mapb").css('height', '0px').css("overflow","hidden");
	$("a.maps").click(function(){
		openMap(this);
		this.blur();
		return false;
	;})
	
	switchInput();
;});

window.onload = function () {
	if($('#iarticle').length > 0) {
		$('#iarticle').slideshow({ 
			timeout: '5000',
			type: 'sequence',
			tag: 'img'
		});
	}
}

function switchInput(){
	
	$('.switchin').each(function(i) {
		
		if($(this).attr("type") == "password"){
			//$(this).replaceWith($(this).clone().attr("type","text"));
			$(this).attr("oldtype","password");
		}
		
		$(this).attr("oldtitle",$(this).attr("value"));
		
		$(this).focus(function() {
			if($(this).attr("value") == $(this).attr("oldtitle")) this.value = "";
			if($(this).attr("oldtype") == "password") {
				//alert('robim heslo');
				//$(this).replaceWith($(this).clone().attr("type","password"));
			}
			
		}).blur(function() {
			if($(this).attr("value") == "") $(this).attr("value",$(this).attr("oldtitle"));
			if($(this).attr("oldtype") == "password") {
				//$(this).replaceWith($(this).clone().attr("type","text"));
			}
		});
	});
}


function openMap(node){
	if($(node.hash).css("height") == "0px") {
		$(node.hash).animate({ 
			height: "350px"
 		}, 500 );
	}
	else {
		$(node.hash).animate({ 
			height: "0px"
 		}, 500 );
	}
	return false;
}







var dData = false;
var dmeno = '';
var dfirma = '';
var dulica = '';
var dmesto = '';
var dpsc = '';
var dstat = '';

function useFdata(node){
	if(node.checked){
		document.getElementById('dmeno').value = document.getElementById('meno').value;
		//document.getElementById('dfirma').value = document.getElementById('fname').value;
		document.getElementById('dulica').value = document.getElementById('fulica').value;
		document.getElementById('dmesto').value = document.getElementById('fmesto').value;
		document.getElementById('dpsc').value = document.getElementById('fpsc').value;
		document.getElementById('dstat').value = document.getElementById('fstat').value;
	}
	else {
		document.getElementById('dmeno').value = '';
		//document.getElementById('dfirma').value = '';
		document.getElementById('dulica').value = '';
		document.getElementById('dmesto').value = '';
		document.getElementById('dpsc').value = '';
		document.getElementById('dstat').value = '';
	}
}

function imgTitle(){
	var titles = $('.imagetitle');
	for(var j = 0;j < titles.length;j++){
		
		var imgTitle = titles[j];
		var imgText = imgTitle.innerHTML;
		var fontSize = 30;

		if(imgTitle.tagName == "H2") fontSize = 15;

		imgTitle.style.position = 'relative';
		imgTitle.innerHTML = imgText+'<img src="/imagetitle/' + imgTitle.offsetWidth + '~' + fontSize + '~' + imgText + '.png" style="position:absolute;top:0px;left:0px;" />';
		//alert(imgTitle.childNodes[1].height);
		//imgTitle.style.height = imgTitle.childNodes[1].height + 'px';
	}
}

function prepareForm(formId){

	var nodes = document.getElementsByClassName("inc",formId,"input");
	for(var i = 0; i < nodes.length; i++) {
		//hides[i].style.display = "none";
		//var alId = hides[i].id.replace(/[^0-9]/g, '');
		var ilabel = nodes[i].parentNode.parentNode.getElementsByTagName("label");
		if(ilabel[0]) {
			if(!nodes[i].value) nodes[i].value = ilabel[0].innerHTML;
		}
		nodes[i].onfocus = function () {focusForm(this)}
		nodes[i].onblur = function () {blurForm(this)}
	}

	var ta = document.getElementsByClassName("inc",formId,"textarea");
	for(var i = 0; i < ta.length; i++) {
		//hides[i].style.display = "none";
		//var alId = hides[i].id.replace(/[^0-9]/g, '');
		var ilabel = ta[i].parentNode.parentNode.getElementsByTagName("label");
		if(ilabel[0]) {
			if(!ta[i].innerHTML) ta[i].innerHTML = ilabel[0].innerHTML;
		}
		ta[i].onfocus = function () {focusTa(this)}
		ta[i].onblur = function () {blurTa(this)}
	}

	var cform = document.getElementById(formId);
	cform.onsubmit = function () {sendForm(this)}
	
}

function focusForm(nod){
	var ilabel = nod.parentNode.parentNode.getElementsByTagName("label");

	if(nod.value == ilabel[0].innerHTML){
		nod.value = '';
	}
}

function blurForm(nod){
	var ilabel = nod.parentNode.parentNode.getElementsByTagName("label");
	if(nod.value == ''){
		nod.value=ilabel[0].innerHTML;
	}
}

function focusTa(nod){
	var ilabel = nod.parentNode.parentNode.getElementsByTagName("label");

	if(nod.innerHTML == ilabel[0].innerHTML){
		nod.innerHTML = '';
	}
}

function blurTa(nod){
	var ilabel = nod.parentNode.parentNode.getElementsByTagName("label");
	if(nod.innerHTML == ''){
		nod.innerHTML=ilabel[0].innerHTML;
	}
}

function sendForm(cform){
	var nodes = document.getElementsByClassName("inc",cform.id,"input");
	for(var i = 0; i < nodes.length; i++) {
		var ilabel = nodes[i].parentNode.parentNode.getElementsByTagName("label");
		if(nodes[i].value == ilabel[0].innerHTML) nodes[i].value = "";
	}

	var ta = document.getElementsByClassName("inc",cform.id,"textarea");
	for(var i = 0; i < ta.length; i++) {
		var ilabel = ta[i].parentNode.parentNode.getElementsByTagName("label");
		if(ta[i].innerHTML = ilabel[0].innerHTML) ta[i].innerHTML = "";
	}
}




