function voteManual(id, thumb)
{
	var $ = $J;
	
	$.get('/ajax_handvote.php?action=manual&id='+ id +'&thumb=' + thumb, function(res)
	{
		var get_all_div = res.split("XX");
		document.getElementById('voteDiv').innerHTML = get_all_div[0];
		document.getElementById('thumbUpDivQuestion').innerHTML = get_all_div[1];
		document.getElementById('thumbDownDivQuestion').innerHTML = get_all_div[2];
	});
}

function votePhoto(id, thumb)
{
	var $ = $J;
	
	$.get('/ajax_handvote.php?action=photo&photo='+ id +'&thumb=' + thumb, function(res)
	{
		var get_all_div = res.split("XX");
		document.getElementById('voteDiv').innerHTML = get_all_div[0];
		document.getElementById('thumbUpDivPhoto').innerHTML = get_all_div[1];
		document.getElementById('thumbDownDivPhoto').innerHTML = get_all_div[2];
	});
}

$J = jQuery.noConflict();

$J(window).scroll(function(){
	var $ = $J;
	/* when reaching the element with id "last" we want to show the slidebox. Let's get the distance from the top to the element */
	if($('#last').length == 0)
		return;
	
	var distanceTop = $('#last').offset().top - $(window).height();		
	if  ($(window).scrollTop() > distanceTop){
		$('#slidebox').animate({'right':'0px'},300);
	}else {
		$('#slidebox').stop(true).animate({'right':'-430px'},100);	
	}
});

$J(document).ready(function($) {
	
	$('#badges span').mouseenter(function(){
		$(this).stop().animate({
		    height: 15,
		  }, 300, function() { });
	});
	$('#badges span').mouseleave(function(){
		$(this).stop().animate({
		    height: 0,
		  }, 300, function() { });
	});

	
	$('#slidebox .close').bind('click',function(){
		$(this).parent().remove();
	});
	
	$('.stickQuestion').bind('click',function(){
		var pid = $(this).data('pid');
		var stick = $(this).data('stick');
		
		$.get('/answers.php?pid='+pid+'&stick='+stick, function() { 
			window.location.reload();
		} );
		
		return false;
	});
	
	$('.showQuestionOnSG').bind('click',function(){
		var pid = $(this).data('pid');
		var showOnSG = $(this).data('show');
		
		$.get('/answers.php?pid='+pid+'&showOnSG='+showOnSG, function() { 
			window.location.reload();
		} );
		
		return false;
	});
	
	$('.deleteQuestion').bind('click',function(){
		var pid = $(this).data('pid');
		
		$.get('/answers.php?delete=1&pid='+pid, function() { 
			window.location.reload();
		} );
		
		return false;
	});
	
	$('.showBlogEntryOnSG').bind('click',function(){
		var pid = $(this).data('pid');
		var showOnSG = $(this).data('show');
		
		$.get('/blog.php?pid='+pid+'&showOnSG='+showOnSG, function() { 
			window.location.reload();
		} );
		
		return false;
	});
	
	
	
	$('#fbFixed').mouseenter(function(){
		$(this).stop().animate({ width: 244 }, 300, function() { });
	});
	$('#fbFixed').mouseleave(function(){
		$(this).stop().animate({ width: 31 }, 500, function() { });
	});
		
	$('#najSelector a').click(function(){
		$('#najSelector a').each(function() { $(this).attr('class',''); });
		$(this).addClass('active');
		$('#najContainer .tab').each(function() { $(this).css('display','none'); });
		var getID = $(this).attr('id');
		$('div.'+getID).css('display','block');		
	});
	
	$('#notForm').css('display','none');
	$('select#numer').clone().appendTo('#notForm');
	
	$('h4#JWC').click(function(){
		//$(this).css('color','#DF3C91');
		$(this).addClass('activeTab');	
		$('.twoCatz select').remove();
		$('#notForm select#numer').clone().appendTo('.twoCatz .inputWraper');
		$('.twoCatz option.kat_sel_2').remove();		
		$('h4#MD').removeClass('activeTab');
		$('.blockCategories').css('display','block');
	});
	
	$('h4#JWC').trigger('click');

	$('h4#MD').click(function(){
		//$(this).css('color','#DF3C91');
		$(this).addClass('activeTab');
		$('.twoCatz select').remove();

		$('#notForm select#numer').clone().appendTo('.twoCatz .inputWraper');
		$('.twoCatz option.kat_sel_1').remove();	
		
		//$('h4#JWC').css('color','#1E8AA2');
		$('h4#JWC').removeClass('activeTab');
		
		$('.blockCategories').css('display','block');
	});
	
	
	// opcjonalnie wylaczone if nie wybrana gruba cat
	// $('.tabCategories select#numer option').each(function(){
	// 	$(this).attr('disabled','disabled');
	// });
	
	jQuery(function($){
		$.datepicker.regional['pl'] = {
			closeText: 'Zamknij',
			prevText: '&#x3c;Poprzedni',
			nextText: 'Następny&#x3e;',
			currentText: 'Dziś',
			monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
			'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
			monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
			'Lip','Sie','Wrz','Pa','Lis','Gru'],
			dayNames: ['Niedziela','Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
			dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
			dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
			weekHeader: 'Tydz',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['pl']);
	});
	
	$("#planowanaDataPorodu").datepicker({ dateFormat: 'dd/mm/yy' });
	
	$('div.errorBox').fadeIn(1000);

    var checkin = $("#searchbox .searchElements input.search").val();
	
	if(checkin==''){ 
		$("#searchbox .searchElements input.search").val('Wpisz szukaną frazę');
	}
	
	$("#searchbox .searchElements input.search").click(function(){
		var checkin = $("#searchbox .searchElements input.search").val();
		if(checkin=='Wpisz szukaną frazę' || checkin==''){
			if(checkin==''){
				$(this).val('Wpisz szukaną frazę');
			} else {
				$(this).val('');
			}
		}else{}
	}).mouseleave(function(){
		var checkin = $("#searchbox .searchElements input.search").val();
		if(checkin=='Wpisz szukaną frazę' || checkin==''){
			
				$(this).val('Wpisz szukaną frazę');

		}else{ }

	});
		
	$('span#wciazy').click(function(e){
		if(typeof e.altKey != 'undefined')
		{
			$.ajax({
				  url: '/ajax_targetquestions.php?target=1' + ajax_query_additional_params,
				  success: function(data) {
					$('.blok_z_pytaniami').html(data);
				  }
				});
		}
		$('.newestQuestionsHeaderText').text('Najnowsze pytania');
		
		$('h1#anwsersH1').show();
		$('h1#manualsH1').hide();
		$('.XLask').show();
		$('.XLporadnik').hide();

		switch_target(1);
	});

	$('span#mamdziecko').click(function(e){
		if(typeof e.altKey != 'undefined')
		{
			$.ajax({
				  url: '/ajax_targetquestions.php?target=2' + ajax_query_additional_params,
				  success: function(data) {
					$('.blok_z_pytaniami').html(data);
				  }
				});
		}
		$('.newestQuestionsHeaderText').text('Najnowsze pytania');
		
		$('h1#anwsersH1').show();
		$('h1#manualsH1').hide();
		$('.XLask').show();
		$('.XLporadnik').hide();
		
		switch_target(2);
	});
	
	$('span#all').click(function(e){
		if(typeof e.altKey != 'undefined')
		{
			$.ajax({
				  url: '/ajax_targetquestions.php?target=0' + ajax_query_additional_params,
				  success: function(data) {
					$('.blok_z_pytaniami').html(data);
				  }
				});
		}
		$('.newestQuestionsHeaderText').text('Najnowsze pytania');
		
		$('h1#anwsersH1').show();
		$('h1#manualsH1').hide();
		$('.XLask').show();
		$('.XLporadnik').hide();
		
		switch_target(0);
	});
	
	$('span#poradniki_pokaz').click(function(e){
		if(typeof e.altKey != 'undefined')
		{
			$.ajax({
				url: '/ajax_targetquestions.php?manual=1' + ajax_query_additional_params,
				success: function(data) {
					$('.blok_z_pytaniami').html(data);
				}
			});
		}
		$('.newestQuestionsHeaderText').text('Najnowsze poradniki');
		
		$('h1#anwsersH1').hide();
		$('h1#manualsH1').css("display", "block");
		$('.XLask').hide();
		$('.XLporadnik').css("display", "block");
		
		switch_target(999);
	});
	
	$('#QAtagi input').focus(function() {
	  
		$(this).keypress(function() {
			var chars = $(this).val();
			if(chars!='') $('#QAtagi .qTip').css('display','none');
		});
	
	});
	
	$('#QAtagi input').blur(function() {
		var chars = $(this).val();
		if(chars=='') $('#QAtagi .qTip').css('display','block');
	});
	
	$('a#shoutboxResize').click(function(){
		var currentState = $(this).attr('class');
		if(currentState=='maximize'){
			if($('.mainRight #askSearch').length){
				$('<div id="shoutboxWide"></div>').insertAfter('.mainRight #askSearch');
				$('#shoutboxWide').append($('#shoutboxContainer'));
			}else if($('.rightSubPage').length){
				
				if( $('.leftSubPage .userInfo').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage .userInfo')){
					$('<h2 id="rmHeader">Profil</h2>').insertAfter('#shoutboxWide');
				}

				if( $('.leftSubPage #tabWrapper').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage .blogIco')){
				}

				if( $('.leftSubPage .wideSB').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage .wideSB')){
				}

				if( $('.leftSubPage .bcrumbs').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage .bcrumbs')){
				}

				if( $('.leftSubPage .QueItem').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage h2.quest')){
				}

				if( $('.leftSubPage #questForm').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage h2.quest')){
				}

				if( $('.leftSubPage .subMSG').length>0 && $('<div id="shoutboxWide"></div>').insertBefore('.leftSubPage h4.quest')){
				}

				
				$('#shoutboxWide').append($('#shoutboxContainer'));
			}

			$(this).removeClass('maximize').addClass('minimize');
			$(this).attr('title','Pomniejsz okno shoutbox\'a');
			
		}else if(currentState=='minimize'){
			if($('.mainRight #askSearch').length){
				$('#shoutboxContainer').prependTo($('.mainLeft'));
			}else if($('.rightSubPage').length){
				$('h2#rmHeader').remove();
				$('#shoutboxContainer').prependTo($('.rightSubPage'));	
			}
			$(this).removeClass('minimize').addClass('maximize');
			$(this).attr('title','Powiększ okno shoutbox\'a');
		}else{
			//not good, no class.
		}
	});
	
	
	
	
	$('#floating-box').fadeTo(100, 0.6, function() { });
	$('#floating-box').mouseenter(function(){
		$(this).fadeTo(600, 1, function() { });
	});
	$('#floating-box').mouseleave(function(){
		$(this).fadeTo(100, 0.6, function() { });
	});

	//this is the floating content
	var $floatingbox = $('#floating-box');
 
	if($('#global').length > 0){
 
	  var bodyY = parseInt($('#global').offset().top) - 20;
	  var originalX = $floatingbox.css('margin-right');
 
	  $(window).scroll(function () { 
 
	   var scrollY = $(window).scrollTop();
	   var isfixed = $floatingbox.css('position') == 'fixed';
 
	   if($floatingbox.length > 0){
 
	      //$floatingbox.html("srollY : " + scrollY + ", bodyY : " 
          //                        + bodyY + ", isfixed : " + isfixed);
 
	      if ( scrollY > bodyY && !isfixed ) {
			$floatingbox.stop().css({
			  position: 'fixed',
			  top: 20,
			  marginLeft: 970
			});
		} else if ( scrollY < bodyY && isfixed ) {
		 	  $floatingbox.css({
			  position: 'absolute',
			  top: 217,
			  marginRight: originalX
		});
	     }		
	   }
       });
     }
	
	
	
	
	
	
	
});
