window.onload = function(){
	if (window.screen.width<=1280) {
		$("#adv").css({display:"none"});
	}
	//ricavo tutti i banner della pagina
	listaBanner = $(".imgBanners");
	for(i=0;i<listaBanner.length;i++){
		urlPhp = "dir=banner&file=upBanner&id=" + listaBanner[i].id;
		$.ajax({
			type: "GET",
			url: "../../blocchi.php?",
			data: urlPhp,
			success: function(msg){
				//alert(msg);
			}
		});
	}
};
//funzione che incrementa il click di un
function salva_dati_video(idBanner){
	op 			= document.getElementById('op').value;
	nome 		= document.getElementById('nome').value;
	descri 		= document.getElementById('descri').value;
	categoria 	= document.getElementById('categoria').value;
	tags 		= document.getElementById('tags').value;
	urlPhp 		= "dir=wall&file=youtube_upload&op="+op+"&nome="+nome+"&descri="+descri+"&categoria="+categoria+"&tags="+tags;
	//alert("blocchi.php?"+urlPhp);
	$.ajax({
		type: "GET",
		url: "../../blocchi.php?",
		data: urlPhp,
		success: function(msg){
			//alert(msg);
			$("#box_yt_load").html(msg);
		}
	});
}
//funzione che incrementa il click di un
function clickBanner(idBanner){
	urlPhp = "dir=banner&file=upBanner&cp=click&id=" + idBanner;
	$.ajax({
		type: "GET",
		url: "../../blocchi.php?",
		data: urlPhp,
		success: function(msg){
			//alert(msg);
		}
	});
}
function redir(url){
	window.location=url;
}
function updatecaptcha() {
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = '../../lib/captcha/immagine.php?' + Math.random();
}

//Funzione che si occupa di postare sulla bacheca in AJAX
function submit_post(){
	if ($("#write_wall").val()!=""||$("#link_video").val()!=""||$("#link_video2").val()!=""||$("#load").val()!=""||$("#divStatus").html()!=""){
	  $('#load-wall').show(); 
		$.ajax({
			type: "POST",
			url: "../../blocchi.php?dir=wall&file=home",
			data: $("#frm-wall").serialize(),
			success: function(msg){
			  $('#load-wall').hide();
				$("#new-post").prepend(msg);
				$("#write_wall").val("");
				$("#write_wall").css({height:"40px"});
				$("label.over").next().blur();
				close_attach();
			}
		});
	}
}
//Funzione che si occupa di postare un commento in AJAX
function submit_commento(id_post, file){
	if($("#write_comment-"+id_post).val() != ''){
		$.ajax({
			type: "POST",
			url: "../../blocchi.php?dir=wall&file="+file,
			data: $("#frm-comment-"+id_post).serialize(),
			success: function(msg){
				$("#new-commento-"+id_post).append(msg);
				$("#write_comment-"+id_post).val("");
				$(".write_comment").addClass("hide");
			}
		});
	}
}
//Funzione che si occupa di incrementare di un voto in AJAX
function vota_post(id){
	$.ajax({
		type: "POST",
		url: "../../blocchi.php?dir=wall&file=home",
		data: "id_post="+id,
		success: function(msg){
			if(msg != ''){
				voti = parseInt($("#voti_post_"+msg).html());
				voti = voti + parseInt(1);
				$("#voti_post_"+msg).html(voti);
			}
		}
	});
}
function show_up_video(id){
	$("#box_yt_attach").css({display:"none"});
	$("#box_yt_load").css({display:"none"});
	$("#"+id).css({display:"block"});
	
	if(id = "box_yt_load"){
		var f = document.getElementById('iframe_yt');
		f.src = f.src;
	}
}
//Funzione che apre il Div con il tipo di allegato al post in Wall
function show_attach(id){
	$("#attach-image").css({display:"none"});
	$("#attach-market").css({display:"none"});
	$("#attach-video").css({display:"none"});
	$("#attach-link").css({display:"none"});
	$("#attach-meteo").css({display:"none"});
	$(".attach-image").removeClass("attach-image-on");
	$(".attach-market").removeClass("attach-market-on");
	$(".attach-video").removeClass("attach-video-on");
	$(".attach-link").removeClass("attach-link-on");
	$(".attach-meteo").removeClass("attach-meteo-on");
	
	/*$(".attach-meteo").css({display:"none"});
	$(".attach").css({display:"none"});
	$(".attach-market").css({display:"none"});*/
	if (id=="meteo") {
		$("#flag_meteo").val('1');	
	}
	else {
		$("#flag_meteo").val('');
	}
		
	$(".attach-" + id ).addClass("attach-" + id + "-on");
		
	$("#attach-"+id).css({display:"block"});
	$("#attach-close").css({display:"block"});
	$("#flag").val(id);
}
//Funzione che chiude qualsiasi Div della procedura per allegare
function close_attach(){
	$("#attach-image").css({display:"none"});
	$("#attach-market").css({display:"none"});
	$("#attach-video").css({display:"none"});
	$("#attach-link").css({display:"none"});
	$("#attach-meteo").css({display:"none"});
	
	$(".attach-image").removeClass("attach-image-on");
	$(".attach-market").removeClass("attach-market-on");
	$(".attach-video").removeClass("attach-video-on");
	$(".attach-link").removeClass("attach-link-on");
	$(".attach-meteo").removeClass("attach-meteo-on");
	
	$(".attach").css({display:"block"});
	$("#attach-close").css({display:"none"});
	
	$("#url").val("http://");
	$("#link_video").val("");
	$("#flag").val("");
	$("#flag_meteo").val('');
	//$("#loader").html('<div align="center" id="load" style="display:none"><img src="img/load.gif" /></div>');
}

//Mostra i commenti successivi ai 3 mostrati di default
function more_comment(id){
	$(".comm-hidden-"+id).removeClass("hide");
	$("#mostra-commenti-"+id).css({display:"none"});
}

//Funzione che si occupa di mostrare i post in una sorta di paginazione tipo Twitter
$('.more').livequery("click", function(){
	var rel = $(this).attr("rel");
	var ID = $(this).attr("id");
	if(rel){
		$("#more-"+ID).html('<img src="img/load.gif" />');
		$.ajax({
			type: "GET",
			url: "../../blocchi.php?",
			data: rel,
			cache: false,
			success: function(html){
				$("#append_more_posts").append(html);
				$("#more-"+ID).remove(); // removing old more button
			}
		});
	}
	else{
		$(".morebox").html('The End');// no results
	}
	return false;
});
//Modalità recupero password in AJAX [DA FINIRE]
function recupera_password(){
	$.ajax({
		type: "POST",
		url: "../../blocchi.php?dir=utenti&file=recupero_password",
		data: $("#frm-password").serialize(),
		success: function(msg){
			if(msg == 'err_recupero'){
				$('.messaggio').html('Email errata o inesistente');	
			}else{
				$('#form_recupero').hide();
				$('.messaggio').html(msg);	
			}
			
		}
	});
}
//Funzione per sfogliare le immagini di un albun in AJAX
$('.immagine_prev').livequery("click", function(){
	var id=parseInt($('.immagine_prev').attr('rel'));
	//jQuery.queryString(window.location.href, '&id='+id);
	$.ajax({
		type:	"GET",
		url:	"../../blocchi.php?dir=wall&file=dettaglio_img",
		data:	"ajax=1&id="+id,
		success:function(msg){
			$('.bacheca-message').html('');
			$('.bacheca-message').html(msg);
		}
	});
});
$('.immagine_next').livequery("click", function(){
	var id=parseInt($('.immagine_next').attr('rel'));
	//jQuery.queryString(window.location.href, '&id='+id);
	
	$.ajax({
		type:	"GET",
		url:	"../../blocchi.php?dir=wall&file=dettaglio_img",
		data:	"ajax=1&id="+id,
		success:function(msg){
			$('.bacheca-message').html('');
			$('.bacheca-message').html(msg);
		}
	});
});
//funzione per eliminare un immagine dall'album in AJAX
function elimina_immagine(id_blog, id_immagine){
	$.ajax({
		type: "POST",
		url: "../../blocchi.php?dir=wall&file=gestione_album&id="+parseInt(id_blog),
		data: 'id_immagine='+parseInt(id_immagine),
		success: function(msg){
			$('#img-'+id_immagine).remove();
			$('#didascalia-'+id_immagine).remove();
		}
	});
}
/* FUNZIONI PER GENERARE UN ANTEPRIMA (TIPO FACEBOOK) DI UN LINK WEB */
$(document).ready(function(){	
	// delete event 
	$('#attach-link-btn').livequery("click", function(){
		link_l = $('#url-link').val()	;
		link_m = $('#url-meteo').val();
		
		if (isValidURL(link_l)){
			link = link_l;
			flag = "-link";
		}
		else if(isValidURL(link_m)){
			link = link_m;
			flag = "-meteo";
		}
		else link = false;
		
		if(!link)
		{
			alert('Inserirsci un link valido ( compreso http:// ).');
			return false;
		}
		else
		{
			$('#load'+flag).show();
			$.post("../../lib/fb_style_link.php?url="+ link, {
			}, function(response){
				$('#loader'+flag).html($(response).fadeIn('slow'));
				$('.images img').hide();
				$('#load'+flag).hide();
				$('img#1').fadeIn();
				$('#link-img').val($('img#1').attr("src"));
				$('#cur_image').val(1);
			});
		}
	});	
	// next image
	$('#nextFB').livequery("click", function(){
		
		var firstimage = $('#cur_image').val();
		$('#cur_image').val(0);
		$('img#'+firstimage).hide();

		if(firstimage <= parseInt($('#total_images').val()))
		{
			firstimage = parseInt(firstimage)+parseInt(1);
			$('#cur_image').val(firstimage);
			$('img#'+firstimage).show();
			$('#link-img').val($('img#'+firstimage).attr("src"));
		}
	});	
	// prev image
	$('#prevFB').livequery("click", function(){
	
		var firstimage = $('#cur_image').val();
		
		$('img#'+firstimage).hide();
		if(firstimage>0)
		{
			firstimage = parseInt(firstimage)-parseInt(1);
			$('#cur_image').val(firstimage);
			$('img#'+firstimage).show();
			$('#link-img').val($('img#'+firstimage).attr("src"));
		}
		
	});	
	// watermark input fields
	jQuery(function($){
	   
	   $("#url").Watermark("http://");
	});
	jQuery(function($){

		$("#url").Watermark("watermark","#369");
		
	});	
	function UseData(){
	   $.Watermark.HideAll();
	   $.Watermark.ShowAll();
	}

	//COMPORTAMENTO LABEL SOPRA INPUT
	$("label.over").click(function() { // bind click event to link
		$(this).addClass("hide");
		$(this).next().focus();
	});
	$("label.over").next().focus(function() { // bind click event to link
		$(this).prev().addClass("hide");
	});
	$("label.over").next().blur(function() { // bind click event to link
		if(this.value == "") $(this).prev().removeClass("hide");
	});
	$(".show-next").livequery("click",function() { 
		$(this).next().removeClass("hide");
	});
	
	$('#webcams-slide').cycle({ 
		fx:     'scrollHorz',
		autostop:        true,
		autostopCount:   -1,
		timeout: 8000, 
		next:   '#next2', 
		prev:   '#prev2' 
	});
	
	$('.webcams-slide li img').jcaption({
		copyStyle: true,
		animate: false,
		show: {height: "show"},
		hide: {height: "hide"}
	});

	$('.cbox-frame').colorbox({
		innerWidth:"704px", innerHeight:"528", iframe:true
	});
	
	$('.cbox-iframe').colorbox({
		preloading:false,
		//innerWidth:(window.screen.width-150),
		//innerHeight:(window.screen.height-300),
		innerWidth:"1044px", innerHeight:"628",
		iframe:true
	});
	
	$('.cbox').colorbox({
		maxWidth:"704px", maxHeight:"576"
	});
	
	$("#slideshow").easySlider({
		auto: 		true,
		continuous: true ,
		speed:		1000,
		pause:		4000,
		prevId: 		'prevBtn_g',
		nextId: 		'nextBtn_g',

	});

	
	/*$('.slideshow').cycle({
		fx: 		'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	    timeout:	4000
	});*/
	
});	

function isValidURL(url){
	var RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

	if(RegExp.test(url)){
		return true;
	}else{
		return false;
	}
}

/* ### FINE FUNZIONI PER CREARE ANTEPRIMA LINK WEB */
/*----SWF UPLOAD ----*/
var swfu;

window.onload = function() {
	
	var settings = {
		flash_url : "../../uploader/swfupload.swf",
		file_post_name: "Filedata",
		upload_url: "uploader/upload.php",
		post_params: {"PHPSESSID" : phpSessionId},
		file_size_limit : "100 MB",
		file_types : "*.jpg;*.png;*.gif",
		file_types_description : "Immagini",
		file_upload_limit : 100,
		file_queue_limit : 0,
		custom_settings : {
			progressTarget : "fsUploadProgress",
		},
		debug: false,

		// Button settings
		button_image_url: "uploader/images/XPButtonUploadText_61x22.png",
		button_width: 61,
		button_height: 22,
		button_placeholder_id: "spanButtonPlaceHolder",
		
		// The event handler functions are defined in handlers.js
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete	// Queue plugin event
	};
	
	var settings2 = {
		flash_url : "../../uploader/swfupload.swf",
		file_post_name: "Filedata",
		upload_url: "uploader/upload.php",
		post_params: {"PHPSESSID" : phpSessionId},
		file_size_limit : "100 MB",
		file_types : "*.jpg;*.png;*.gif",
		file_types_description : "Immagini",
		file_upload_limit : 100,
		file_queue_limit : 0,
		custom_settings : {
			progressTarget : "fsUploadProgress2",
		},
		debug: false,

		// Button settings
		button_image_url: "uploader/images/XPButtonUploadText_61x22.png",
		button_width: 61,
		button_height: 22,
		button_placeholder_id: "spanButtonPlaceHolder2",
		
		// The event handler functions are defined in handlers.js
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete2	// Queue plugin event
	};
	
	var settings3 = {
		flash_url : "../../uploader/swfupload.swf",
		file_post_name: "Filedata",
		upload_url: "uploader/upload.php",
		post_params: {"PHPSESSID" : phpSessionId},
		file_size_limit : "100 MB",
		file_types : "*.jpg;*.png;*.gif",
		file_types_description : "Immagini",
		file_upload_limit : 100,
		file_queue_limit : 0,
		custom_settings : {
			progressTarget : "fsUploadProgress3",
		},
		debug: false,

		// Button settings
		button_image_url: "uploader/images/XPButtonUploadText_61x22.png",
		button_width: 61,
		button_height: 22,
		button_placeholder_id: "spanButtonPlaceHolder3",
		
		// The event handler functions are defined in handlers.js
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete3	// Queue plugin event
	};
	
	if (document.getElementById("spanButtonPlaceHolder")){
		swfu = new SWFUpload(settings);
	}
	if (document.getElementById("spanButtonPlaceHolder2")){
		swfu = new SWFUpload(settings2);
	}
	if (document.getElementById("spanButtonPlaceHolder3")){
		swfu = new SWFUpload(settings3);
	}
 };
