// JavaScript Document

var lviewedheight = 0;

function property_start() {
	
    $('div.fancy_form:not(.vtrip)').hide();
	
    $('#project').hide();
	
    $('.fancy_form input').add('.fancy_form textarea').change(function() {
	$(this).removeClass('error')
    });
	
    $('.search_slide>p>a').click(function(){
	$(".search_content").slideToggle("slow");
	$(this).toggleClass("active");
	return false;
    });
	
    $('.search_content').slideToggle("fast");
	
    if (bfancybox) {
	
	$('a.gallery').fancybox({
	    'zoomOpacity': true,
	    'overlayShow': true,
	    'overlayOpacity': 0.2,
	    'zoomSpeedIn': 500,
	    'zoomSpeedOut': 500
	});
	
    }
	
    $('ul.utoljara_nezett').children('li').find('div.szeles_photo').css({
	'height': '0px'
    });
	
    $('ul.utoljara_nezett').children('li').hover(
	function () {
	    $(this).contents().find('div.szeles_photo').stop().animate( {
		height:"126px"
	    }, 500 );
	},
	function () {
	    $(this).contents().find('div.szeles_photo').stop().animate( {
		height:"0px"
	    }, 500 );
	});
	
    $('.menu>ul>li').hover(
	function() {
	    $(this).children('span').stop().css({
		'opacity': 0,
		'left': $(this).children('a').offset().left-1,
		'top': $(this).parent().parent().offset().top+33
	    }
	    ).show();
	    $(this).children('span').animate({
		'opacity': 0.95
	    }, 'fast');
	},
	function() {
	    $(this).children('span').stop().animate({
		'opacity': 0
	    }, 'fast',
	    function() {
		$(this).css({
		    'display': 'none'
		});
	    }
	    );
	});

    $('.menu li:not(.selected)>a')
    .fadeTo(1000, 0.5)
    .hover(	function() {
	$(this).stop().css({
	    'opacity': 1
	});
    },
    function() {
	if ($(this).is(':animated')) $(this).stop().fadeTo('fast', 1 ,
	    function() {
		$(this).fadeTo(600, 0.5);
	    });
	else $(this).stop().fadeTo(600, 0.5);
    }
    );
		
    $('.kozepso_fejlec div').hide().fadeTo('fast', 0, function() {
	$('.kozepso_fejlec div').show()
    });
	
    /*$('#languages a').hover( function() {
								
									if ($(this).hasClass('hu')) lang='hu';
									else lang='de';
									$('.kozepso_fejlec div.'+lang).stop().show().fadeTo('slow', 0.7);
									
								}, function() {
								
									if ($(this).hasClass('hu')) lang='hu';
									else lang='de';
									$('.kozepso_fejlec div').stop().fadeTo('slow', 0, function() {$('.kozepso_fejlec div:').hide();});
								
								});*/

    if ($('ul.kereses li div').size()>0) {
		
	$('ul.kereses li div').hide();
		
	$('ul.kereses li').hover(	function(){
	    $(this).children('div')
	    .css({
		'left': $(this).offset().left+40
	    })
	    .css({
		'top': $(this).offset().top+25
	    }).show();
	    $(this).children('span').children('span').hide();
	    $(this).addClass('over');
	    return false;
	},
	function(){
	    $(this).children('div').hide();
	    $(this).children('span').children('span').show();
	    $(this).removeClass('over');
	    return false;
	});
	$('ul.kereses li a:not(.head)').bind('click', function(e){
	    $(this).parent().children('a.selected').removeClass('selected');
	    $(this).addClass('selected');
	    $(this).parent().prev('span').children('span').text($(this).text());
	    return false;
	})
		
    }
	
    $(".slide").slideUp();
    content_show = $(".active").attr("title");
    $("#"+content_show).slideDown();
	
    $("#slider_controller a").click(function () {
			  
	if (!($(this).hasClass("active"))) {
		
	    // switch all tabs off
	    $(".active").removeClass("active");
					   
	    // switch this tab on
	    $(this).addClass("active");
					 
	    // slide all elements with the class 'content' up
	    $(".slide").slideUp();
					  
	    // Now figure out what the 'title' attribute value is and find the element with that id.  Then slide that down.
	    var content_show = $(this).attr("title");
	    $("#"+content_show).slideDown();
		
	}
		
	return false;
	
    });

    $('input#search_id').keypress(function(e) {
	if (e.which == 13) $('#id_search').val('1');
    });
	
	
}

function submit_search_form() {
    form_string="";
    $('ul.kereses a.selected').each(function() {
	if (form_string.length > 0) form_string+='&';
	form_string+=$(this).parent().parent().attr('name')+'='+$(this).attr('name');
    })
    //	window.alert(form_string);
    location.href = "/form/search?"+form_string;
}

function show_form(form_id) {
    $('.fancy_form form').not('#'+form_id).add('#message').hide();
    $('#'+form_id+' textarea').add('#'+form_id+' input').removeClass('error');
    $('#'+form_id).fadeIn('slow');
    $('.fancy_form').slideDown('slow');
}


function submitForm(form_id) {
    $('#message').hide();
    $('#'+form_id).slideUp('fast');
    $('#working').show();
    var postData = $('#'+form_id).serialize();
    $.post('/form/'+form_id+'/', postData);
}

function switch_on_loader() {
	
    if (!$('#top_win').is(':visible')) {
	$('.top_win_content').hide();
	$('.top_win_loader').show();
	$('#top_win').show();
    } else {
	$('.top_win_loader').slideDown('fast');
	$('.top_win_content').slideUp('fast');
    }
    top_win_loader = true;
    hiding_time = -1;
}

function switch_off_loader() {
	
    $('.top_win_loader').slideUp('fast');
    $('.top_win_content').slideDown('fast');
    top_win_loader = false;
/*	if (!top_win_mouse_on) {
		hiding_time = 5000;
//		top_win_hide_it();
	}*/
	
}

function switch_off_top_win(utasitas) {
    if (utasitas) $('#top_win').fadeOut('normal', window.location.reload());
    else $('#top_win').fadeOut('normal');
}

function ajax_process(address, variables) {
	
    if (variables != 0) variables += '&rnd=' + Math.floor(Math.random()*1000000);
    else variables = 'rnd=' + Math.floor(Math.random()*1000000);
    $.ajax({
	type: "POST",
	url: address,
	data: variables,
	beforeSend: switch_on_loader()
    })
	
}

function validateForm(form_id) {

    var error = FALSE;
	
    //console.log('validate NOT_NULL')
    // NOT_NULL validator, input mezo nem lehet �res - k�sobb checkbox stb.
    $('#'+form_id+' input.NOT_NULL').each(function() {
	$(this).toggleClass( 'error', !validateNotNull($(this).val()));
	error = TRUE;
    });
	
    //console.log('validate VALID_EMAIL')
    // NOT_NULL validator, input mezo nem lehet �res - k�sobb checkbox stb.
    $('#'+form_id+' input.VALID_EMAIL').each(function() {
	$(this).toggleClass( 'error', !validateEmail($(this).val()));
	error = TRUE;
    });
	
    return !error;
	
}

function ajax_submit(form_id, url) {
	
    //console.log('submit');
    /*if (validateForm(form_id))*/ ajax_process(url, $('#'+form_id).serialize());
/*
	$(this).toggleClass( 'error', !validateEmail($(this).val()));

	form = $('#'+id+' input').add('#'+id+' textarea').add('#'+id+' textarea');ajax_process('/ajax/login', jQuery.param(form));
	return false;*/
}

function validateEmail(elementValue){      
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
}

function validateNotNull(elementValue) {
    return elementValue;
}

function ajax_link(address) {
	
    ajax_process(address, 0);
	
}



$(document).ready(function () {
							
    property_start();
						
});