
//var hide_form_label;
var form_show = true;
var form_hide = false;
var form_visible = false;
var hide_form_timer;
var on_form_content;
var hide_form_label = true;
var intro_current = 0;
var intro_slide_interval = 5000;
var intro_interval = setInterval('intro_update()', intro_slide_interval);

$(document).ready(function () {

    $('#contact-form').hover(function () {
        form_hide = false;
    }, function () {
        form_hide = true;
        clearTimeout(hide_form_timer);
        hide_form_timer = setInterval('hide_form()', 500);
    });

    $('#form-side').hover(function () {
        if (!form_visible) {
            show_form();
        }
        form_hide = false;
    }, function () {
        form_hide = true;
        clearTimeout(hide_form_timer);
        hide_form_timer = setTimeout('hide_form()', 500);
    });

    $('#points img').click(function () {
        intro_current = $('#points img').index(this);
        do_intro_update();
    });

    if ($('#left-content').height() > $('#right-content').height()) {
        $('#right-content').height($('#left-content').height());
    }

    $('.send').click(function () {

        if (!checkEmail($('#contact_email').val()) || !$('#contact_text').val()) {
            alert('Musíte vyplnit email a text zprávy');
        }

        if (checkEmail($('#contact_email').val()) && $('#contact_text').val()) {
            //alert('asdasdas');
            $.ajax({
                url: "/form",
                data: "contact_from="        + encodeURIComponent($('#contact_from').val())
                    + "&contact_email="      + encodeURIComponent($('#contact_email').val())
                    + "&contact_phone="      + encodeURIComponent($('#contact_phone').val())
                    + "&contact_company="    + encodeURIComponent($('#contact_company').val())
                    + "&contact_text="       + encodeURIComponent($('#contact_text').val()),
                success: function(msg) {
                    //alert(msg);
                    $('.send').parent().empty().append('<h3 style="padding-top: 10px;">Odesláno</h3>');
                }
            });
        }
        return false;
    });

    $('#contact_email').blur(function () {
        //alert('asdasd');
        //alert(checkEmail($(this).val()));
        if (checkEmail($(this).val())) {
            $('.send').removeAttr("disabled"); 
            $('.send').css('text-decoration', 'underline');
        } else {
            $('.send').attr('disabled', true);
            $('.send').css('text-decoration', 'none');
        }
    });

});

function checkEmail(email) {
	var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
	if (!filter.test(email)) {
		return false;
	}
	return true;
}

function intro_update() {
    intro_current++;
    if (intro_current == intro_images.length) {
        intro_current = 0;
    }

    do_intro_update(intro_current);

}

function do_intro_update() {

    $('#intro .image').fadeOut("fast", function () {
        var path = $('#intro .image').attr('src');
        path = path.substr(0, path.lastIndexOf('/') + 1);

        $('#intro .image').attr('src', path + intro_images[intro_current]);
        $('#intro .image').fadeIn("fast");
        //alert(intro_links[intro_current]);
        $('#intro a:eq(0)').attr('href', intro_links[intro_current]);

        var elm = '#intro #points img:eq(' + intro_current + ')';
        var path = $(elm).attr('src');
        path = path.substr(0, path.lastIndexOf('/') + 1);
        $('#intro #points img').attr('src', path + 'point.png');
        $(elm).attr('src', path + 'point-selected.png');

        $('#intro #info .content').hide();
        $('#intro #info .content:eq(' + intro_current + ')').show();

        clearTimeout(intro_interval);
        intro_interval = setInterval('intro_update()', intro_slide_interval);
    });
}

function hide_form() {
    if (form_hide && form_visible /*hide_form_label && hide_form_content*/) {
        $('#contact-form').hide('slide', { direction: 'right' }, 500, function() {
            form_visible = false;
        });
        clearTimeout(hide_form_timer);
        //hide_form_label = true;
        form_hide = true;
        //form_visible = false;
    }
}

function show_form() {
    //if (!hide_form_content) {
        //alert($('#contact-form').css('display'));
        //if (form_show && !on_form_content) {
            form_visible = true;
            //var p = $('#contact-form').position();
            $('#contact-form').css('left', 822)
                              .css('top', $('#top').height())
                              .show('slide', { direction: 'right' }, 500);
        //}
    //}
}



