/* YOUTUBE */
function youtube(id,container,W,H) {
	params = {
		allowfullscreen: 'true',
		allowscriptaccess: 'samedomain',
		wmode: 'transparent'
	};
	attributes = {
		id: container,
		name: container
	};
	callback = function(e) {
		if(e.success) {
			$('#'+e.id).hide();
			setTimeout(function(){
				$('.videoloader').hide();
				$('#'+e.id).fadeIn(1250);
			},20);
		} else {
			alert('Attenzione! Impossible caricare il contenuto');
		}
	}
	swfobject.embedSWF('http://www.youtube.com/v/'+id+'&showinfo=0&fs=1', container, W, H, '9.0.0', false, false, params, attributes, callback);
}

function archiveWebTv(xml) {
	params = {
		allowfullscreen: 'true',
		allowscriptaccess: 'samedomain',
		wmode: 'transparent'
	};
	attributes = {
		id: 'archivio-web-tv',
		name: 'archivio-web-tv'
	};
	flashvars = {
		urlVideoXml: xml
	}
	swfobject.embedSWF(img_dir+'/video-archive.swf?p='+Math.random(), 'archive-webtv', 570, 600, '9.0.0', false, flashvars, params, attributes, false);
	
}


$(function(){ 
	$(document).pngFix();
	$('.input-login').click(function(){
		$(this).val('');
	});
	
	$('.multimedia-link').click(function(){
		var scrolltop = $('#video-title').position().top;
		$('#video-title').show();
		$('div[id*="video_"]').hide();
		window.scrollTo(0,scrolltop);
		
		var href = $(this).attr('href');
		var vid = href.split('watch?v=');
		
		youtube(vid[1],'youtube_'+vid[1],472,343);
		$('#video_'+vid[1]).show();
		
		return false;
	});
	
	$('.video-acm-link').click(function(){
		var scrolltop = $('#video-title').position().top;
		$('#video-title').show();
		$('div[id*="video_"]').show();
		window.scrollTo(0,scrolltop);
		
		var href = $(this).attr('href');
		var id = $(this).attr('id');
		
		videoPlayer('video_acm',href,472,343);
		$('#video_'+id).show();
		$('#video_acm').show();
		
		return false;
	});
	
	$('.esp-view').each(function(){
		$(this).attr('href','javascript:void(0);');
		
		$(this).click(function(){
			$(this).parents('.single-esp').find('.single-esp-dett').slideToggle('normal', function(){
				if($(this).is(':visible')) {
					$(this).parent('.single-esp').find('.esp-view').html('Chiudi');
				} else {
					$(this).parent('.single-esp').find('.esp-view').html('Dettaglio');
				}
			});
		});
	});
});

function viewVideo(y_id, art_id) {
	window.scrollTo(0,360);
	var artTitle = $(art_id).find('.vg-elenco-title').text();
	var artDate = $(art_id).find('.vg-elenco-date').html();
	var artSubTitle = $(art_id).find('.vg-elenco-subtitle').html();
	var artBody = $(art_id).find('.vg-elenco-body').html();
	
	$('#vg-video-main-cont').show();
	
	if(y_id!='') {
		$('#vg-video-container').show();
		$('#vg-video-main-txt').show();
		$('#vg-video-main').removeAttr('style');
		$('#vg-video-main-single-txt').hide();
		
		$('#youtube').hide();
		$('.videoloader').show();
		
		youtube(y_id,'youtube',292,219);
		
		if(artDate!=null){
			$('#vg-video-main-txt').find('.vg-video-main-date').html(artDate);
			$('#vg-video-main-txt').find('.vg-video-main-date').removeClass('hide');
		} else {
			$('#vg-video-main-txt').find('.vg-video-main-date').html('');
			$('#vg-video-main-txt').find('.vg-video-main-date').addClass('hide');
		}
		$('#vg-video-main-txt').find('.vg-video-main-title').html(artTitle);
		artBody!=null?$('#vg-video-main-txt').find('.vg-video-main-body').html(artBody):$('#vg-video-main-txt').find('.vg-video-main-body').html(artSubTitle);
	} else {
		$('#vg-video-container').hide();
		$('#vg-video-main-txt').hide();
		$('#vg-video-main').css('background','none');
		$('#vg-video-main-single-txt').show();
		
		if(artDate!=null) $('#vg-video-main-single-txt').find('.vg-video-main-date').html(artDate);
		$('#vg-video-main-single-txt').find('.vg-video-main-title').html(artTitle);
		artBody!=null?$('#vg-video-main-single-txt').find('.vg-video-main-body').html(artBody):$('#vg-video-main-single-txt').find('.vg-video-main-body').html(artSubTitle);
	}
	
}

function videoPlayer(idVideo,url,W,H) {
	var flashvars = {
		//videoUrl: 'http://artcafe.externalcontents.com/dea_edicola_dipingere.flv',
		videoUrl: url,
		autoPlay: 'stop'
	};
	var params = {
		allowScriptAccess: 'sameDomain',
		allowFullScreen: 'true',
		wmode: 'transparent'
	};
	var attributes = {
		id: idVideo,
		name: idVideo
	};
	
	swfobject.embedSWF(img_dir+'/video-player.swf', idVideo, W, H, '9.0.0', false, flashvars, params, attributes);	
}