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://morzepokoje.pl"; 
	var title = "MorzePokoje.pl"; 

	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; }
}

function startowa() {
    var tytul = 'MorzePokoje.pl';
    var adres = 'http://morzepokoje.pl';
    //FireFox
    if (window.sidebar) {
        window.sidebar.addPanel(tytul, adres, "");
    //IE
    } else if (window.external) {
        window.external.AddFavorite(adres, tytul);
    //Opera
    } else if (window.opera && window.print) {
        var a = document.createElement('a');
        a.setAttribute('href', adres);
        a.setAttribute('title', tytul);
        a.setAttribute('rel','sidebar');
        a.click();
    }
} 

function getMiasta(select_id, url, class_name){
	$("#miasta_list").attr("disabled", "disabled");
    $("#loading_bar").fadeIn("slow");
	var id = $("#"+select_id).val();
			
	$.post(url, { id : id, class_name : class_name },
  	function(data){
    	if(data.length > 0){
    		$("#miasta").html(data); 
    	} else {
    		alert('Coś poszło nie tak');
    	}
    	$("#loading_bar").fadeOut("slow");
    	$("#miasta_list").attr("disabled", false);
  	});
}

$(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("even2");
	$(".wyniki2 tr:odd").addClass("odd2");
	$(".wyniki2 tr").mouseover(function() {
    	$(this).addClass("tr_hover2");
	}).mouseout(function() {
    	$(this).removeClass("tr_hover2");
	});
	
	$(".wyniki tr").mouseover(function() {
    	$(this).addClass("tr_hover");
	}).mouseout(function() {
    	$(this).removeClass("tr_hover");
	});
	
	$("#shout_1").click(function(){
		if($(this).val() == 'nick') $(this).val("");
	});
	
	$("#shout_2").click(function(){
		if($(this).val() == 'tekst') $(this).val("");
	});
	
	$("#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;
		}

		$("#shout_2").val($("#shout_2").val() + emo_text);
	});	
	
	  // Add Scroller Object
  $jScroller.config.refresh = 50;
  $jScroller.add("#suwak","#marquee","left",2,true);
  
  // Start Autoscroller
  $jScroller.start();


	
});

