// JavaScript Document

$(function() {
		
		$("#lightsOff").click(function () {
			$("div#lb-bg:hidden:first").fadeIn("slow");
			$("#lightsOff").fadeOut("slow"); 
			$("#lightsOn:hidden").fadeIn("slow"); 
			return false;
		});
	
		$("#lightsOn").click(function () {
			$("div#lb-bg").fadeOut("slow");
			$("#lightsOn").fadeOut("slow"); 
			$("#lightsOff:hidden").fadeIn("slow"); 
			return false;
		});

	$("#more_div").click(function() {
		$("#div_more").toggle("blind","slow");
		return false;
	});
	
	$('.add-sticky').click(function(){
		
		var unique_id = $.gritter.add({
			// (string | mandatory) the heading of the notification
			title: 'Attention!',
			// (string | mandatory) the text inside the notification
			text: 'Questa azione si può fare unicamente da loggato.',
			// (string | optional) the image to display on the left
			//image: 'http://s3.amazonaws.com/twitter_production/profile_images/132499022/myface_bigger.jpg',
			// (bool | optional) if you want it to fade out on its own or just sit there
			sticky: false, 
			// (int | optional) the time you want it to be alive for before fading out
			time: 2500,
			// (string | optional) the class name you want to apply to that specific message
			class_name: 'my-sticky-class' 
		});
		
		// You can have it return a unique id, this can be used to manually remove it later using
		/*
		setTimeout(function(){
			
			$.gritter.remove(unique_id, { 
				fade: true,
				speed: 'slow'
			});
			
		}, 6000)
		*/
		
		return false;
	
	});

	
	
	$(".form_login").click( function() {
		/*								  
		$("body").append("<div id=\"dlg_form_login\" title=\"Login\"></div>")	
		
		$("#dlg_form_login").dialog({
			zIndex: 1200,
			bgiframe: true,
			autoOpen: false,
			width: 500,
			height: 450,
			modal: true,
			draggable: false,
			resizable: false,
			close: function() {
				$("#dlg_form_login").remove();
			}
		});		
					
		var url = "/_new/frm_userloginregistration.php"
		$("#dlg_form_login").load(url).dialog('open');
		*/
		$(window.location).attr('href', 'http://www.soogames.net/log_in/');
		return false;
	});
	
	
	$(".logout").click(  function() {
		$.ajax({
			type: "POST",
			async: false,
			url: "/_new/sys_login.php?",
			// passaggio di tutti i parametri
			data: "action=logout",
			success: function(html) {
				$("#page_container").prepend(html);
			},
			beforeSend: function(){
				//$("#dlg_game_comment").html("Loading...");
			},
			error: function() {

				//$("#dlg_game_comment").html("Errore AJAX");
			}
		});
		
		return false;
	});
	
});


/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='http://www.soogames.net"+ this.t +"' alt='Image preview' /></p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
