var delayNews = 5; // v sekundach
var delayNews2 = 10; // v sekundach

var lastActM;
var lastNews;
var newsStat = 0;
var dataActual = "";
var dataNews = "";




$(document).ready(function() {
    dataActual = $('#aktual a');
    $(".sort-up").click(function(){
    	var sort=$(this).attr("name");;
    	$("input[name=sort]").val(sort);
    	$("input[name='asc']").val('ASC');
    	$("#form1").submit();
    });
    $(".sort-down").click(function(){
    	var sort=$(this).attr("name");
    	$("input[name=sort]").val(sort);
    	$("input[name='asc']").val('DESC');
    	$("#form1").submit();
    });
    
    $('.listingpage').click(function(){
    	var list=$(this).attr("name");
    	$("input[name='listing']").val(list);
    	$("#form1").submit();
    });
    
    $('#aktual').html(dataActual[0]);
    animNews(0);
    
    $(".finance").mouseover(function(){
    	var text=$(this).children(".short_text").html();
    	$("#short_text").html(text);
    	$("#short_text").show(0)
    	$("#maintext").hide(0);
    });
    $(".finance").mouseout(function(){
    	$("#short_text").hide(0);
    	$("#maintext").show(0);
    });
    
    
    $(".vystavba").mouseover(function(){
    	var text=$(this).children(".short_text").html();
    	$("#short_text3").html(text);
    	$("#short_text3").show(0)
    	$("#maintext3").hide(0);
    });
    $(".vystavba").mouseout(function(){
    	$("#short_text3").hide(0);
    	$("#maintext3").show(0);
    });
    
    $(".reality").mouseover(function(){
    	var text=$(this).children(".short_text").html();
    	$("#short_text2").html(text);
    	$("#short_text2").show(0)
    	$("#maintext2").hide(0);
    });
    $(".reality").mouseout(function(){
    	$("#short_text2").hide(0);
    	$("#maintext2").show(0);
    });
    
    jQuery.validator.addMethod("phoneCZ", function(phone_number, element) {
        phone_number = phone_number.replace(/\s+/g, ""); 
    	return this.optional(element) || phone_number.length > 10 &&
    		phone_number.match(/^(\+420)??[0-9]{3}?[0-9]{3}?[0-9]{3}$/);
    }, "Neplatné telefonní číslo");



    
    
    
    $("#contactform").validate({ 
		rules: {
			jmeno:{
				required: true,
				minlength: 1
			},
			email:{
				email:true,
				required: true,
				minlength: 1
			},
			telefon:{
				phoneCZ:true,
				required: true,
				minlength: 1
			},
			zprava:{
				required: true,
				minlength: 1
			}
			
		},
	    messages: { 
	        jmeno: '<p style="color:red">Nebyly vyplněny povinné údaje!</p>',
	        email: '<p style="color:red">Špatný formát e-mailu, nebo e-mail nebyl vyplněn!</p>',
	        telefon: '<p style="color:red">Špatné telefonní číslo, nebo telefon nebyl vyplněn!</p>',
	        zprava: '<p style="color:red">Zpráva nebyla vyplněna!</p>'
	    } 
	}); 
    
    $("#chciprodat").validate({ 
		rules: {
			jmeno:{
				required: true,
				minlength: 1
			},
			adresa:{
				required: true,
				minlength: 1
			},
			email:{
				email:true,
				required: true,
				minlength: 1
			},
			telefon:{
				phoneCZ:true,
				required: true,
				minlength: 1
			},
			zprava:{
				required: true,
				minlength: 1
			}
			
		},
	    messages: { 
	        jmeno: '<p style="color:red">Jméno a příjmení nebyli vyplněny!</p>',
	        email: '<p style="color:red">Špatný formát e-mailu, nebo e-mail nebyl vyplněn!</p>',
	        telefon: '<p style="color:red">Špatné telefonní číslo, nebo telefon nebyl vyplněn!</p>',
	        adresa: '<p style="color:red">Adresa nebyla vyplněna!</p>',
	        zprava: '<p style="color:red">Zpráva nebyla vyplněna!</p>'
	    } 
	}); 


    
});

$(function() {
	$('a.lightbox').lightBox({
		fixedNavigation:true,
		txtImage: 'Obrázek',
		txtOf: 'z'
	});
});



function animNews(i){
    if(i >= dataActual.length ) i = 0;
    $('#aktual').css( {top : '-10px', opacity: 0});
    $('#aktual').html(dataActual[i]);
    
    $('#aktual').animate( {top : '0px', opacity: 1}, function(){
        this.newsTimer = setTimeout(function() {
            $('#aktual').animate( {top : '10px', opacity: 0}, function(){
                animNews(++i);
            });
        }, delayNews * 1000);
    });
}


function province(url){
	var id=$("#region").val();
	$("#okres").fadeIn(100);
	$.post(url,{id_region: id, action: "province" }, 
	function(data){
		$("#okres").html(data);
	});
}


