
$(function(){
    $(".delme").focus(function(){
        if ($(this).is('input')) {
            var orival = $(this).val();
            $(this).val("");
        }else{
            var orival = $(this).html();
            $(this).html("");
        }
        $(this).blur(function(){
            if(1 || $(this).is('input')){
                if ($(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).val(orival);
                }
            }else{
                if ($(this).html() != "" && $(this).html() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else if ($.browser.safari && $(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).html(orival);
                }
            }

        });
    });
	$(".home .slider").configurableSlider({infiniteMode : true, speed : 800, easing : 'swing', naviContainer : '.slider-nav', slideCallback : function(){
		$('#header .text p').html($('.slider-current-active-element .cat-description').html());
		var href = $('.slider-current-active-element a').attr('href');
		$("#header a.button").attr('href', href);
		var section = $('.slider-current-active-element').attr('id').replace('element-', 'section-');
		$("body").attr('class', section);
	}});
	$('form').submit(function(){
		$.wdbox.alert('Lütfen Bilgileri Istendigi Gibi Giriniz...');
		var theform  = $(this);
		var data = {};
		$('input, textarea, checkbox', theform).each(function(){
			if($(this).hasClass('delme')){
				data[$(this).attr('name')] = '';
			}else{
				data[$(this).attr('name')] = $(this).val();
			}
		});
		if($('input[name=privacy]:not(:checked)', theform).length){
			data['privacy'] = 0;
			$.wdbox.alert('Per inviare la richiesta <br /> devi acconsentire al trattamento dei dati personali <br/><br /> <a class="closeLink"><span>&otimes;</span> chiudi la finestra</a>');
			return false;
		}
		$("input[type=text], textarea", theform).parent('div').removeClass('errored');
		var url = $(this).attr("action");
		$.post(url, data, function(res){
			eval(res);
			if(!res.correct){
				setTimeout(function(){
					$.wdbox.alert(res.message);					
					$.each(res.errors, function(k, v){
						var fcont = $('input[name='+v+'], textarea[name='+v+']', theform).parent('div');
						if(!fcont.hasClass('errored')){
							fcont.addClass('errored');
						}					
					});
				}, 1000);
				
			}else{
				$.wdbox.alert(res.message);
			}
		});
		return false;
	});
	$(".thumb a").lightBox();
});

