var nameDiv="";
var dataForLightBox="";
var cptch="";

var mytool_array;
var myTypeContent;
var myIdContent;
var myIdContentData;
var mediaBHM;
var playerFlash;
var myVote=0;


function apriLightBox(whatPopPup, params,captchaURL)
{
	/*CONTROLLO PRESENZA IN PAGINA VIDEO*/
	if ( $("#videoPlayer").length > 0 ) {
		$("#videoPlayer").css("display","none")
	}
	nameDiv=whatPopPup;
	cptch=captchaURL;
	dataForLightBox=params; // questo valore serve anche a captha
	myWidth = $(window).width();
	myHeight =$(document).height();
	$("#lightBoxArea").css("display","block");
	$("#lightBoxArea").width(myWidth);
	$("#lightBoxArea").height(myHeight);
	$("#lightBoxArea").fadeTo(250, 0.85);
	if(whatPopPup.indexOf('guardailconcerto')!=-1){
		nameDiv=whatPopPup;
		getImgCaptcha('#captchaImg');
	} else if(whatPopPup=='comevotare'){
		nameDiv="comevotare";
	} else if(whatPopPup=='comepartecipare'){
		nameDiv="comepartecipare";
	}  else if(whatPopPup=='votailmigliore'){
		nameDiv="votailmigliore";
		whatWindow=dataForLightBox.split(",");
		if(whatWindow[2]=="news"){
				initCaptcha2();
			} else if(whatWindow[2]=="box"){
				initCaptcha();
			} else if(whatWindow[2]=="video"){
				initCaptcha3();
		}
	}
	else if(whatPopPup=='votook'){
		nameDiv="votook";
	}
	else if(whatPopPup=='bhm'){
		nameDiv="bhmLightBox";
		compileDataOfLightBHMBox();
	}
	else if(whatPopPup=='progressBar'){
		nameDiv="progressBar";
	}


	if(nameDiv!='votailmigliore'){
		setTimeout("viewInterfaces('"+nameDiv+"')", 500);
	} else{
		ceckMyVote();
	}


}


function ceckMyVote(){
	var rand = Math.floor(Math.random()*100000000);
	var defaultPathCeckVote=pathData+"checkvote/?r="+rand;
	var voteStatus=0;
	$.ajax({
	  url: defaultPathCeckVote,
	  cache: false,
	  error:function (){
	  },
	  success: function(html){
	  },
	  complete: function(html){
	  		if (html.status == 200) {
				if (html.responseText.length > 0) {
					myVote=html.responseText;
					if(myVote==1){
						nameDiv="postVotoLightBox"
						setTimeout("viewInterfaces('"+nameDiv+"')", 500);
					} else{
						setTimeout("viewInterfaces('"+nameDiv+"')", 500);
					}
				}
			}
	  }
	});

}


function viewInterfaces(poppup){
	window.scrollBy(0,0);
	//ALLINEO LA FINESTRA DI REGISTRATI
	var posx=(myWidth-$("#"+poppup).width())/2;
	var myWinDimension=$(document).height()-($(document).height()-$(window).height());
	window.scroll(0,0);
	var posy=((myWinDimension-$("#"+poppup).height())/2);
	/*if(posy<0){
		posY=10;
		}*/
//	$("#"+poppup).css("top",posy);
	$("#"+poppup).css("left",posx);
	$("#"+poppup).css("display","block")
}


function chiudiLightBox()
{
	$("#"+nameDiv).css("display","none");
	$("#lightBoxArea").css("display","none");
	$("#videoPlayer").css("display","block");
	if ( $("#videoPlayer").length > 0 ) {
		$("#videoPlayer").css("display","block")
	}
}


function compileDataOfLightBHMBox(){
	mytool_array=dataForLightBox.split(",");
	myTypeContent=mytool_array[0];
	myIdContent=mytool_array[1];
	myIdContentData=mytool_array[2];
	mediaBHM=mytool_array[3];
	playerFlash=mytool_array[4];
	idSms=mytool_array[5];
	switch(myTypeContent){
			case 'ft': 	captureDataBhmFullTrack()
						break;
			case 'sf':	captureDataBhmBackground()
						break;
			case 'vd': 	captureDataBhmVideo()
						break;
		}
	initLightBoxBhm(myIdContentData,myTypeContent,idSms);
}


function captureDataBhmFullTrack(){
	var myVideoBHM=$("#musicaBHMTitleFt"+myIdContent).html();
	var myAutoreBHM=$("#autoreBHMFt"+myIdContent).html();
	var myImageSf=$("#copertinaBHM"+myIdContent).attr("src");
	$("#sfImgBhmFt").attr("src",myImageSf);
	$("#titleContentBhmLightBoxFt").html(myVideoBHM);
	$("#artistContentBhmLightBoxFt").html(myAutoreBHM);
	$("#messageDownload").html("Scarica il brano per il tuo cellulare:");
	if(mediaBHM!=""){
		var stringaFlash="<embed width='400' height='20' flashvars='&file="+mediaBHM+"&autostart=true' allowscriptaccess='always' allowfullscreen='true' bgcolor='#000000' src='"+playerFlash+"'></embed>"
	}else{
		var stringaFlash="";
	}
	$('#flashFullTrackBhmDiv').html(stringaFlash)
	$("#bhmLightBox").css("height","450px");
}


function captureDataBhmBackground(){
	var myImageSf=$("#copertinaBHM"+myIdContent).attr("src");
	$("#sfImgBhm").attr("src",myImageSf);
	$("#messageDownload").html("Scarica lo sfondo per il tuo cellulare:")
	$("#bhmLightBox").css("height","460px");
}


function captureDataBhmVideo(){
	var myAlbumBHM=$("#videoBHMTitle"+myIdContent).html();
	var myAutoreBHM=$("#autoreBHM"+myIdContent).html();
	$("#titleContentBhmLightBox").html(myAlbumBHM);
	$("#artistContentBhmLightBox").html(myAutoreBHM);
	$("#messageDownload").html("Scarica il video per il tuo cellulare:");
	if(mediaBHM!=""){
		var stringaFlash="<embed width='400' height='300' flashvars='&file="+mediaBHM+"&autostart=true' allowscriptaccess='always' allowfullscreen='true' bgcolor='#000000' src='"+playerFlash+"'></embed>"
	} else
		{
		var stringaFlash="";
		}
	$('#flashVideoBhm').html(stringaFlash)
	if(mediaBHM!=""){
	$("#bhmLightBox").css("height","660px");
	} else{
		$("#bhmLightBox").css("height","330px");
		}
}
