// F1 front-end/back-end toggle
if (document.all) {
	document.onhelp = function() {
		location.href = 'admin/';
		return false;
	}
} else {
	document.onkeydown = function (evt) {
		if (evt.keyCode == '112') {
			location.href = 'admin/';
			return false;
		}
	}
}

// JQUERY
$(document).ready(function(){

	// PAGINA MARCHI (cms)
	// al mouseover evidenzio il singolo marchio
	if (location.href.indexOf('marchi.php') != -1){
		$('img[hspace][vspace]')
			.wrap('<div class="singoloMarchio" style="float: left">')
		$('.singoloMarchio')
			.css({
				padding: '10px',
				margin: '0 10px'
			})
			.hover(
				function(){
					$(this).css({
						background: '#ffa',
					})
				},
				function(){
					$(this).css({
						background: ""
					})
				}
			)
	}
	
	// ELENCO CATEGORIE (thumb) SE SENZA PRODOTTI
		$("#elencoCat td.empty")
			.find("a:first") // il link che contiene la thumb
				.remove()
				.end()
			.prepend('<div style="width: 101px; height: 151px; margin: 5px auto; background: #ddd"></div>')
			.find("a:first") // il link che contiene il testo
				.removeAttr("href")
				.css({ color: "#777" })
				.hover(
					function(){ $(this).css({textDecoration: "none"}) }
					, function(){ $(this).css({textDecoration: "none"}) }
				)
	
	// VALIDAZIONE FORM CONTATTI
		function formValidation(){
			errorTxt = "";
			var company = $("input[name='f_company']");
			var email = $("input[name='f_email']");
			
			// campo f_company vuoto
			if (company.val() == 0 ) { errorTxt += "- Il campo \'Azienda\' e\' obbligatorio\n" };
			// campo f_email vuoto
			if (email.val() == 0 ) { errorTxt += "- Il campo \'E-mail\' e\' obbligatorio\n" };
			
			// messaggio
			if (errorTxt != "") { alert(errorTxt); return false; }
		};
		$("form[name='contactForm']").submit(formValidation);

	// LINK INDIETRO
	$("a:contains('back')")
		.click(function(){ history.back() })
		.css({ display : "block", margin: "10px 0", cursor: "pointer"} )
		.text("< indietro")
		
	// PNG FIX
	$('img[src$=.png]').ifixpng();
	
	// FACEBOX
	$("a[rel=facebox]").facebox();
	
	// POKER, STATISTICHE
	$('.pokerStats tr[class!="itsMe"]').hover(
		function(){
			$(this).css({
				background: '#eee'
				, color: '#000'
			})
		}
		, function(){
			$(this).css({
				background: ''
				, color: ''
			})
		}
	)
	
	// STILI TABLE cms (visual editor)
		// stile: "marketing"
			// evidenzio la cella contenente un link...
			$("#marketing td > a").parents("td")
				.hover(
					function(){
						$(this).css({ background: "#ffc", cursor: "pointer" });
					}
					, function(){
						$(this).css({ background: "" })
					}
				)
				// ... e cliccandola redireziono all'href del link stesso
				.click(function(){
					location.href = $(this).find("a:first").attr("href");
				})
		// stile: "marketing"
			// evidenzio la cella al passaggio del mouse
			$("#marketing td").hover(
				function(){ $(this).find('td').css({background: '#ffc'}) }
				, function(){ $(this).find('td').css({background: ''}) }
			)	


});
