$(document).ready(function() {
if($('input#sarat9_city').length >0){
	$('input#sarat9_city').autocomplete({
		
		 focus: function(event,ui) 
				  {
						 $('input#sarat9_city').val(ui.item.label);
					  return false;
				  },
		minLength: 2,
		select: function(event,ui) 
				  { 
				  $('input#h_city').val(ui.item.id);
					  $('input#sarat9_city').val(ui.item.label);
					  return false;
					},
		source: 'sarat/editadd/menuajax.php?template=sarel.comuni'
		});
}		
if($('.info-acquisto').length >0){
	$("a.info-acquisto").fancybox({
				'width'				: 660,
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'centerOnScroll'    :  true,
				'type'				: 'iframe'
			});
}

if($('.CNF').length >0){
	$("a.CNF").fancybox({
				'width'				: 660,
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'centerOnScroll'    :  true,
				'type'				: 'iframe'
			});;
}

		
	
$( '.as-button' ).button();
extendLink('.channel-list');
detectPay('.select-pay  .item-pay');
sortCorsi();	

if($('.home-pacchetto').length>0){

	if($('.home-pacchetto h5').length){
	$('.home-pacchetto').removeClass('no-pkg');
	}

}

$('.fake-link-cs').click(function(e){e.preventDefault();});

});// end doc ready

//compra corso
detectPay= function(reference){
	if( $(reference).length > 0){
	$('.select-pay input[type="radio"]').each(function(){
		if($(this).is(':checked')){
			$(this).parent().addClass('active-option');
			$(this).parent().next().show();
		}
	});
	$('.select-pay input[type="radio"]').click(function(){
		if($(this).is(':checked')){
			$('.select-pay label').removeClass('active-option');
			$(this).parent().addClass('active-option');
			$('.item-pay').hide(300);
			$(this).parent().next().show(300);
		}
	});
  }
}
//channel-list home
extendLink=function(reference){
	if( $(reference).length > 0){
		$(reference + ' ul li').each(function(){
			$(this).click(function(){
				location.href= $('.canale-logo',this).attr('href');
			});
		});
	}
}


sortCorsi=function(){
	if($('.palinsesto-action').length >0){
	var where=location.href.split('&masterPage');
	var whereSure= where[0];
	$('.palinsesto-action input[type="radio"]').each(function(){
	$(this).click(function(){
			location.href= whereSure + $(this).attr('value');
		
		});
	
	});
		
	}
	
}
