jQuery.fn.cwQtip = function(stile){
	$(this).qtip( $.extend({style: { name: stile, tip: true }}, baseQtip));
};

$(function() {
	function qTipInit() {
		baseQtip = {
			content: { 
			  text: 'aiuto',
			  title: { 
				text: '', 
				button: 'Chiudi'
			  }
			},
			position: { adjust: { screen: true } },
			show: { delay:0, when: { event: 'click' } },
			hide: { when: { event: 'unfocus' } },
			api: {
				onRender: function() {
					//var qtip = this;
					var a = this.elements.target;
					/*if ($(a).hasClass('jsScheda') && !$(a).data('loaded')) {
						$.get(scheda_url+'personali/scheda/'+$(a).attr('rel'), function(data) {
							$(a).next().html(data);
							qtip.updateContent($(a).next().html());
							$(a).data('loaded', 1);
						});
					} else {*/
						this.updateContent($(a).next().html());
					/*}*/
				}
			}
		};

		$.fn.qtip.styles.cwTip1 = { 
		   width:250,
		   background: '#ffec73',
		   color: '#42210b',
		   title: { 'font-size': '13px', 'color': '#42210b', 'background-color':'#ffd421' },
		   border: {
			  width: 3,
			  radius: 3,
			  color: '#ffce00'
		   }
		};
		
		$.fn.qtip.styles.cwTip2 = {
		   width:500,
		   background: '#bcddf5',
		   color: '#000000',
		   title: { 'font-size': '15px', 'color': '#007fd9', 'background-color':'#aad5f5' },
		   border: {
			  width: 5,
			  radius: 5,
			  color: '#0090cb'
		   }
		};
		
		$("a.qTipCall").cwQtip('cwTip1');
		//$("a.qTip2Call").cwQtip('cwTip2');
	}
	qTipInit();
});

/*
 * @homepage
 * 
 */
function page_home() {
  
  function importo_richiesto_listener() {
    $(this).removeClass('InfoCampo').val('').unbind();
  };

	$(function() {
		/*$("#preventivo_personale_destination").change(function() { 
			switch($(this).val())
			{
				case 'Prestito personale':
					var url = home.destinazioni.prestito_personale;
					break;
				case 'Cessione del quinto':
					var url = '#_';
					break;
				case 'Prestito auto':
					var url = home.destinazioni.prestito_auto;
					break;
				default: return false; break;
			}
			$(this).parents("form").attr("action",url);
		});*/

		$('#preventivo_personale_importo_richiesto').focus().bind('click', importo_richiesto_listener).bind('keypress', importo_richiesto_listener);
	});

};

/*
 * @prestito_personale_result
 * 
 */
function page_result() {
  
	$(function() {	
		$(".jsSlideOptions").click(function() {
			$(this).toggleClass("ExpBt").toggleClass("CollapsBt").parents("fieldset").next("fieldset").slideToggle();
		});
		
		$("tr.ItmPro,tr.InfoPro").hover(toggle_ov, toggle_ov);
		
		$('#IfcM .jsScheda').click(scheda_load).bind('scheda.loaded', scheda_show);
		$('#WinDettagli').dialog({
		  autoOpen: false,
		  modal: true,
		  title: 'Dettagli Offerta', 
		  width: 600, 
		  maxHeight: 600
		});
	});

	function toggle_ov() {
		$(this).toggleClass("ov");
		if ($(this).hasClass("ItmPro")) {
			if ($(this).next().hasClass("InfoPro")) {
				$(this).next().toggleClass("ov");
			}
		} else {
			$(this).prev().toggleClass("ov");
		}
	};
	
	function scheda_load() {
	  var a = this;
	  if (!$(a).data('loaded')) {
      $.get(scheda_url+'personali/scheda/'+$(a).attr('rel'), function(data) {
        $(a).data('loaded', 1).next().html(data);
        $(a).trigger('scheda.loaded');
      });
	  } else {
	    $(a).trigger('scheda.loaded');
	  }
	  
	  return false;
	};
	
	function scheda_show() {
	  $('#WinDettagli').html($(this).next().html()).dialog('open');
	  
	  return false;
	};

};