/**
  *	Głowny plik javascript do oblugi clip.pl
  *	(c) 2008 Netstel Software
  *
  *	Paweł Sośnicki <pawel@sosnicki.pl>
  */
  
/**
  *	Laduje liste gier do gamelist
  *
  */
function LoadGames(module, game_category_id) {
	$('div#gamelist div.loader').show();
	$.ajax({
		url: '/request/games/show_gamelist/' + module + '/' + game_category_id,
		data : {'x' : 'load' },
		success: function(html){
			$("div#gamelist div.list").html(html);
			$('div#gamelist div.loader').hide();
		}
	})
};

/**
  *	Wystawia ocene dla gry
  *
  */
function RateGame(GameId, Rate) {
	if(Rate > 0 && Rate <= 5) {
		$.ajax({
			url: '/request/games/rategame/' + GameId + '/' + Rate + '/',
			success: function(html){
				$("div#rates").html(html);
			}
		})	
	}
	return(true);
}

/**
 *	Dodaje grę do ulubionych gier użytkownika
 *
 */
function AddToMyFavoriteGames(GameId) {
	$("div#my_game").html('Trwa dodawanie...');
	$.ajax({
		url: '/request/games/add_favorite/' + GameId + '/',
		success: function(html){
			$("div#my_game").html(html);
		}
	})	
	return(true);
}
 
/**
  *	Po zaladowaniu drzewa DOM odpalamy wszystkie akcje
  *
  */
$(document).ready(function() {
	$('body.home div.column div.handler').hover(
		function(){
			$(this).parent().find('.info').fadeIn(1000);
			$(this).parent().find('.image').animate(
				{width: 150}, 
				1000
			);			
		},
		function(){
			$(this).hide();
			$(this).parent().find('.info').fadeOut(500);
			$(this).parent().find('.image').animate(
				{width: 400},
				500,
				null,
				function() {
					$(this).parent().find('.handler').show();
				}
			);
		}
	);
	
	$('body.home div.ksw_row div.handler').hover(
			function(){
				$(this).parent().find('.info').fadeIn(1000);
				$(this).parent().find('.image').animate(
					{width: 350}, 
					1000
				);			
			},
			function(){
				$(this).hide();
				$(this).parent().find('.info').fadeOut(500);
				$(this).parent().find('.image').animate(
					{width: 800},
					500,
					null,
					function() {
						$(this).parent().find('.handler').show();
					}
				);
			}
		);
	
	$('li').hover(
		function() {
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	);		

	$('ul.submenu li').hover(
		function() {
			$(this).find('ul.subsubmenu').show();
		},
		function() {
			$(this).find('ul.subsubmenu').hide();
		}
	);
});



/**
  *	Sprawdza czy obiekt ma zdefiniowana wlanosc
  *
  */
function isdefined(object, variable) {
	return (typeof(eval(object)[variable]) == "undefined")? false: true;
}


Shoutbox = function() {
    return {
		init	: function() {
			$(document).ready(function(){
				Shoutbox.Refresh();
				setInterval(function(){ Shoutbox.Refresh(); }, 10000);
				$.ajaxSetup({
				  global: false,
				  type: "POST"
				});		
				$('input#shoutbox-message').focus(function() {
					$(this).val('');
				});
			});		
		},
		DeleteMsg		:	function(id){
			$('div#shoutbox-progress').show();
			$.ajax(
				{ 
					url		: "/request/shoutbox/delete/" + id + "/",
					async	: true,
					data	: { "data[index]" : '1'},
					success	: function() {
						Shoutbox.Refresh();							
					}
				}
			);				
		},
		Refresh	:	function(){
    			return (true);
			$('div#shoutbox-progress').show();
			var d = new Date();
			$('div#shoutbox-window').load(
				'/shoutbox/?' + d.getDate() + d.getHours() + d.getMinutes() + d.getMilliseconds(), 
				function(){ 
					$('div#shoutbox-window')[0].scrollTop = $('div#shoutbox-window')[0].scrollHeight;
					$('div#shoutbox-progress').hide();
				}
			);
		},
		WriteMsg	:	function(){
			if($('input#shoutbox-message').val() == "Twoja wiadomość") {
				return(false);
			}
			$('div#shoutbox-progress').show();
			data = $('input#shoutbox-message').fieldSerialize();
			$('input#shoutbox-message').val('');
			$.ajax(
				{ 
					url		: "/shoutbox/add/",
					dataType	: 'html',
					data	: data,
					success	: function() {
						Shoutbox.Refresh();							
					}
				}
			);
			Shoutbox.Refresh();				
		}														
    };
}();
Shoutbox.init();
