// JavaScript Document
	
	var pageUrl = document.location.href;
	var sbox = false;
	var interval = true;
	var maps = "http://maps.google.it/maps?q=";
	var spinner_16 = "<img src='/images/layout/spinner_16.gif' />";
	var spinner_32 = "<img src='/images/layout/spinner_32.gif' />";
	var spinner_32_000 = "<img src='/images/layout/spinner_32_000.gif' />";
	var closer = "<div class='alert_closer'></div>";
	
	
	function resizeAll(){
													
		var gap = 420;	
		if($.browser.msie) { gap = 420;}
	
		var content_column_height = $(".main").height() - gap;
		var central_column_height = $(".column.w600").height();
		var right_column_height = $(".column.w200").height();
		
		if(central_column_height > right_column_height){	
			$(".column.w200").css({"min-height": central_column_height});
		}
		if(right_column_height > central_column_height){	
			$(".column.w600").css({"min-height": right_column_height});
		}
		
		//console.log("central:"+central_column_height+" - right:"+right_column_height);
	};
	
	$(window).load(function(){
		resizeAll();
	});
	
	
	function openMaps(q) {
		var maps_link = "<a target='_blank' href='"+maps+q+"'>Vedi Mappa</a>";
		return maps_link;
	}
	
	
	function shareOnTwitter(){
		shareUrl = "http://www.twitter.com/home?status="+pageUrl;
		window.open(shareUrl,'shareOnTwitter','toolbar=0,status=0,resizable=1,width=800,height=600');
	};
	
	/* FACEBOOK COMMUNITY */
	
	function bLogin(){
		FB.login(function(response){
			if(response.session){
				window.location.href=pageUrl;
			}
			else{
				window.location.href=pageUrl;
			}
		});
	};
	
	function bLogout(){
		FB.logout(function(response){window.location.href=pageUrl;});
	};
	
	function bShare(){
		var share = {
			method: 'stream.share',
			u: 'http://www.google.it/'
		};
	
		FB.ui(share, function(response) {console.log(response); });
	};
	
	
	function bStream(){
		FB.ui(
			{
				 method: 'stream.publish',
				 //display: "wall",
				 message: '',
				 attachment: {
					 name: 'Bland App',
					 caption: 'Aggiungi Bland App sul tuo profilo',
					 description: (
						 'L&acute;applicazione ufficiale ' +
						 'che ti consente di rimanere aggiornato sulle le news e sui concerti live della band!'
					 ),
					 href: 'http://www.facebook.com/apps/application.php?id=117767404902233'
				 },
				 action_links: [
					 {text:'Bland Web Site', href:'http://www.bland.it'}
				 ],
				 user_prompt_message: 'Rimani in contatto con Bland App'
			}
			
			/*
			,
			function(response) {
			 if(response && response.post_id) {
				 displayWarning("Pubblicazione sulla Bacheca", "Il post &egrave; stato pubblicato sulla tua bacheca")
			 } else {
				 displayWarning("Pubblicazione sulla Bacheca", "Il post non &egrave; stato pubblicato")
			 }
			}
			*/
			
		);//end FB.ui
		
	};
	
	
	function removeDialog(){$(".panes").remove();}
	
	function displayDialog(title,message,id){
		
		var alert_dialog = "<div class='panes'><div class='alert_shadow'><div class='alert'><div class='dialog_title'>"+title+"</div><div class='dialog_message'>"+message+"</div><div class='dialog_separator'></div><div class='dialog_tools'><span class='b_button' id='dialog_abort'>Annulla</span><span class='b_button def' id='dialog_action'>OK</span></div></div></div></div>";
		
		$("body").append(alert_dialog);
		
		$("#dialog_abort").click(function(){removeDialog();});
		
	};
	
	function displayWarning(title,message,id){
		
		var alert_dialog = "<div class='panes'><div class='alert_shadow'><div class='alert'><div class='dialog_title'>"+title+"</div><div class='dialog_message'>"+message+"</div><div class='dialog_separator'></div><div class='dialog_tools'><span class='b_button' id='dialog_abort'>OK</span></div></div></div></div>";
		
		$("body").append(alert_dialog);
		
		$("#dialog_abort").click(function(){removeDialog(); if(id)$("input"+id).focus().addClass("error");});
		
	};
	
	/*######################*/
	
	
	$(document).ready(function(){
		
		var top_bg = Math.round(7*Math.random());
		$(".top_banner").css({background:"url(/images/w_top_section_"+top_bg+".jpg) no-repeat"});
		
		$(".main_sharer_button").show();
		
		$("#top_home_bt").click(function(){location.href = "http://www.bland.it/";});
		$("#top_promo_bt").click(function(){location.href = "http://itunes.apple.com/it/album/se-poi-ci-ripensi/id368691741";});
		
		
		// SEARCH OPTIONS 
		$(".search_field").focus(function(){
			if($(this).attr("value") == "Cerca"){
				$(this).attr("value", "");
			}
		});
		$(".search_field").blur(function(){
			if($(this).attr("value")==0 ){
				$(this).attr("value", "Cerca");
			}
		});
		
		
		
		$(".search_field").keydown(function(e) {
			
				var name = $(this).val();
				
				if (e.which == 13 ){
					if(name != "" && name.length >= 2){
						searchAll(name);
					}
				}
			
				else { 
					void(0);
				}
				
		});
		
		$(".search_button").click(function(){
			var name = $(".search_field").val();
			if(name != "Cerca" && name != "" && name.length >= 2){
				searchAll(name);
			}
		});
		
		
		$(".search_nav span").click(function(){
			var filter = $(this).attr("title");
			$(".search_nav span").removeClass("selected");
			$(this).addClass("selected");
			if(filter != "all"){
				$("div.filter").hide();
				$("div.filter."+filter).show();
			}
			else{
				$(".search_nav span").removeClass("selected");
				$("div.filter").show();
			}
			resizeAll();
		});
		
		
		function searchAll(name){
		
			window.location.href = "/search/?q="+name;
				
		};
	
		/*
			var sharer_switch = "<div class='sharer_switch'></div>";
			var sharer_mover = "<div class='sharer_mover'></div>";
			var sharer_closer = "<div class='sharer_closer'></div>";
			
			var sharer_name = "<div class='sharer_name'><input type='text' id='sharer_name' /></div>";
			var sharer_email = "<div class='sharer_email'><input type='text' id='sharer_email'/></div>";
			var sharer_femail = "<div class='sharer_femail'><input type='text' id='sharer_femail'/></div>";
			var sharer_response = "<div class='sharer_response'></div>";
			var sharer_sender = "<div id='sharer_sender' title='send email'></div>";
			
			var tell_box = "<div class='tell_box'>"+sharer_name+sharer_email+sharer_femail+sharer_response+sharer_sender+"</div>";
			
			//$("body").prepend("<div class='sharer_box'>"+tell_box+"<div class='sharer_bt'></div>"+sharer_closer+sharer_mover+sharer_switch+"</div>");
			
			//$(".sharer_box .sharer_bt").append("<div class='sharer first'><a name='fb_share' type='button' href='http://www.facebook.com/sharer.php'>Condividi</a></div>");
			
			//$(".sharer_box .sharer_bt").append("<div class='sharer'><a class='pp_share twitter' href='javascript:void(0)' onclick='shareOnTwitter()'><span class='pp_share_text twitter'>Twitter</span></a></div>");
					
			
			$(".sharer_box input").focus(function(){$(".sharer_response").html("").removeClass("error");});
			$(".sharer_box input").keyup(function(){$(this).removeClass("error");$(".sharer_response").html("");});
			$(".sharer_box input").mouseover(function(){if($(this).val() == "")$(this).addClass("error");});
			$(".sharer_box input").mouseout(function(){$(this).removeClass("error");});
			//document.getElementById("sharer_sender").onclick = function(){tellAfriend();};
			
			$(".sharer_closer").attr("title","close widget").click(function(){reset_share();});
			$(".sharer_mover").attr("title","move widget");
			$(".sharer_switch").attr("title","open widget");
			$(".sharer_box").draggable({handle:'.sharer_mover'});
			
			$(".sharer_switch").mouseenter(function(){
				if(interval == true){
					interval == false;
					//window.clearInterval(sh);
				}
			});
			
			$(".sharer_switch").css({cursor:"pointer"}).click(function(){
				if(sbox == false){open_share();}
				else if(sbox == true){close_share();}
			});
			
			//sh = window.setInterval("$('.sharer_box').effect('bounce',{}, 200, close_share)", 8000);
			
			open_share=function(){
				sbox=true;$(".sharer_box").animate({top:"-15px"},180);$(".sharer_switch").attr("title","close widget");
			}
			
			close_share =function(){
				sbox=false;$(".sharer_box").animate({top:"-310px"},180);$(".sharer_switch").attr("title","open widget");
			}
			
			reset_share =function(){
				sbox=false;$(".sharer_box").animate({left:0,top:"-310px"},200);$(".sharer_switch").attr("title","open widget");
				$(".tell_box input").val("").removeClass("error");
				$(".sharer_response").html("").removeClass("error");
				$(".sharer_pop").remove();
			}
			
			tellAfriend = function(){
			
				var name = $("input#sharer_name").val();
				var email = $("input#sharer_email").val();
				var femail = $("input#sharer_femail").val();
				
				var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
					
				if(name.length < 3 || name == ""){
					$("#sharer_name").focus().addClass("error");
					$(".sharer_response").html("Errore nome! Inserisci il nome.").addClass("error");
					return false;
				}
				else if((!email_reg_exp.test(email)) || email == ""){
					$("#sharer_email").focus().addClass("error");
					$(".sharer_response").html("Errore email! Inserisci la tua email.").addClass("error");
					return false;
				}
				else if((!email_reg_exp.test(femail)) || femail == ""){
					$("#sharer_femail").focus().addClass("error");
					$(".sharer_response").html("Errore email! Inserisci l'email del tua amico.").addClass("error");
					return false;
				}
				
				else{
					//alert("Ooops!!! Function disabled!!!");
					
					$.ajax({
						type: "POST",
						url: "/php_script/tell_a_friend.php",
						data: "name="+name+"&email="+email+"&femail="+femail+"&link="+pageUrl,
						beforeSend: function(){
						},
						success: function(response){
							if(response == "success"){
								$(".tell_box input").val("").removeClass("error");
								$(".sharer_response").html("").removeClass("error");
								
								var pop_message = "<div class='pop_message'>Messaggio inviato con successo!</div>";
								var pop_bt = "<div class='pop_bt'>OK</div>";
								$(".sharer_box").append("<div class='sharer_pop'>"+pop_message+pop_bt+"</div>");
								$(".pop_bt").click(function(){reset_share();});
							}
							else{
								$(".sharer_response").html("Messaggio non inviato. Riprova.").addClass("error");
							}
						}
						
					});
					
				}
			};
			*/
		
	});


	
	
	
	
	/*
	function loadAlbum(album, title, featured){
		
		$.ajax({
			type: "POST",
			url: "php/load_gallery.php",
			data: "album="+album+"&title="+title,
			beforeSend: function(){
				$(".albums").removeClass("selected");
				$("#"+album).addClass("selected");
				
				$("#main_photo").remove();
				
				var loader = "<div class='gallery_loading'><img src='/images/colorbox/gallery_loading.gif' /><br/>loading album</div>";
				$("#photogallery_container").append(loader);
			},
			success: function(response){
				
				$("#photogallery_container").html("<div id='main_photo'><div class='album_title'>"+title+"</div>"+response+"</div>");
				
				// FEATURED ALBUM
				if(featured){
					$(".album_title").prepend("<div class='featured_album'>Featured Album</div>");
				}
				
				// PRETTY PHOTO
				$("a[rel^='"+album+"']").prettyPhoto({
					animationSpeed: 'normal', // fast/slow/normal 
					padding: 20, // padding for each side of the picture 
					opacity: 0.7, // Value betwee 0 and 1 
					showTitle: true, // true/false 
					allowresize: true, // true/false 
					counter_separator_label: '/', // The separator for the gallery counter 1 "of" 2 
					theme: 'light_square', // light_rounded / dark_rounded / light_square / dark_square 
					callback: function(){}
				});
				
				
				$("#main_photo img").load(function(){$(this).fadeIn(400);});
				
			}
		});
		
	};
	
	*/
	
	
	
	
	
	
	
	
	
	