var reel_scroll_count = 1;
var reel_sel = null;
var reel_in_animation = false;

function enableBusinessCinema() {
	$('#divbusiness').css('display','block');
	$('#divstampa').css('display','none');
	$('input[name="Professione_stampa"]').val(''); 
}
function enableStampa() {
	$('#divstampa').css('display','block');
	$('#divbusiness').css('display','none');
	$('input[name="Professione"]').val(''); 
}

function apriGallery(id) {
	var str = '<div id="pop_gallery"><div class="loader"></div></div>';
	
	$.blockUI({ 
		
		css: { 
			backgroundColor:'transparent', 
			border: 'none', 
			color: '#FFF',
			cursor: 'default',
			margin: '0 0 0 -490px',
			left: '50%',
			top: '610px', //'750px',
			height: '414px',
			position: 'absolute',
			width: '980px'
		},

		message: str,
		overlayCSS: {
			cursor: 'default',
			backgroundColor:'#000', 
			opacity:'0.7' 
		},
		onBlock: function(){
			setTimeout(function(){ $('#pop_gallery').load(BASE_URL + 'gallery.php?id='+id); }, 500);
		} 

	});
	
}

function pulisciScomparsa(frm){
	
	$(frm).find('.t').each(function(){
		if(!$(this).hasClass('cliccato'))
			$(this).val('');
	});
	
}

function checkFormAccrediti(){
	
	var status = true;
	var msg = '';
   
	if(!$('input[name="Professione"]').val() && !$('input[name="Professione_stampa"]').val() ){
		msg += "Scegli una professione dal menu Business o Stampa\n";
		status = false;
	}
   
	if(!$('input[name="Nome"]').val() ){
		msg += "Specifica il tuo nome\n";
		status = false;
	}
   
	if(!$('input[name="Cognome"]').val() ){
		msg += "Specifica il tuo cognome\n";
		status = false;
	}
    			
	if(!$('#recaptcha_response_field').val() ){
		msg += "Inserire il codice di sicurezza\n";
		status = false;
	}
	
	if(!status){
		alert("Attenzione\n\n"+msg+"\n");
	}
	
	return status;
}


function checkFormAccreditiEn(){
	
	var status = true;
	var msg = '';
   
	if(!$('input[name="Professione"]').val() && !$('input[name="Professione_stampa"]').val() ){
		msg += "Please pick a Job from one of the menus Business or Press\n";
		status = false;
	}
   
	if(!$('input[name="Nome"]').val() ){
		msg += "Please fill in your Name\n";
		status = false;
	}
   
	if(!$('input[name="Cognome"]').val() ){
		msg += "Please fill in your Surname\n";
		status = false;
	}
    			
	if(!$('#recaptcha_response_field').val() ){
		msg += "Please solve the CAPTCHA security code by copying the 2 words\n";
		status = false;
	}
	
	if(!status){
		alert("Warning\n\n"+msg+"\n");
	}
	
	return status;
}

function checkFormAccreditiLogin(){
	
	var status = true;
	var msg = '';

	if(!$('#form_accrediti input[name="nome"]').val() && !$('#form_accrediti input[name="cognome"]').val()){
		msg += "Specifica il tuo nome/cognome\n";
		status = false;
	}

	if(!$('#form_accrediti input[name="password"]').val()  ){
		msg += "Specifica la tua password\n";
		status = false;
	}
/*	
	if(!$('#recaptcha_response_field').val() ){
		msg += "Inserire il codice di sicurezza\n";
		status = false;
	}
*/	
	if(!status){
		alert("Attenzione\n\n"+msg+"\n");
	}
	
	return status;
}



function checkFormAccreditiLoginEn(){
	
	var status = true;
	var msg = '';

	if(!$('#form_accrediti input[name="nome"]').val() && !$('#form_accrediti input[name="cognome"]').val()){
		msg += "Please fill in your name/surname\n";
		status = false;
	}

	if(!$('#form_accrediti input[name="password"]').val()  ){
		msg += "Please fill in your password\n";
		status = false;
	}
/*	
	if(!$('#recaptcha_response_field').val() ){
		msg += "Please solve the CAPTCHA security code by copying the 2 words\n";
		status = false;
	}
*/	
	if(!status){
		alert("Warning\n\n"+msg+"\n");
	}
	
	return status;
}







$(document).ready(function(){
	
	//--- Link target _blank ---------------------------------------------------------------------
	$('a').each(function(i,a){
		if($(a).attr('rel')=='blank')
			$(a).attr('target','_blank');				 
	});
	
	//--- Input text a scomparsa -----------------------------------------------------------------
	$('.scomparsa').focus(function(){
		if(!$(this).hasClass('cliccato')){
			$(this).attr('alt', $(this).val());
			$(this).val('');
			$(this).addClass('cliccato');
		}
	});
	
	$('.scomparsa').blur(function(){
		
		if($(this).hasClass('cliccato') && jQuery.trim($(this).val()) == ''){
			$(this).val($(this).attr('alt'));
			$(this).removeClass('cliccato');
		}
	});
	
	//
	
	$('.shade_left, .shade_right').css('opacity', 0.7); 
	
	//--- gallery reel ---------------------------------------------------------------------------
	
	/*$('#reel .left, #reel .right').click(function(){
		
		var sel = $('#reel .sel');
		var next = null;
		
		if(!sel.size())
			sel = $('#reel .item').first();
		
		sel.removeClass('sel');
		
		if($(this).hasClass('left')){
			if(reel_scroll_count > 1){
				reel_scroll_count--;
				$('#reel .outer').scrollTo('-=980px', 600, { easing: 'easeOutExpo' } );
			}
		}else{
			if(reel_scroll_count < ($('#reel .item').size() - 1)){
				reel_scroll_count++;
				$('#reel .outer').scrollTo('+=980px', 600, { easing: 'easeOutExpo' } );
			}
		}
	});

	reel_scroll_count = 3;
	$('#reel .outer').scrollTo('+=1960px', 600, { easing: 'easeOutExpo' } ); */
	
	$('#reel .left, #reel .right').click(function(){
		
		if(reel_in_animation) return;
		
		var first = $('#reel .inner .item').first();
		var last = $('#reel .inner .item').last();
		reel_in_animation = true;
		
		if($(this).hasClass('left')){
			last.css('left', parseInt(first.css('left'), 10) - 980).prependTo('#reel .inner');
			$('#reel .inner .item').animate({'left': '+=980'},{ duration: 600, easing: 'easeOutExpo', complete: function(){
				reel_in_animation = false;
			}});
		}else{
			first.css('left', parseInt(last.css('left'), 10) + 980).appendTo('#reel .inner');
			$('#reel .inner .item').animate({'left': '-=980'},{ duration: 600, easing: 'easeOutExpo', complete: function(){
				reel_in_animation = false;
			}});
		}
	});
	

	//--- menu -----------------------------------------------------------------------------------
	
	$('#menu .item_top').mouseenter(function(){
		$(this).find('.submenu').slideDown(500, 'easeInOutExpo');
	}).mouseleave(function(){
		$(this).find('.submenu').slideUp(500, 'easeOutExpo');
	});
	
	//--- gallery film ---------------------------------------------------------------------------
	
	$('.gallery .more').click(function(){
		
		var gallery = $(this).parents('.gallery');
		var sel = gallery.find('.sel');
		var next = null;
		
		if(!sel.size())
			sel = gallery.find('.item').first();
		
		sel.removeClass('sel');
		
		next = sel.next('.item');
		if(!next.size()) next = gallery.find('.item').first();
		
		next.addClass('sel');
		gallery.find('.outer').scrollTo(next, 400, {easing: 'easeInOutQuad'});
	});
	
	//--- menu a destra ---------------------------------------------------------------------------
	
	$('#col_right .dropdown').click(function(){
		var obj = $('#'+ $(this).attr('rel') );
		$(this).toggleClass('sel');
		obj.slideToggle(500, 'easeInOutQuad');
	});
	
	
	//--- select box personalizzate ---------------------------------------------------------------
	
	$('.select_box .sel, .select_box .selimg').click(function(){
		var sel = $(this).parent();
		
		if(sel.hasClass('open')){
			sel.find('.options').slideUp(200);
			sel.removeClass('open');
		}else{
			sel.find('.options').slideDown(200);
			sel.addClass('open');
		}
		
	});
	
	$('.select_box .options a').click(function(){
		var sel = $(this).parents('.select_box');
		
		sel.find('.value').val( $(this).attr('rel') );
		sel.find('.sel').text( $(this).text() );
		sel.find('.options').slideUp(200);
		sel.removeClass('open');
	});
	
	//--- gallery dettaglio -----------------------------------------------------------------------
	
	$('.box_dettaglio .gallery .inner .item').click(function(){

		$('.box_dettaglio .gallery .areafoto').append('<div class="loader"></div>');

		var sel = $(this);
		var imgurl = $(this).attr('rel');
		
		if($(this).hasClass('img')){
			$('.box_dettaglio .gallery .areafoto .load').load(function(){
				$('.box_dettaglio .gallery .areafoto .view_video').hide().html('');
				$('.box_dettaglio .gallery .areafoto .view').show();
				
				$('.box_dettaglio .gallery .areafoto .view').attr('src', $('.box_dettaglio .gallery .areafoto .load').attr('src'));
				$('.box_dettaglio .gallery .areafoto .loader').remove();
			}).attr('src', imgurl);
		}
		
		if($(this).hasClass('video')){
			
			$('.box_dettaglio .gallery .areafoto .view').hide();
			$('.box_dettaglio .gallery .areafoto .view_video').show();
			
			$('.box_dettaglio .gallery .areafoto .view_video').html('<a href="'+imgurl+'" style="display:block;width:497px;height:306px" id="view_video"></a>');
			
			flowplayer("view_video", BASE_URL + "wp-content/themes/riff/swf/flowplayer-3.2.5.swf", {
				clip: {
					autoPlay: false,
					autoBuffering: true
				},
				controls: {
					backgroundColor: '#000000',
					autoHide: true
				}
			});
			
			$('.box_dettaglio .gallery .areafoto .loader').remove();
			/*$('.box_dettaglio .gallery .areafoto .load').load(function(){
	
				$('.box_dettaglio .gallery .areafoto .view').attr('src', $('.box_dettaglio .gallery .areafoto .load').attr('src'));
				$('.box_dettaglio .gallery .areafoto .loader').remove();
			}).attr('src', imgurl);*/
		}
	});
	
	if( $('.box_dettaglio .gallery .inner').children().size() > 6){
		$('.box_dettaglio .gallery .outer').mousemove(function(e){
															   
			var pos = e.pageX - $(this).offset().left;
			var perc = Math.round( ((pos * 100) / $(this).width()));
			var offset = - Math.round(($('.box_dettaglio .gallery .inner').width() - $(this).width()) / 100 * perc);

			$('.box_dettaglio .gallery .inner').css('left', offset);
		});	
	}
	
	//--- NL -------------------------------------------------------------------------------------
	
	function iscrivitiNl(){
		
		var txt = $('#nl_footer .txt');
		var email = txt.val();
		var lingua = $('#nl_footer .lingua').val();
		
		if(email.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i)){
			
			txt.val('inserimento...');

			$.get(BASE_URL + 'subscribe.php?email='+email+'&lingua='+lingua , function(data){
				txt.val('iscrizione avvenuta!');
				txt.removeClass('cliccato');
			});
		}
	}
	
	$('#nl_footer .txt').keypress(function(e){
		
		if(e.which == 13){
			e.preventDefault();
			iscrivitiNl();
		}
	});
	
	$('#nl_footer .vai').click(function(e){
		iscrivitiNl();
	});
	
	
	
	
	
});
