var link = '/dean/web/';
function sendForm(div, action){
	var form = $("#"+div);
	if(action) form.attr('action', action);
	form.submit();
}

function implode (glue, pieces) {
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];                tGlue = glue;
            }
            return retVal;
        }
    }    else {
        return pieces;
    }
}

function addToFavorites(){
	var url = "http://fajne-gry.eu"; 
	var title = "Fajne Gry"; 

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

$(document).ready(function(){
	
    $('.tip').mouseover(function(){

  	  var id = this.id;
  	  var tresc = $("#tresc_"+id).html();
  	  
  	  var a = $("#"+id);
	  var offset = a.offset();	
	  
	  $("#info_"+id).remove();
	  $("body").append("<div id=\"info_"+id+"\" class=\"tooltip\" style=\"top:"+(offset.top+20)+"px;left:"+(offset.left+5)+"px;\"></div>");
      $("#info_"+id).html(tresc);
		

    });
    
   	$('.tip').mouseout(function(){
  	  var id = this.id;
  	  var tresc = this.title;	  
	  $("#info_"+id).remove();
    }); 
     
    $(".wyniki2 tr:even").addClass("abc");
	$(".wyniki2 tr:odd").addClass("def");	   	
	$(".wyniki2 tr").mouseover(function() {
    	$(this).addClass("tr_hover");
	}).mouseout(function() {
    	$(this).removeClass("tr_hover");
	});
	

	
	$(".wyniki2 th:first-child").css("border-left", "0px");
 	$(".wyniki2 td:first-child").css("border-left", "0px");
	
    $(".najazd_post:even").addClass("forum_show_def");
	$(".najazd_post:odd").addClass("forum_show_abc");
	$(".najazd_post").mouseover(function() {
    	$(this).addClass("forum_show_tr_hover");
	}).mouseout(function() {
    	$(this).removeClass("forum_show_tr_hover");
	});
		
	$(".wyniki tr td:first-child").addClass("l");
	
	$('#search_field_text').click(function(e){
		if($(this).val() == 'wpisz nazwę gry...') $(this).val("");		
	})	
	$('#login_field_text').click(function(e){
		if($(this).val() == 'login...') $(this).val("");		
	})	
	$('#haslo_field_text').click(function(e){
		
		if($(this).val() == 'hasło...') {
			$(this).replaceWith('<input id="haslo_field_text2" name="haslo" type="password" value=""  class="inputtext1"/>');	
			$('#haslo_field_text2').focus();
		}
	})
	
    $('#haslo_field_text').focus(function(){

  	  	if($(this).val() == 'hasło...') {
			$(this).replaceWith('<input id="haslo_field_text2" name="haslo" type="password" value=""  class="inputtext1"/>');	
			$('#haslo_field_text2').focus();
		}
		

    });
    
    
	if(parseInt($("#ramka_1_tresc").height()) < parseInt($("#ramka_left").height())){
		$("#ramka_1_tresc").height($("#ramka_left").height()+15);
	}
	
	$(".img_gra_tip").mouseover(function(e){
	  var x = e.pageX;
	  var y = e.pageY;
	  
	  if(x > 850){
	  	var left = x - 305;
	  } else {
	  	var left = x + 15;
	  }
  	  var id = $(this).attr('alt');
  	  
  	  var html = $("#gra_tip_"+id).html();
  	  
  	  if($("body>#gra_tip_"+id).length){
		$("#gra_tip_"+id).css({'top' : (y+15), 'left' : left});
  	  } else {
  	  	$("#gra_tip_"+id).remove();
  	  	$("body").append("<div id=\"gra_tip_"+id+"\" class=\"gra_tip\" style=\"top:"+(y+15)+"px;left:"+(x+15)+"px;\">"+html+"</div>");	
  	  }
  	  $("#gra_tip_"+id).show(); 
    });
    
    $(".img_gra_tip").mousemove(function(e){
      var x = e.pageX;
	  var y = e.pageY;
	  
	  if(x > 850){
	  	var left = x - 305;
	  } else {
	  	var left = x + 15;
	  }
	  
  	  var id = $(this).attr('alt');
  	  $("#gra_tip_"+id).css({'top' : (y+15), 'left' : left});
    });
   
    $('.img_gra_tip').mouseleave(function(e){
    	
  	  var id = $(this).attr('alt');
  	  $("#gra_tip_"+id).fadeOut();
    }); 
    
    $("#zbior_ikonek img").click(function(){
		var id = $(this).attr('id');
		var emo_text = '';
		switch(id){
			case 'sout_ico0' : emo_text = ' [:)] '; break;
			case 'sout_ico1' : emo_text = ' [:(] '; break;
			case 'sout_ico2' : emo_text = ' [:p] '; break;
			case 'sout_ico3' : emo_text = ' [:D] '; break;
			case 'sout_ico4' : emo_text = ' [:/]'; break;
			case 'sout_ico5' : emo_text = ' [:>] '; break;
			case 'sout_ico6' : emo_text = ' [!!] '; break;
		}

		$("#gra_komentarz_tresc").val($("#gra_komentarz_tresc").val() + emo_text);
	});
});

