
function peopleFilterCountry()
{
	$.ajax({
		type:	 		"GET",
		url:			"/ranking/ajax-get-cities",
		data: 		{
		  cid: $('#people_filter_country').val()
		},
		success: function(msg)
		{
		   if (!msg.error)
		   {
             $('#people_filter_city').html(msg);
		   } else {
             window.alert(msg.error);
		   }
		}
	});
};

function peopleFilterCity()
{
	$.ajax({
		type:	 		"GET",
		url:			"/ranking/ajax-get-schools",
		data: 		{
		  cid: $('#people_filter_city').val()
		},
		success: function(msg)
		{
		   if (!msg.error)
		   {
             $('#people_filter_school').html(msg);
		   } else {
             window.alert(msg.error);
		   }
		}
	});
};
	
$(document).ready(function(){

	/* ----------------- zakładka ludzie w rankingach ------------------ */
	
	
	
   /*-- zwijanie intro tabs !!! TO DO
	--------------------------------------------------------*/
	
	$('.slideBtn').toggle(function(){  
		stripesHeight = $(".colorfulStripes").height();
		$(".colorfulStripes").height('70px');
		$("#tabs").slideUp(function(){
			titleH1 = $('#introSection h1').text();
			$('#introSection h1').html(titleH1)
			Cufon.replace('#introSection h1');							
		});
		$(this).addClass('down');
		return false;					  
	}, function(){
		$(this).removeClass('down');
		$("#tabs").slideDown(function(){
			$(".colorfulStripes").height(stripesHeight);
		});	
			
	});

	$('.infoBtn').livequery(function(){
		$(this).toggle(function(){
			stripesHeight = $(".colorfulStripes").height();
			$(".colorfulStripes").height('70px');
			$("#tabs").slideDown(function(){
				titleH1 = $('.panelTabs ul li a').text();
				$('#introSection h1').html(titleH1);
				Cufon.replace('#introSection h1');							  
			});
			$(this).addClass('up');
			return false;					  
		}, function(){
			$(this).removeClass('up');
			$("#tabs").slideUp(function(){
				$(".colorfulStripes").height(stripesHeight);	
			});	
		});				 
	});
	
				


   /*-- kolorowe tła belek
	--------------------------------------------------------*/

	
   $('#sidebar').livequery(function(){	
      if ($(this).hasClass('outerAds')){
         var class1 = $(this).attr('class').split(' ');
         $(this).wrap('<div id="sidebarOuter"></div>');
         $(this).parent().append('<div class="outerBox"></div>');
         ads = $(this).children('.ads').html();
         $(this).parent().children('.outerBox').html(ads);
         $(this).children('.ads').remove();
         $(this).parent().addClass(class1[0]);
      }
   });

   $('#wrapper').livequery(function(){
      if ($(this).hasClass('wrapperBorder')){
         $(this).append('<div class="wrapperTop"></div><div class="wrapperBottom"></div>');
      }
   });
	
	
	
   var color = '';
	
   $('.boxSidebar h3, .boxWrapper h3, .boxBlack h3').livequery(function() {
																		 
      //long
      if ($(this).hasClass('blueGreen')) color = ' colorBlueGreen';
      if ($(this).hasClass('blue')) color = ' colorBlue';
      if ($(this).hasClass('blue2')) color = ' colorBlue2';
      if ($(this).hasClass('yellow')) color = ' colorYellow';
		
      //short
      if ($(this).hasClass('pinkFirst')) color = ' colorPink1';
      if ($(this).hasClass('pinkSecond')) color = ' colorPink2';
      if ($(this).hasClass('vsblue')) color = ' vsBlue';
      if ($(this).hasClass('orange')) color = ' colorOrange';
		
      $(this).append('<span class="h3Color '+color+'"></span>');
   });
	
	
   $('.breadcrumbs ul.belt').livequery(function(){
		
		
      $(this).prepend('<li class="firstBg"></li>');
      $(this).append('<li class="lastBg"></li>');
		
      liczba = $(this).children('li').length;
      liczba2 = liczba - 2;
	
		
      if($(this).children('li:eq('+liczba2+')').hasClass('disabled')){
         $(this).children('li.lastBg').addClass('disabled');
      }
		
      if($(this).children('li:eq(1)').hasClass('disabled')){
         $(this).children('li.firstBg').addClass('disabled');
      }
		
   });
	
   $('.breadcrumbs ul.belt > li:not(.firstBg, .lastBg)').livequery(function(){
      $(this).append('<span />');
   });
	
	
   $('#wrap .forumPage h3').livequery(function(){
      if($(this).css('height') > '28px'){
         $(this).css({
            background: '#1F1F20'
         }).addClass('h3Border').children('span').remove();
			
      }
									 
   });
   
   $('.breadcrumbsHelper').livequery(function(){
		if ($(this).length) {
			$('.searchAnnouncements').css({
				bottom: '2px'
			});	
		}
	});
	
   /*-- wysokosc tla w headerze
	--------------------------------------------------------*/
	
   topOff = $("#header").height();
   $("#header .bgX").height(topOff);
	
	
   $('.oneFeedback').livequery(function(){
										 
      oneFeedback1 = $(this).children(".col12").height();
      oneFeedback2 = $(this).children(".col22").height();
	
      if (oneFeedback1 < oneFeedback2) {
         $(this).children(".col12").height(oneFeedback2);
      }
	
   });
	
   /*-- buttons
	--------------------------------------------------------*/
	
   var button = '';
   var float = '';
   var btnres = '';
	
  
	
   var icon = '';
   $(".btnS").livequery(function() {
		
      if ($(this).hasClass('add')) icon = ' iconAdd';
		
      if ($(this).hasClass('icons')){
         $(this).append('<span class="icon '+icon+'"></span>');
         $(this).css('padding-left', '23px');
      }
								  
   });

   /*-- inne
	--------------------------------------------------------*/
	
   $(".tabsConst #tabs").append('<div class="bottomBg"></div>');
   $(".tabsConst #tabs .panes").append('');
	
	
	
   /*-- toDo list - dodaj nowa pozycje
	--------------------------------------------------------*/

   function addNewToDo() {
      title = $('.addMore .text').val();
      if (title!='') {
         $.ajax({
            type:	 		"POST",
            url:			"/index/ajax-savetodo",
            data: 		{
               todo:title
            },
            success: 	function(msg) {
               if (!msg.error) {
                  $("#divAddTodo").html(msg);
                  $('.addMore .text').val('');
                  rebindTodo();
               } else {
                  window.alert(msg.error);
               }
            }
         });
      }
      return false;
   }


	/*
   $(".addMore a.addNew").click(function(){
      addNewToDo();
      return false;
   });
	
   $(".addMore input.text").bind('keypress', function(e) {
      var code = (e.keyCode ? e.keyCode : e.which);
      if(code == 13) {
         addNewToDo();
         return false;
      }
   });
   */
	
	
   /*-- toDo list - zaznacz checkbox
	--------------------------------------------------------*/
	/*
   $("ul.toDo li > a").livequery(function(){
      $(this).click(function(){
											 
         var checked = 'jqTransformChecked';
         var active = 'active';
         var self = $(this).next().children().find('.jqTransformCheckbox');
			
									
         if (!self.hasClass(checked)){
            self.addClass(checked);
            self.parents('ul.toDo li').addClass(active);
         } else {
            self.removeClass(checked);
            self.parents('ul.toDo li').removeClass(active);
         }
         return false;
      });
   });
	*/
   /*-- toDo list - usun pozycje
	--------------------------------------------------------*/
	
   $("ul.toDo li a.delete").livequery(function(){
	
      $(this).click(function(){
         $(this).parents('ul.toDo li').slideUp(
            function(){
               // AJAX

               $.ajax({
                  type:	 		"POST",
                  url:			"/index/ajax-deletetodo",
                  data: 		{
                     todo:todo
                  },
                  /*dataType:	"json",*/
                  success: 	function(msg) {
                     if (!msg.error) {
                        $("#ulAddTodo").html();
                        rebindTodo();
                     } else {
                        window.alert(msg.error);
                     }
                  }
               });

               $(this).remove();
            }
            );
         return false;
      });
	
   });
		
   /*-- toDo list - pokaż zrobione
	--------------------------------------------------------*/
   /*
   $("a.showDone").livequery(function(){
      $(this).toggle(function(){
			
         activeLi = $(this).parents('.boxSidebar').children('form').children('.toDo').children('li:not(.active)');
         tekst = $(this).text();
         ukryj = 'Pokaż wszystkie zadania';
			
         $(this).text(ukryj);
			
         activeLi.slideUp();
						  
      }, function(){
			
         $(this).text(tekst);
         activeLi.slideDown();
								  
      });
   });
	*/

	
   /*-- opinie ogólne - zakładki zwijanie/rozwijanie
	--------------------------------------------------------*/

   $(".yourRanking .tab a:not(.showMap)").toggle(function(){
											 
      $(this).addClass('slideDownArrow');
      $(this).parent('.tab').next('.tabContent').hide();
	 
		
      return false;
   }, function(){
      $(this).removeClass('slideDownArrow');
      $(this).parent('.tab').next('.tabContent').show();
   });
	
	$('.yourRanking .tab a.showMap').toggle(function(){
		$(this).removeClass('slideDownArrow');
        $(this).parent('.tab').next('.tabContent').show();
	}, function(){
		$(this).addClass('slideDownArrow');
        $(this).parent('.tab').next('.tabContent').hide();	
	}).click(function(){
		map.checkResize();
		var lat = $('#country_lat').val();
		var lng = $('#country_lng').val();
		map.setCenter(new GLatLng(lat,lng));
	});
	
	/*-- wishbox - zwijanie/rozwijanie notek
	--------------------------------------------------------*/
	

	$(".wishBox a.showNote").click(function(){
      current = $(this).text();
		toggle = $(this).attr('title');
      $(this).text(toggle).toggleClass('slides');
      $(this).attr('title',current);
      if ($(this).hasClass('slides')) {
         $(this).parents('.wishBox').find('.notes').slideDown();
      } else {
         $(this).parents('.wishBox').find('.notes').slideUp();
      }
		return false;
	});
	
	/*-- wybor jezyka - rejestracja - active class
	--------------------------------------------------------*/
	
	$("#wrap .langsChoice ul.radioList li a").click(function(){
		$(this).toggleClass('active');				  
	});
	
	
	/*-- wyrowanie wysokosci
	--------------------------------------------------------
	
	$(".usersList ul li").livequery(function(){
		title = $("#wrap .usersList ul li a.titleU").height();
		height = 53 + parseInt(title);
		$(this).height(height);
		$(this).parents('ul').height(height+20);
	});
	*/
	$(".searchPage .col12").livequery(function(){
		col1h = $(this).height();
		col2h = $(this).next().height();
		if (col2h > col1h)
			$(this).height(col2h)
	});
	
	
/*-- opinie ogólne - tabelka
	--------------------------------------------------------*/
	
/*$(".tableContent table tr").click(function(){
		tableCheckbox = $(this).children('td:eq(0)').find('input.checkbox');
		if(!tableCheckbox.attr('checked') == true){
			tableCheckbox.attr('checked', true);
		} else {
			tableCheckbox.attr('checked', false);
		}								   
		return false;
	});*/
	
	$('.iconDown').toggle(function() {
		$(this).addClass('yellowA');	
	}, function() {
		$('.myBox').hide();
		$('.iconDown').removeClass('yellowA');
	});
	
	$('.doBoxClose').click(function(){
		$('.iconDown').removeClass('yellowA');
		return false;
	});
	

		

	

	/*
	$('.showNewsfeed').click(function(){
		$.ajax({
		  url: '/newsfeed',
		  success: function(data) {
			$('ul.newsfeed').html(data);
		  }
		});
		return false;
	});
	*/
	
	$('.modal input[type=reset]').livequery(function(){
		$(this).click(function(){
			$('.modal').hide('fast');
			return false;
		});						 
	});
	
	$('.searchPeople .text').livequery(function(){
		$(this).focus(function(){
			 current = $(this).val();
			$(this).val('');
		}).blur(function(){
			if ($(this).val() == ''){
				$(this).val(current);
			}
		});
	});
	
	
	
	$('.closegMap').livequery(function(){
		$(this).click(function(){
			$(this).parents('.infobox').remove();
			return false;
		});							   
	});
	
	$('#boxLanguage .active a').click(function(){
		$(this).parents('#boxLanguage').hide('fast');
		return false;
	});
	

	


	
	
	function checkstatusto(value, to){
		$.ajax({
			type: "GET",
			url: '/auth/ajax-checkstatusto',
			data: "status="+value+"&to="+to,
			success: function(data){
				$('.checkStatusto').html(data);
			}	   
		});		
	}
	
	function checkstatusfrom(value, from){
		$.ajax({
			type: "GET",
			url: '/auth/ajax-checkstatusfrom',
			data: "status="+value+"&from="+from,
			success: function(data){
				$('.checkStatusfrom').html(data);
			}	   
		});		
	}
	
	$('.inputEState').click(function(){
		value = $(this).val();
		from = $('.erasmFromHid').val();
		to = $('.erasmToHid').val();
		checkstatusto(value, to);
		checkstatusfrom(value, from);
	});
	
	$('.inputEState:checked').livequery(function(){
		var value = $(this).val();
		from = $('.erasmFromHid').val();
		to = $('.erasmToHid').val();
		if(value != '1'){
			$('#erasmUnsetBtn').hide();	
		}
		checkstatusto(value, to);
		checkstatusfrom(value, from);
	});


	$('.checkStatusfrom').bind('change', function(){
		var val = $(this).val();
		$('.erasmFromHid').val(val);
	});

	$('.checkStatusto').bind('change', function(){
		var val = $(this).val();
		$('.erasmToHid').val(val);
	});

	

	 $('.closeMe').click(function(){
		$('.modalMessage').hide('fast');
		return false;
	});
	 
	 $('.coda-nav-left, .coda-nav-right').livequery(function(){
		$(this).click(function(){
			return false;					   
		});
	});
	 
	 
	 
	 
	/*
	$('#formRankingAddOpinion').livequery(function(){
		textClear = $('.textClear').html();
		$(this).submit(function(){
			if(textClear == textClear){
				 $('.textClear').html('');
			}
		});
		$('.textClear').focus(function(){
			$(this).html('');							   
		});
	});
	*/
	
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	$('.cookieClass').toggle(function(){
		createCookie('slide', 'true', 7);										 
	}, function(){
		eraseCookie('slide');
	});
	
	var slidecookies = readCookie('slide');
	
	if ($('body').hasClass('homepage')){
		if (slidecookies){	
			$('#tabs').addClass('hideIt');
			$('.cookieClass').click();
		}
	}
	
	$('input.btn, input.btnBigBlack, input.btnBlack').focus(function() {
		$(this).blur();
	});
	
	$('.btn, .btnBgBigBlack, .btnBlack').mousedown(function() {
		$(this).fadeTo(100, 0.5);
	}).mouseup(function() {
		$(this).fadeTo(100, 1);
	}).mouseout(function() {
		$(this).fadeTo(100, 1);
	});
	

	$('.translatedText').livequery(function(){
		$(this).click(function(){
			$(this).parents('.forumEntry, .col').find('.translateOrg').slideUp(function(){
				$(this).parents('.forumEntry, .col').find('.translateFake').slideDown();
			});
			$(this).hide().prev('.originalText').show();
			return false;
		});
	});
	
	$('.originalText').livequery(function(){
		$(this).click(function(){
			$(this).parents('.forumEntry, .col').find('.translateFake').slideUp(function(){
				$(this).parents('.forumEntry, .col').find('.translateOrg').slideDown();
			});
			$(this).hide().next('.translatedText').show();
			return false;
		});
	});
	
	$('#doLinkLink').livequery(function(){
		  $(this).click(function() {
			 $(this).parent().remove();
			 $('.todoLink').hide();
			 $('.newLink').show();
			 return false;
		  });
	 });
	
	$('.todoCheckbox .checkbox').livequery(function(){
		if ($(this).attr('checked') == true){
			$(this).parent('.todoCheckbox').addClass('checkedBox');	
		}
	});   
	
	function mjquote(stri) {
		
	 	var tempArray = stri.split("\n"), outputArray = [];
  			for (var i = 0, len = tempArray.length; i < len; i++) {
  			var line = tempArray[i].split(" "), num = 0;
   				for (var j = 0, jLen = line.length; j < jLen; j++) {
     				num += line[j].length + 1;
     					if (num >= 80) {
        				num = 0;
        				outputArray[outputArray.length] = "\n>";
     					 } else {
      						outputArray[outputArray.length] = " ";
      					}
      				outputArray[outputArray.length] = line[j];
			    }
    		outputArray[outputArray.length] = "\n";
  			}
  return $.trim(outputArray.join(""));
}

	
	$('.quoteLink').click(function(){
		var quote = $(this).prev('p').text();
		var quoteuser = $(this).parents('.forumPage').find('.userAvatar a:eq(1)').text();
		var quotedate = $(this).parents('.forumPage').find('.userAvatar .small').text();
		$('.quoteContent').val('\n\n'+quoteuser+' ['+quotedate+']:\n>'+mjquote(quote));
		location.replace('#quoteHere');
		return false;
	});
	


	
});


