// JavaScript Document
function link(adres){var wzorzec=/\#[\S]{0,}/i;document.location.href=document.location.href.replace(wzorzec,"")+adres;}
function goToErrorLabel(elem){ 
	var x = $('#'+elem).offset().top - 100; // 100 provides buffer in viewport
	$('#'+elem).focus();//focus an element
    $('html,body').animate({scrollTop: x}, 500);
}

/*
	porownanie, czy pola o podanych id sa identyczne
	przy prawdzie zwraca true, przy bledzie komunikat i zwraca false
*/
function porownajPola(haslo, haslo2, tekst) {
	if ($('#'+haslo).val()===$('#'+haslo2).val()) return true;
	else { alert (tekst); return false; }
}

/*
	zaznacza i odznacza po klikniecu wszystkie checboxy o podanej klasie
	id okresla id pola sterujace zaznaczaniem pozostalych checkbox'ow
*/
function zaznaczOdznacz(klasa,id) {
	$("INPUT[type='checkbox']."+klasa).attr('checked', $('#'+id+'').is(':checked'));   
}

/** zminia formy w artykułach w zależności czy to news czy tekst**/

function changeForm(form){
	if (form == 37) { $('#right_coulmn').load(domena+'articles/loadform/kind/37');}
	if (form == 38){ $('#right_coulmn').load(domena+'articles/loadform/kind/38'); }
	if (form == 39){ $('#right_coulmn').load(domena+'articles/loadform/kind/37'); }	
};

function usunKategorie(id) {
		jConfirm('Na pewno usunąć wybraną kategorię i jej podkategorię',
		'Confirm', function(r) {
				kom = $('#comments').text();
				if( r ) {					
					$('#comments').load(domena+'articles/delCat/id/'+id);
					//if (<?php echo $this->delete ?>=='1') 
					if (true){
						$.tree.focused().select_branch('#k_'+id);
						$.tree.focused().remove();
					}
					}
			})
	}
	
function deleteNode(id) {
		jConfirm('Na pewno usunąć wybraną węzeł i jego podwęzły?',
		'Confirm', function(r) {
				kom = $('#comments').text();
				if( r ) {					
					$('#comments').load(domena+'menu/deletenode/id/'+id);
					//if (<?php echo $this->delete ?>=='1') 
					if (true){
						$.tree.focused().select_branch('#k_'+id);
						$.tree.focused().remove();
					}
					}
			})
}	
	
function zaznaczKategorie(id) {
		$.tree.focused().select_branch('#k_'+id);
	}
/* ---------------------- funkcja do tłumaczenia ciągow stringów -------------------------------------------*/	
function _(str){
/* return $.i18n._(str);*/	
} 	
/* ---------------------- pgr file manager init -------------------------------------------*/	
function BrowseServer() {	

	$('#right_coulmn').load(domena.replace('/admin','')+'public/scripts/js/pgrfilemanager/PGRFileManager.php');

    /*   	       
	var filemanager = new PGRFileManager({
           sId : "nlksi9vk7d91f24ue3kcpn1ls2", 
           rootDir : domena.replace('/admin','')+"/userfiles", 
           allowedExtension : "*.jpg;*.gif;*.jpeg;*.png;*.bmp", 
           fileDescription : "images", 
           filesType : "Image",
           fileMaxSize : "10485760 B",
           lang: "pl",
           ckEditorFuncNum: "1",
           allowEdit: true
		   });
           filemanager.init();*/	
    }
    
function SetFileField( fileUrl ) {
        document.getElementById( 'filepath' ).value = fileUrl ;
    }	
	

/**

* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+

* <http://cherne.net/brian/resources/jquery.hoverIntent.html>

* 

* @param  f  onMouseOver function || An object with configuration options

* @param  g  onMouseOut function  || Nothing (use configuration options object)

* @author    Brian Cherne <brian@cherne.net>

*/

(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:50,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


 //ajax support
			$(window).bind("ajaxSend", function() {				
			  jQuery('#ajax_info').show();	
			  jQuery('#ajax_info').html('<img src="<?php echo $this->root_path,$this->skin_path; ?>ajax-loader-client.gif">');
			  jQuery('#ajax_info img').css('top',$(window).scrollTop()+$(window).height()/2-100);
			});

			$(window).bind("ajaxError", function() {
			  jQuery('#ajax_info').hide();
			  jQuery('#ajax_info').html('');
			});

			$(window).bind("ajaxSuccess", function() {
			  jQuery('#ajax_info').hide();
			  jQuery('#ajax_info').html('');
			});
			
	//contactform.chang select
	/* $(document).ready(function(){
		$('#ContactForm-recipient_email').selectmenu({
				style: 'dropdown',
				width: 420
		});
	 });*/
	 
	//funkcje do filtrów
	function setVal(id,type){
		
		if(id == 'sort_type_f') {
			$('#sort_type p').each(function() { $(this).removeClass('active_f'); });
			if (type == 'data') $('#'+id+'_p').toggleClass('active_f'); 
			if (type == 'data_o') $('#'+id+'_p1').toggleClass('active_f');
			if (type == 'name')$('#'+id+'_p2').toggleClass('active_f');
			$('#'+id).val(type);
		}else{
			if ($('#'+id).is(':checked')) $('#'+id).attr('checked', false); else $('#'+id).attr('checked', true);
			$('#'+id+'_p').toggleClass('active_f');
		}
	}
	
	function checkAll(check){
		$('form#filter_oprions input[type="checkBox"]').each(function() {$(this).attr('checked',check);});
		$('#where p').each(function() {
				if (check) $(this).addClass('active_f'); else $(this).removeClass('active_f');
			});
	}


//google maps
	function maxMap() {
		$('.filter').html($('.maps_cointainer .controls').html());
		$('#largeMap').width($(window).width());
		$('#largeMap').height($(document).height());
		initialize('largeMap');
		$('#largeMap').css('z-index',5000);
		$('#large_map_controls').show();
		$('#largeMap').show();
	}
	
	function closeMaxMap() {
		$('#large_map_controls').hide();
		$('#largeMap').html('');
		$('#largeMap').hide();
	}
	
//galeries

		
//menu
$(document).ready(function() {
			$('.menu_container ul li.parent').find('a.fadeThis').prepend('<span class="hover"></span>').each(function () {
				var $span = $('> span.hover', this).css('opacity', 0);
				$(this).hover(function () {
					$span.stop().fadeTo(800, 1);
				}, function () {
				$span.stop().fadeTo(800, 0);
				});
				});
});


//news
	function showNews(id){
		
		$(window).scrollTop(300);
		$('#news_list').hide();
		$('#large_news').load(domena+'index/getnews/id/'+id);
		$('#large_news').fadeIn();
		
		//var displayed = $('#news'+id).css('display');
		//var a = $('#news'+id).parent().find('a.more');
		//	if (displayed == 'none'){
		//		$('#news'+id).fadeIn();
		//		a.addClass('less');
		//	}
		//	if (displayed == 'block'){
		//		$('#news'+id).fadeOut();
		//		a.removeClass('less');
		//	}

		
		}
		
	function news_goBack(){
		$('#large_news').html('');
		$('#large_news').hide();
		$('#news_list').fadeIn();
	}	
		
//first right slideshow
$(function() {

$("#slidetabs_1").tabs("#slides_1 > .slide", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: 5000,

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
}).slideshow({interval: 5000,autoplay: true});
});

//second right slider

$(function() {

$("#slidetabs_2").tabs("#slides_2 > .slide", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: 5000,

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
}).slideshow({interval: 5000,autoplay: true});
});

//search box function
$(document).ready(function() {
	
	$('.fraza').click( function() {
			if ($('.fraza').val() == 'wpisz szukaną fraze...') $('.fraza').val('');
		});
		
	$('.fraza').blur(function() {
			if ($('.fraza').val() == '') $('.fraza').val('wpisz szukaną fraze...');
		});
		
		
	$("#search_box form div:first input[name=fraza]").focus(function(){
			if(this.value===this.defaultValue){
				this.value=""
			}else{
				this.select()
			}
			$("#search_box div.fancy-panel").fadeIn("fast");
	});
			
	$("#search_box form div:first input[name=fraza]").click(function(){
			$("#search_box div.fancy-panel").fadeIn("fast");
	});
			
	$("#search_box form div:first").mouseleave(function(){
			$("#search_box div.fancy-panel").fadeOut("fast");
	});
		
	$("#search_box form div:first input[name=fraza]").blur(function(){
			if($.trim(this.value)===""){
					this.value=(this.defaultValue?this.defaultValue:"")}});
	$("#search_box form").submit(function(){
		var b=$("#search_box form div:first input[name=fraza]").val();
		if(b==="wpisz szukaną fraze..."||b===""){
			$("#search_box div.fancy-panel:hidden").fadeIn("fast");
			return false
			}
		return true});
		
		var allCats=$("#search_box input.all-cats");
			if(allCats.is(":checked")){
				$("#search_box input.sub-cat").each(function(){
					$(this).attr("disabled","disabled");
					$(this).attr("checked","true")})}
			allCats.change(function(){
				if(allCats.is(":checked")){
					$("#search_box input.sub-cat").each(function(){
						$(this).attr("disabled","true");
						$(this).attr("checked","false")})
				}else{
					$("#search_box input.sub-cat").each(function(){
						$(this).removeAttr("disabled");
						$(this).removeAttr("checked")
				}
			)}
		});
	
	
	});





//nivo slider
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:100, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});


//wortal scroll
$(document).ready(function() {
	$("#browsable").scrollable().navigator();	
});

//pagination function
/*
$(document).ready(
	function() {
	var linki = $('#content a[href*="_lp_"]');
	linki.each(
		function() {
		var link = $(this).attr('href');
		var link_split = link.split('/');
		var link_split_2 = link_split[link_split.length-1].split('.');
		$(this).attr('href',link_split_2[0]+','+$('#news_per_page').val()+','+$('#sort_cena').val()+','+$('#sort_nazwa').val()+".html");
		}
	)
	}
);
*/

	function loadPage(container,site) {
		
			$('#'+container).load(site);
		
		}



