/* tooltip */
var index_url = '/';
$(document).ready(function(){
	$('a').tooltip({
		showBody: " - ",
		showURL: false
	});

});

/* box podobne */

$(document).ready(function(){
	$("#podobne_a").toggle(function(){
		$("#podobne_a").css({backgroundImage:'url(../public/img/default/strzala1.gif)'});
		$("#podobne").animate({ height: 'show', opacity: 'show' }, 'fast');
		var d = $("#podobne_a").attr('rel');
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=similar",
			data: "category="+d ,
			dataType: "text",
			beforeSend: function() {
				$("#podobne").html('<img src="../public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#podobne").html('Blad');
			},
			success: function(data) {
				$("#podobne").html(data);
			}
		});
		return false;

	},function(){
		$("#podobne_a").css({backgroundImage:'url(../public/img/default/strzala2.gif)'});
		$("#podobne").animate({ height: 'hide', opacity: 'hide' }, 'fast');
	});
});

/* glosowanie gwiazdki wywolanie */

$(document).ready(function() {
	var i = parseFloat($('#star1').html());
	$('#star1').rating(index_url+'index.php?module=ajax&action=glosowanie&name='+$("#dodajulubione").attr('rel'), {maxvalue:5,curvalue:i,increment:.5});
});

/* dodaj do ulubionych */

$(document).ready(function() {

	$("#dodajulubione").click(function(e){
		var d = $("#dodajulubione").attr('rel');
		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=favorite&name="+d,
			data: "name=" + d,
			dataType: "text",
			beforeSend: function() {
				$("#dodajulubione").html('<img src="../public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#dodajulubione").html('Blad');
			},
			success: function(data) {
				$("#dodajulubione").html(data);
			}
		});
		return false;
   });

   	$("#pokazUlubioneA").toggle(function(e){
		$("#pokazUlubione").slideDown('fast');
		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=favoriteList",
			data:"box",
			dataType: "text",
			beforeSend: function() {
				$("#pokazUlubione").html('  <img src="'+index_url+'/public/img/default/loader_w.gif" alt="" />');
			},
			error: function() {
				$("#pokazUlubione").html('Blad');
			},
			success: function(data) {
				$("#pokazUlubione").html(data);
					$('a').tooltip({showBody: " - ",showURL: false});
			}
		});
		//return false;
   },function(){
		$("#pokazUlubione").html('');
   });
    $("#pokazZnajomychA").toggle(function(e){
		$("#pokazZnajomych").slideDown('fast');
		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=friendsList",
			data:"box",
			dataType: "text",
			beforeSend: function() {
				$("#pokazZnajomych").html('  <img src="'+index_url+'/public/img/default/loader_w.gif"  alt="" />');
			},
			error: function() {
				$("#pokazZnajomych").html('Blad');
			},
			success: function(data) {
				$("#pokazZnajomych").html(data);
			}
		});
		return false;
   },function(){
		$("#pokazZnajomych").html('');
   });

	$("#dodajznajomego").click(function(e){
		var d = $("#dodajznajomego").attr('rel');
		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=friends&name="+d,
			data: "name=" + d,
			dataType: "text",
			beforeSend: function() {
				$("#dodajznajomego").html('<img src="../public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#dodajznajomego").html('Blad');
			},
			success: function(data) {
				$("#dodajznajomego").html(data);
			}
		});
		return false;
   });

/* zglos problem */
	$("#problem").toggle(function(e){
		$("#problemBox").slideDown('fast');
		return false;
   },function(){
		$("#problemBox").slideUp('fast');
   });

  	$("#sProblem").click(function(e){
		var name = $("#aProblem").val();
		var info = $("#aProblemInfo").val();
		var aUrl = $("#dodajulubione").attr('rel');

		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=problem",
			data: {"alert_subject": name,"alert_text":info,"game_url":aUrl},
			dataType: "text",
			beforeSend: function() {
				$("#iInfo").html('<img src="'+index_url+'public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#iInfo").html('Blad');
			},
			success: function(data) {
				if(data != 'blad'){
					$("#problemBox").html(data);
				} else {
					$("#iInfo").html('Błąd !!<br /><br />');
				}
			}
		})
		return false;
   });

/* zglos komentarz */

	$(".zglos-komentarz").click(function(e){
		return false;
   });



/* dodaj tytul */

  	$("#saddName").click(function(e){
		var Name = $("#aName").val();
		var Url = $("#aUrl").val();

		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=addName",
			data: {"game_name": Name, "game_url":Url},
			dataType: "text",
			beforeSend: function() {
				$("#iInfo").html('<img src="'+index_url+'public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#iInfo").html('Blad');
			},
			success: function(data) {
				$("#iContainer").html(data);
			}
		})
		return false;
   });

/* dodawanie img w komentarzu */
	$("#pokazImgA").toggle(function(e){
		$("#pokazImg").slideDown('fast');
		return false;
   },function(){
		$("#pokazImg").slideUp('fast');
   });

/* wysuwanie okienka z dodawniem tagow */
	$("#pokazTagA").toggle(function(e){
		$("#pokazTag").slideDown('fast');
		return false;
   },function(){
		$("#pokazTag").slideUp('fast');
   });

/* dodaj tag */

  	$("#addTag").click(function(e){
		var Url = $("#addTag").attr('rel');
		var tag = $("#tag").val();

		// wysylamy do plika

		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=addTag",
			data: {"game": Url,"tag": tag},
			dataType: "text",
			beforeSend: function() {
				$("#addTag").attr('disabled','disabled');
				$("#iInfoTag").html('<img src="'+index_url+'public/img/default/loader_w.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#iInfoTag").html('Blad');
			},
			success: function(data) {
                if(data == 'Tag został dodany'){
                    $("#tag").val('');
                }
				$("#iInfoTag").html(data);
			}
		});
		return false;
   });

/* wyslij znajomemu */

  	$("#sEmail").click(function(e){
		var MyEmail = $("#aMyEmail").val();
		var Email   = $("#aEmail").val();
		var Subject = $("#aSubject").val();
		var Text    = $("#aText").val();
		var GUrl    = $("#aGUrl").val();
		var CUrl    = $("#aCUrl").val();

		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=sendToFriend",
			data: {"my_email": MyEmail,"friend_email": Email,"subject":Subject, "email_text":Text, "game_url":GUrl, "category_url":CUrl},
			dataType: "text",
			beforeSend: function() {
				$("#iInfo").html('<img src="'+index_url+'public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#iInfo").html('Blad');
			},
			success: function(data) {
				$("#iContainer").html(data);
			}
		})
		return false;
   });
 });
   /**
    *
    * @access public
    * @return void
    **/
   function comentError(id){
		// wysylamy do plika
		$.ajax({
			type: "POST",
			url: index_url+"index.php?module=ajax&action=commentAlert",
			data: "id=" + id,
			dataType: "text",
			beforeSend: function() {
				$("#zglos-komentarz-"+id).html('<img src=index_url+"public/img/default/loader.gif" style="margin-left:30px;" alt="" />');
			},
			error: function() {
				$("#zglos-komentarz-"+id).html('Blad');
			},
			success: function(data) {
				$("#zglos-komentarz-"+id).html(data);
			}
		});
   }