// JavaScript Document
      $(document).ready(function(){
								 


	$(".forgot-pass").click(function () {
		sliderNext("#slider1");
    }); 
				
	$("#show-club-map").click(function () {
		 $("#map-club-avatar").animate({
			height: 550
		  }, 500, function() {
    // Animation complete.
  });
		     }); 
		 
	$(".hide-club-map").click(function () {
		 $("#map-club-avatar").animate({
			height: 0
		  }, 300, function() {
  });

    }); 	
	
	$("#popuup_div").click(function () {
	$(this).hide();	
	$('#popuup_div_shadow').hide();
	});
	
	$("#report-button").click(function () {
	$(".report-form").slideDown();	
	});
	
	$("#report-hide-button").click(function () {
	$(".report-form").slideUp();	
	})
		
		
	$('#after_date').change(function() {
		$.ajax({
			  type: 'POST',
			  data: "datefrom="+$('#after_date').val()+"&dateto="+$('#before_date').val(),
			  url: '/kmosite/index.php?option=com_kmo&controller=utils&task=newslist&ajax=1',
			  success: function(data) {
				$('#news-list-ctnr').html(data);
			  }
			});
	});

	
	$('#before_date').change(function() {
		$.ajax({
			  type: 'POST',
			  data: "datefrom="+$('#after_date').val()+"&dateto="+$('#before_date').val(),
			  url: '/kmosite/index.php?option=com_kmo&controller=utils&task=newslist&ajax=1',
			  success: function(data) {
				$('#news-list-ctnr').html(data);
			  }
			});
		});

                $(".ofl").click(function (e) {



                });
			
		$(".oflll").click(function (e) {
  //getting height and width of the message box
  var height = $('#popuup_div').height();
  var width = $('#popuup_div').width();
    var height = $('#popuup_div_shadow').height();
  var width = $('#popuup_div_shadow').width();
  //calculating offset for displaying popup message
  leftVal=e.pageX+"px";
  topVal=e.pageY+(5)+"px";
  //show the popup message and hide with fading effect
  
  $('#popuup_div').css({left:leftVal,top:topVal}).show();
  leftVal=(e.pageX+5)+"px";
  topVal=(e.pageY+5)+(5)+"px";
  $('#popuup_div_shadow').css({left:leftVal,top:topVal}).show();
  return false;
    }); 	
			

	$( "#map_canvas" ).each(
	function( intIndex ){
	mapinit();
	}
	);
	backgroundFix();
		$("div.community-leak div.menu").find("div.item").click(function () {
		  showLeak($(this).attr("nrtoshow"));
  		  }); 
		
 	ctnrFix();

	$('.only-send-form').each(
	function( intIndex ){
		    $(this).ajaxForm(function() { 
                	$('#status-inf').html("Zmieniono okładkę galerii."); 
            }); 
	});
	
	$('#f_status').focus(function(){
	 if(this.value=='Tutaj wpisz nowy status')
	 {
	 this.value=''
	 }
	 }); 
	
	var lastUserSrch = "";
	var lastClubSrch = "";
	var fcsSrch = "" ;
	
	 function srchPerf() {
	$.ajax({
 		  url: '/kmosite/index.php?option=com_kmo&controller=utils&task=search&scheme=community',
		  success: function(data) {
 		 }
	});
	};	
	var data;
	var last,diff;
	//$("#users-detalis").at_intervals(srchLoad); 
	$('#main-user').keyup(function (event) {
      var value = $(this).val();
	      diff = event.timeStamp - last;
  			last = event.timeStamp;
	 $('#search-results').html($('#loading').html());
	  $.ajax({
		  type: "POST",
		  data: "main_user="+$('#main-user').val()+"&users=1&user_town="+$('#user_town').val()+"&user_club="+$('#user_club').val()+($('#get_students').attr("checked")?"&get_students=on":"")+($('#get_teachers').attr("checked")?"&get_teachers=on":"")+($('#get_animators').attr("checked")?"&get_animators=on":""),
		  url: '/kmosite/index.php?option=com_kmo&controller=utils&task=search&ajax=1&scheme=community',
		  success: function(data) {
			waitingdata=data;
		  }
		});
    });
	
	if($('#main-user').val()=="")
	{	
	$('#main-user').val('wpisz szukaną frazę');
	$('#main-user').css('color','#999');	
	}
	
	$('#main-user').click(function (event) {	
		if(	$('#main-user').val() =='wpisz szukaną frazę')
		{
			$('#main-user').val('');
			$('#main-user').attr('style','');
		}
	});	
	
	$('#club_town').attr('style','color:#999;');
	
	$('#club_town').change(function (event) {	
		if(	$(this).val() =='none')
		{
			$(this).attr('style','color:#999;');
		}
		else
		{
			$(this).attr('style','');			
		}
	});	
	
	if($('#main-club').val()=="")
	{
	$('#main-club').val('wpisz szukaną frazę');
	$('#main-club').css('color','#999');	
	}
	
	$('#main-club').click(function (event) {	
		if(	$('#main-club').val() =='wpisz szukaną frazę')
		{
			$('#main-club').val('');
			$('#main-club').attr('style','');
		}
	});	
	
	$('#main-club').keyup(function (event) {
	
		if(	$('#main-club').val() =='wpisz szukaną frazę')
		{
			$('#main-club').val('');
			$('#main-club').attr('style','');
		}
	
      var value = $(this).val();
	      diff = event.timeStamp - last;
  			last = event.timeStamp;
	 $('#search-results').html($('#loading').html());
	  $.ajax({
		  type: "POST",
		  data: "main_club="+$('#main-club').val()+"&clubs=1&club_town="+$('#club_town').val()+"&with_maps="+($('#with_maps').attr("checked")?"1":"0"),
		  url: '/kmosite/index.php?option=com_kmo&controller=utils&task=search&ajax=1&scheme=community',
		  success: function(data) {
			waitingdata=data;
		  }
		});
    });
	
	$("#search-results").ajaxStop(function(){
      $(this).html(waitingdata);
	  ctnrFix();
      });
	
	$("#users-detalis .cb-ctnr").click(function () {
			$('#main-user').keyup(); 
			
	});
	$("#users-detalis .search-submit-users").click(function () {
			$('#main-user').keyup();
			return false;
	});
	$("#user_town").change(function () {
			$('#main-user').keyup(); 			
	});
	$("#user_club").change(function () {
			$('#main-user').keyup(); 			
	});
	
	$("#clubs-detalis .search-submit-clubs").click(function () {
			$('#main-club').keyup();
			return false;
	});	
	
	$("#club_town").change(function () {
			$('#main-club').keyup(); 			
	});
	
	$("#with_maps").change(function () {
			$('#main-club').keyup(); 			
	});
	
	
	$('#main-user').focus(function(){
	$('#users-detalis').fadeIn('fast');
	$('#clubs-detalis').fadeOut('fast');
	 });
	
	$('#main-club').focus(function(){
	$('#users-detalis').fadeOut('fast');
	$('#clubs-detalis').fadeIn('fast');
	 }); 


	
	
    $(function(){
      $("#leak-gallery").mbScrollable({
        width:340,
        elementsInPage:1,
        elementMargin:10,
        height:300,
        controls:"#outter-controls",
        slideTimer:600,
        autoscroll:true,
        scrollTimer:6000 
      });
    });	

	var ident = "";
	$( ".leak-gallery" ).each(
	function( intIndex ){
	ident = $(this).attr('id');
	$( this ).mbScrollable({
        width:340,
        elementsInPage:2,
        elementMargin:10,
        shadow:"#999 2px 2px 2px",
        height:110,
        controls:"#"+ident+"-contr",
        slideTimer:300,
        autoscroll:false,
        scrollTimer:2000 
      }); 
	}
	);
	$( "#leak-gals" ).css('display','block');
	
	swfobject.addDomLoadEvent(function() {
 	 swfobject.embedSWF(
					"/kmosite/swfs/text_and_image_cloud.swf?a=b", "scenario-cloud",
					"280", "180",
					"9.0.0", "/kmosite/swfs/expressInstall.swf",
					{
						cloud_data:"cloud_data.xml",
						tcolor:"0xf39400",
						tcolor2:"0xffdda7",
						hicolor:"0x1a9ab2",
						tspeed:"100",
						fontFace:"Sommet"
					},
					{wmode: "transparent", menu: "false", quality: "best"}
					);
		});

	$.fx.speeds._default = 1000;
	$(function() {

	});

	
/*
    $(function(){
      $("#leak-gallery-1").mbScrollable({
        width:340,
        elementsInPage:2,
        elementMargin:10,
        shadow:"#999 2px 2px 2px",
        height:110,
        controls:"#controls-1",
        slideTimer:300,
        autoscroll:false,
        scrollTimer:2000 
      });
    });	
	
	$(function(){
      $("#leak-gallery-2").mbScrollable({
        width:340,
        elementsInPage:2,
        elementMargin:10,
        shadow:"#999 2px 2px 2px",
        height:110,
        controls:"#controls-2",
        slideTimer:300,
        autoscroll:false,
        scrollTimer:2000 
      });
    });	
*/		

      function backgroundFix() {   
		$('body').css('background-position',(Math.floor($('#wrap').width()/2)-821)+'px 135px');	
      };
	  

       
      var resizeTimer = null;
      $(window).bind('resize', function() {
      if (resizeTimer) clearTimeout(resizeTimer);
      resizeTimer = setTimeout(backgroundFix, 100);
      });


    var options = { 
        target:        '#component',   // target element(s) to be updated with server response 
        clearForm: true        // clear all form fields after successful submit 
    }; 

    var options2 = { 
        target:        '#scenario-leak',   // target element(s) to be updated with server response 
    }; 
	
    $('#search-adv').ajaxForm(options); 
    $('#search-sim').ajaxForm(options); 
	$('#search-sim-main').ajaxForm(options2); 

	$('div#slider1').live('mouseover', function() {
  		$(this).addClass('mouseover');
	});
	$('div#slider1').live('mouseout', function() {
		$(this).removeClass('mouseover');
	});
	
	$('div:has(.show-on-parenthover)').live('mouseover', function() {
  		$(this).children(".show-on-parenthover").show();
		$(this).children(".hide-on-parenthover").hide();
	});
	$('div:has(.show-on-parenthover)').live('mouseout', function() {
  		$(this).children(".show-on-parenthover").hide();
		$(this).children(".hide-on-parenthover").show();
	});

	$('div.commen').live('mouseover', function() {
  		$(this).children("div.icon").css('background-position',$(this).children("div.icon").attr("baggpos")+'px -44px');
	});
	$('div.commen').live('mouseout', function() {
  		$(this).children("div.icon").css('background-position',$(this).children("div.icon").attr("baggpos")+'px 0px');
	});
	
	$('.entry').live('mouseover', function() {								   
  		$(this).children(".entry-buttons.onh").show();
	});
	$('.entry').live('mouseout', function() {
  		$(this).children(".entry-buttons.onh").hide();
	});

	$('.move-on-parenthover').live('mouseover', function() {
  		$(this).css("background-position","2px 2px");
	});
	$('.move-on-parenthover').live('mouseout', function() {
  		$(this).css("background-position","0px 0px");
	});
	
	$('.move-on-parenthover-class').live('mouseover', function() {
  		$(this).addClass("hover");
	});
	$('.move-on-parenthover-class').live('mouseout', function() {
  		$(this).removeClass("hover");
	});

	$('.tab-ro').live('mouseover', function() {
  		$(this).removeClass('inactive');
  		$(this).addClass('active');
	});
	$('.tab-ro').live('mouseout', function() {
  		$(this).removeClass('active');
  		$(this).addClass('inactive');
	});
	
	$('.bounce').live('mouseover', function() {
		 $(this).stop().animate({
			'padding-left' : '47'
		  }, 50, function() {
			// Animation complete.
		  });
		 $(this).find('div').stop().animate({
			'left' : '12'
		  }, 50, function() {
			// Animation complete.
		  });
		 $(this).removeClass('bounce').addClass('bounce2');

	});
	$('.bounce2').live('mouseout', function() {
		 $(this).stop().animate({
			'padding-left' : '42'
		  }, 50, function() {
			// Animation complete.
		  });
		 $(this).find('div').stop().animate({
			'left' : '7'
		  }, 50, function() {
			// Animation complete.
		  });
	    $(this).removeClass('bounce2').addClass('bounce');
	});
	$('.bg-hover.active').each(function() {
		 var org = 	$(this).css('background-position');
		 $(this).attr('orgbgpos', org);
		 org = org.replace("0px", ($(this).attr('bghover')*2) + "px");
		 $(this).css('background-position',org)
		 $(this).removeClass('bg-hover').addClass('bg-hover-activeted');
	});	
	$('.bg-hover').live('mouseover', function() {
		 var org = 	$(this).css('background-position');
		 $(this).attr('orgbgpos', org);
		 org = org.replace("0px", $(this).attr('bghover') + "px");
		 $(this).css('background-position',org)
		 $(this).removeClass('bg-hover').addClass('bg-hover1');
	});
	$('.bg-hover1').live('mouseout', function() {
		 $(this).css('background-position',$(this).attr('orgbgpos'));
		 $(this).removeClass('bg-hover1').addClass('bg-hover');
	});	
	
	
	$('.div-hover').live('mouseover', function() {
		 $(this).removeClass('div-hover').addClass('div-hover1');
	});
	$('.div-hover1').live('mouseout', function() {
		 $(this).removeClass('div-hover1').addClass('div-hover');
	});	
	
	$('.small-hover-zoom').live('mouseover', function() {
  		$('.small-hover-zoom').addClass("hided-image");
		$('.big-hover-zoom').removeClass("hided-image");
		$('.big-hover-zoom').animate({
			width: 182,
		  }, 800, function() {
		  });
	});
	$('.big-hover-zoom').live('mouseout', function() {
		$('.big-hover-zoom').animate({
			width: 32,
		  }, 200, function() {
		$('.big-hover-zoom').addClass("hided-image");
		$('.small-hover-zoom').removeClass("hided-image");
		});
	});
		
	$('.hide-form').live('click', function() {
	$(this).parent().hide();
	});
		
    $(".comment-bt").click(function () {
		$("#cf2_"+$(this).attr("cmntr-id")).show();
		$("#cmnt-ctnr-"+$(this).attr("cmntr-id")).show();		
    }); 

	$(".comment-btn").click(function () {
		$("#cf2_"+$(this).attr("cmntr-id")).show();
		$("#cmnt-ctnr-"+$(this).attr("cmntr-id")).show();		
   }); 


    $(".next-slide").click(function () {
		sliderNext("#slider1");
    }); 
	
	$(".show1slide").click(function () {
		sliderShow("#slider1",1);
    }); 
	
	$(".show2slide").click(function () {
		sliderShow("#slider1",2);
    }); 
		
	$(".show3slide").click(function () {
		sliderShow("#slider1",3);
    }); 
	
	setInterval ( "sliderNext('#slider1')", 4000 );

	
    $(".divlink").click(function () {
		window.location=$(this).attr('divlink');
    }); 
	
	$(".write-on-user").click(function () {
				if ($(".wallwrite").css("display")=="none")
				 {
				$(".wallwrite").slideDown();
				 }	
				 else
				 {
					 $(".wallwrite").slideUp();
				 }
		
   
  }); 	
	
	
		$('div:has(.show-on-parenthover)').live('mouseover', function() {
  		$(this).children(".show-on-parenthover").show();
		$(this).children(".hide-on-parenthover").hide();
	});
		
	$(".ajaxlink").live('click',function () {
		//$('#component').load($(this).attr('ajaxhref'),ctnrFix());
		$.ajax({
			  url: $(this).attr('ajaxhref'),
			  success: function(data) {
				$('#component').html(data);
				ctnrFix();
			  }
			});	
		
		$('.active-news-item').removeClass('active-news-item').addClass("news-item");
        $(this).find('div.news-item').addClass("active-news-item");	
		$(this).find('div.active-news-item').removeClass("news-item");
		
		return false;
    });
	
	$('.main-image').height(parseInt($('.main-image').height())+19);
	
	$(".advenced-btn").click(function () {
		$("#simple-search").hide();
		$("#advenced-search").slideDown('slow');
    }); 
	
	$(".go-to-advenced-btn").click(function () {
		window.location="/scenariusze/wyszukiwarka";
    }); 
	
	$(".prev-slide").click(function () {
		sliderPrev("#slider1");
    }); 
	
	});
	 

	function sliderNext(witchSlider)  { 
	if(!($("#slider1").hasClass('mouseover')))
		{
		var old = parseInt($(String(witchSlider)).attr("actual"));
		
		$(String(witchSlider)).find("#s"+old).fadeOut(2000);
		
		if(old==$(String(witchSlider)).attr("n"))
			{
			$(String(witchSlider)).attr("actual",1);	
			}
		else
			{
			$(String(witchSlider)).attr("actual",old+1);	
			}
			$(String(witchSlider)).find("#s"+$(String(witchSlider)).attr("actual")).fadeIn(2000);
		}
	} 
	
	function sliderPrev(witchSlider)  { 
	var old = parseInt($(String(witchSlider)).attr("actual"));
	
	$(String(witchSlider)).find("#s"+old).fadeOut("fast");
	
	if(old==1)
		{
		$(String(witchSlider)).attr("actual",$(String(witchSlider)).attr("n"));	
		}
	else
		{
		$(String(witchSlider)).attr("actual",old-1);	
		}
	$(String(witchSlider)).find("#s"+$(String(witchSlider)).attr("actual")).fadeIn("fast");
	} 
	
	function sliderShow(witchSlider,witchSlide)  {
	var old = parseInt($(String(witchSlider)).attr("actual"));
	if(old!=witchSlide)
	{	
	$(String(witchSlider)).find("#s"+old).fadeOut("fast");
	
	$(String(witchSlider)).attr("actual",witchSlide);	
		
	$(String(witchSlider)).find("#s"+$(String(witchSlider)).attr("actual")).fadeIn("fast");
	}
	} 
	
	function showLeak(optionNumber)  { 
		$(".community-leak div.option").each(function(index) {
   			 if ($(this).hasClass("o"+optionNumber))
			 {
				$(this).fadeIn(300) ;
			 }
			 else
			 {
				 if ($(this).css("display","none"))
				 {
				$(this).fadeOut(300) ;
				 }
			 }
 		 });

	} 
	
		  function ctnrFix() {
	  $('#bread-title').html($('h1.title').html());
	  if($('#component').height()>600)
	  {
		$('.ctnr').css('height',$('#component').height()+200);
		$('.c-ctnr').css('height',$('#component').height()+200);
	  }
	  else
	  {
		$('.ctnr').css('height',800);
		$('.c-ctnr').css('height',800);  
	  }
	  };
