<!--

$(document).ready(function(){

	// pngFix for IE 6

	$(document).pngFix('/images/fix/blank.gif');

	

	// account fields

	$('.field').example(function() {

		return $(this).attr('title'); 

	},{className: 'example'});

	

	// switch to password

	$('#pwd_account_helper').focus(function(){

		$(this).hide();

		$('#pwd_account').val('').show().focus();

	});

	$('#pwd_account').blur(function(){

		if ( $(this).val() == '' || $(this).val() == 'password' ) {

			$(this).hide();

			$('#pwd_account_helper').show().blur();

		}

	});

	

	// activate search

	$('form#catalog_search').find('a').click(function() {

		if ( $('input[name="type_search"][value="sito"]').is(':checked') ) {

			window.location = '/it/ricerca?g_search=' + $('#catalog_text').val();

		}else{

			window.location = '/it/catalogo?browse_by=search&query=' + $('#catalog_text').val();

		}

		return false;

	});

	$('form#catalog_search').submit(function(){

		if ( $('input[name="type_search"][value="sito"]').is(':checked') ) {

			window.location = '/it/ricerca?g_search=' + $('#catalog_text').val();

		}else{

			window.location = '/it/catalogo?browse_by=search&query=' + $('#catalog_text').val();

		}

		return false;

	});

	

	// footer search

	$('#footer_search').submit(function(){

		window.location = '/it/ricerca?g_search=' + $('#footer_search_text').val();

		return false;

	});

	

	// shopping cart

	$('.show_shopping_cart').click(function(e) {

		if (Camargue.modals['shopping_cart']) {

			Camargue.modals['shopping_cart'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_green'});

		fv.addToSet('/modals/shopping_cart.php', 'Carrello', '', {width: 550, height: 410});

		fv.open(0);

		Camargue.modals['shopping_cart'] = fv;

		return false;

	});
	
	
	// Trial demo adda

	$('.show_trial_request').click(function(e) {

		if (Camargue.modals['trial_adda']) {

			Camargue.modals['trial_adda'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_green'});

		fv.addToSet('/modals/trial_adda.php', 'Trial', '', {width: 550, height: 410});

		fv.open(0);

		Camargue.modals['trial_adda'] = fv;

		return false;

	});
	

	// adda terms & privacy

	$('.adda_terms, .adda_privacy').click(function(e) {

		if (Camargue.modals['adda_terms']) {

			Camargue.modals['adda_terms'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_green'});

		fv.addToSet($(this).attr('href'), $(this).attr('title'), '', {width: 550, height: 410});

		fv.open(0);

		Camargue.modals['adda_terms'] = fv;

		return false;

	});
	

	// wishlist

	$('.show_wishlist').click(function(e) {

		if (Camargue.modals['wishlist']) {

			Camargue.modals['wishlist'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_blu'});

		fv.addToSet('/modals/wishlist.php', 'Lista dei desideri', '', {width: 550, height: 410});

		fv.open(0);

		Camargue.modals['wishlist'] = fv;

		return false;

	});

	

	// login

	$('#header_login_button').click(function(){

		$('#account_login').submit();

		return false;

	});

	$('#account_login').submit(function(){

		remote_authentication();

		return false;

	});

	function remote_authentication(){

		$.ajax({

			type: 'POST',

			url: '/modals/login.php',

			cache: false,

			data: 'action=remote_login&email_account=' + $('#email_account').val() + '&pwd_account=' + $('#pwd_account').val(),

			success: function(html){

				if ( $.trim(html) != 'OK' ) {

					if (Camargue.modals['user_login']) {

						Camargue.modals['user_login'].close();

					}

					var fv = new FancyViewer({theme: 'giuntios_green'});

					fv.addToSet('/modals/login.php?msg='+$.trim(html), 'Autenticazione', '', {width: 400, height: 300});

					fv.addToSet('/modals/password_recover.php', 'Recupera password', '', {width: 400, height: 300});

					fv.open(0);

					Camargue.modals['user_login'] = fv;

				}else{

					window.location = window.location;

				}

			},

			error: function(html){

				alert('Si è verificato un errore di connessione. Si prega di riprovare');

			}

		});

	}

	

	//block resize textarea on safari - because need css 3.0

	if(jQuery.browser.safari && parseInt(jQuery.browser.version) >= 522){

		$('textarea').css({'resize':'none'});

	}

	

	// modal login

	$('a.login_modal_open').click(function(){

		if (Camargue.modals['user_login']) {

			Camargue.modals['user_login'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_green'});

		fv.addToSet('/modals/login.php', 'Autenticazione', '', {width: 400, height: 300});

		fv.addToSet('/modals/password_recover.php', 'Recupera password', '', {width: 400, height: 300});

		fv.open(0);

		Camargue.modals['user_login'] = fv;

		return false;

	});

	

	// modal recover pwd

	$('a.recover_modal_open').click(function(){

		if (Camargue.modals['user_login']) {

			Camargue.modals['user_login'].close();

		}

		var fv = new FancyViewer({theme: 'giuntios_green'});

		fv.addToSet('/modals/login.php', 'Autenticazione', '', {width: 400, height: 300});

		fv.addToSet('/modals/password_recover.php', 'Recupera password', '', {width: 400, height: 300});

		fv.open(1);

		Camargue.modals['user_login'] = fv;

		return false;

	});



	// video help
	$("li.account_tutorial a").fancybox({
		'width'				: 791,
		'height'			: 341,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true,
		'padding'			: 0,
		'showCloseButton'	: true
	});
	$("li.account_tutorial a.hd").fancybox({
		'width'				: 932,
		'height'			: 422,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true,
		'padding'			: 0,
		'showCloseButton'	: true
	});

$('a.home_modale').fancybox({
  'width'    : 562,
 'height'   : 393,
  'transitionIn'  : 'none',
  'transitionOut'  : 'none',
  'type'    : 'iframe',
  'centerOnScroll' : true,
  'padding'   : 0,
  'showCloseButton' : false,
  'scrolling': 'no'
 });


	// feedback sidebar
/*
	$("#side_feedback a.fb_open").fancybox({
		'width'				: 600,
		'height'			: 490,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true
	});
*/
	// feedback sidebar close
/*
	$("#side_feedback a.fb_close").fancybox({
		'width'				: 550,
		'height'			: 200,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true
	});
*/
	
	// video help sidebar
/*
	$("#side_help a").fancybox({
		'width'				: 791,
		'height'			: 391,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true,
		'padding'			: 0,
		'showCloseButton'	: true
	});
*/
	
	//script per mandare a capo gli URL o href troppo lunghi by L //

	if($("#content_sidebar").find("p").find("a")){
	target=$("#content_sidebar").find("p")
	l_max= target.innerWidth();			   
	l= target.find("a").innerWidth();
		if(l > l_max){
			stringa= target.find("a").html();
			l_stringa=stringa.length
			// calcolo il numero di caratteri che entrano nella larghezza del paragrafo basato sui caratteri effettivamente presenti nel <p>//
			l_stringa_max=(l_stringa*(l_max-20))/l;
			////////////////
			result= stringa.substring(0,l_stringa_max)+"<br>"+stringa.substring(l_stringa_max);
			//alert(result);
			target.find("a").empty();
			target.find("a").append(result);
		}
	}
	
	// glossary tooltip
	/*
	var settings_tooltip = {

		effect: 'slide',

		lazy: false,

		fadeOutSpeed: 500,

		delay: 30,

		predelay: 100,

		relative: true,

		position: "top center",

		relative:false,

		offset: [15, 0]

	};

	$('span.man_tooltip').tooltip(settings_tooltip);
*/

	// flipbook link
	$(".flipbook_link").fancybox({
		'width'				: 900,
		'height'			: 600,
		'type'				: 'iframe',
		'centerOnScroll'	: true,
		'padding'			: 0,
		'showCloseButton'	: true,
		'titleShow'			: false
	});
	
	// Set default homepage
	$('#set_default_home, li.account_sethome a').click(function(){
	
		if($.browser.msie) {
			this.style.behavior='url(#default#homepage)';
			this.setHomePage('http://www.giuntios.it');
			return false;
		}
		
	});
	$('#set_default_home, li.account_sethome a').fancybox({
		'width'				: 562,
		'height'			: 537,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: true,
		'padding'			: 0,
		'showCloseButton'	: true
	});


});

//-->

