$(document).ready(function(){
	
	/**
     * tabs
     */
	$( "#tabs, #tabs2" ).tabs({
            select: function(event, ui) {
                $('.breadcrumbs_h').hide();
                $('.breadcrumbs-'+ui.panel.id).show();
                $('.breadcrumbs_resources').hide();
                return true;
            }
        });


	$('.copycode').click(function(){
		var link = $(this).attr('href');
		$.copy( link );
		return false;
	});

	$('#register_tooltip').html('?');

	/**
 * zaznaczam wszystko
 */
	$('input#selAll').change(function(){
		if($('input#selAll').attr('checked')) {
			var checked = "checked";
		} else {
			var checked = "";
		}
		var parent = $(this).parent().parent().parent();

		$(parent).find("td.selAll input[type=checkbox]").each(function(){
			$(this).attr('checked',checked);
		});
	});
	
	/**
     * dodaje confirma
     */
	
	$('.confirm').click(function(e){
		df(0);
		if(!confirm('Czy napewno usun\u0105ć ten element?')) {
			e.preventDefault();
		}
	});

	/**
     * Dodawanie do ulubionych
     */
	$('.addToFav , .addToFav2').live('click',function(){
		var noLoad = $(this).hasClass('noLoad');
		var id = $(this).attr('href').substring(1);
		var path = SITE_PATH+'/logged/product/addfavourite/id/'+id;
		if (noLoad)
			$(this).parent().attr('style','display:none');
		$('.addToFav').load(path,function(){
                    $('.addToFav').addClass('remToFav');
                    $('.addToFav').removeClass('addToFav');
                    $('.remToFav').before('<span>x</span>');
                });
		return false;
	});
	$('.remToFav').live('click',function(){
		var id = $(this).attr('href').substring(1);
		var path = SITE_PATH+'/logged/product/removefavourite/id/'+id;
		$(this).load(path,function(){
                    $('.remToFav').addClass('addToFav');
                    $('.remToFav').prev('span').hide();
                    $('.remToFav').removeClass('remToFav');
                });
		return false;
	});

	/**
	 * menu left
	 */
	$('.leftMenu li ul').hide();
	$('.leftMenu li ul li a').each(function(){
		var link = $(this).attr('href').split('?',2);
		if (link[0]==document.location.pathname){
			$(this).parent().parent().show();
			$(this).parent().parent().addClass('dontHide');
		}
	});
	$('.leftMenu li a').not('.leftMenu li ul li a').click(function(){
		if ($(this).parent().find('ul').length>0){
			$('.leftMenu li ul').not('.dontHide').hide();
			$(this).parent().children().show();
			return true;
		}
	});

	$('#buttonZadajPytanie').click(function () {
		
		$('#alerts').attr('id', 'ask_questions');
		$('.ask').css('display', 'block');
		$('form[name=fr-recived]').css('display', 'none');
		$('#buttonZadajPytanie').css('display', 'none');
	});

	$('#buttonZadajPytanieWOdp').click(function () {
		$('#questions').attr('id', 'ask_questions')
		$('#ask').css('display', 'block');
		$('.hidden').css('display', 'none');
		$('#buttonZadajPytanieWOdp').css('display', 'none');
		$('.addToFavx').css('display', 'none');
		return false;
	});
	
});



