$(function(){
	/*
setInterval(function(){
		var style = $("link[rel=stylesheet]:first");
		var href = style.attr("href");
		style.attr("href", href+"?rn="+Math.floor(Math.random()*1100));
		
	}, 1000);
*/

/*Cufon.replace("h1, h2, h3, .featured-entry span, .featured-entry em", {
        hover : true
    });*/

/* Img Border for Firefox */
if($.browser.mozilla){
	$('.post img:not(.entry img, img.biglietteria, .post-slug-biglietteria img, .fscreen-gallery img), .latest-post img, .featured .thumb img').after("<span class='moz-image-border'></span>");
	$('.moz-image-border').each(function(){
		var thespan = $(this);
		var theimg = $(this).prev();
		theimg.load(function(){
			var w = theimg.css("width");
		if(!w){
			w = theimg.width();
			var h = theimg.height();
		}else{
			var h = theimg.css("height");
		}
		thespan.width(w).height(h).css({"backgroundImage" : "url('"+theimg.attr("src")+"')", display : "block"});
		theimg.remove();
		});
	});
}

$('.section-navigation li:has(ul)').addClass('has-children');
if($.browser.version < 8){
    if($.browser.msie){
        DD_roundies.addRule('.featured, .thumb img, .featured-details ul, .module h4, .module-table, .module-title, .calendar', '5px');
    }
}
//$('.fscreen-box img').gallerizr();
$(".fullscreen").click(function(){
//    $(".fscreen-box").appendTo("body");
//    $(".galleria_wrapper").height($("window").height());
//    $('ul.fscreen-gallery').galleria();
//    $(".close").click(function(){
//        $(".fscreen-box").appendTo(".gallery-page");
//    });
    $('.fscreen-box a').gallerizr();
});
//DD_roundies.addRule('#top form input.text', '20px');
//DD_roundies.addRule('.go-to-post', '10px');
$("form#alboform").live('submit', function(){
		theform = $(this);
		if($('input[name=privacy]:not(:checked)', theform).length){
			alert('Per inviare la richiesta \n devi acconsentire al trattamento dei dati personali');
			return false;
		}
		var data = theform.serialize();
		var url = theform.attr("action");
		$.post(url, data, function(res){
			eval(res);
			$('.errorfield', theform).remove();
			$('textarea.errored').removeClass('errored');
			if(!res.correct){
				$.each(res.errors, function(k, v){
					$('textarea[name='+v+']', theform).addClass('errored');
					var fcont = $('input[name='+v+']', theform).parent('div');
					if(!fcont.find('.errorfield').length){
						$('br:last', fcont).before('<div class="errorfield"><span>obbligatorio</span></div>');
					}							
				});
				alert('Il form contiene degli errori, verificare di avere inserito correttamente i dati');
				window.location.hash='alboform';
			}else{
				alert('Il modulo è stato inviato correttamente.');
				$('input:text', theform).val('');
			}
		});
		return false;
	});
});
