$(document).ready(function(){
    $("ul li:last-child").addClass("last");
    $("ul li:first-child").addClass("first");
	$(".image_set .image_link:last-child").addClass("last");
    $(".image_set .image_link:first-child").addClass("first");
	$("section h3:last-child").addClass("last");
    $("section h3:first-child").addClass("first");
	
	$('.question').fancybox();
	$("section .gallery a").fancybox();
	$(".section .gallery a").fancybox();
	$("article .gallery a").fancybox();
	$(".article .gallery a").fancybox();
	$(".other_gallery a").fancybox();
	$("#czym_jest").fancybox();
	
	//$('.rounded2').corners('6px');
    //$('.rounded2').corners('6px'); /* test for double rounding */
	
	$("#scrolled_items").haccordion();
	
	var newsCount = $("#scrolled_items").children().length/2;
	var current = 1;
	var currentMenuPos;
	var t;
	
	function autoAccordion(){
		//document.title += ' : #scrolled_header_'+current;
		//scrollAccordion();
		$("#scrolled_header_"+current).click();
		ajaxLoad("#scrolled_item_"+current+" a");
		if(current < newsCount){
			current ++;
		}else{
			current = 1;	
		}
		t = setTimeout(autoAccordion, 10000);
	}
	//alert($("#scrolled_header_1").click());
	autoAccordion();
	
	$('#scrolled_items').click(function(){clearTimeout(t)});
	
	/* !!!!!!!!!!!!!! below code moved to sidebar.php !!!!!! */
	
/*	$('#side_nav li').each(sideNavSetup);
	
	function sideNavSetup(){
		$(this).css('overflow','hidden');
		$(this).css('height','16px');
		$(this).bind('click',this,navMenuClick);
		if($(this).children('ul').length > 0 && $(this).parent().attr('id') == 'side_nav'){
			//$(this).children('ul').children('li').each(sideNavSetup);
			$(this).children('a').attr('href', 'javascript:;');
		}
	}
	
	function navMenuClick(what){
		event.stopPropagation();
		if($(this) != currentMenuPos){
			currentMenuPos.animate({
				height: 16
			   }, 500);
			currentMenuPos = $(this);
		}
		if($(this).children('ul').length > 0){
			if($(this).height() == 16){
				$(this).animate({
				height: $(this).children('ul').height()+12
			   }, 500);
			}else{
				$(this).animate({
				height: 16
			   }, 500);
			}
		}
	}
	$('#side_nav li.current_page_parent').animate({
          height: $('#side_nav li.current_page_parent').children('ul').height()+12
        }, 500);
	currentMenuPos = $('#side_nav li.current_page_parent');
	if($('#side_nav li.current_page_item').children('ul').length > 0){
		$('#side_nav li.current_page_item').click();
	}*/
/*	var imgHeight = 230;
	var divHeight = 230;
	var duration = 1000;
	var galleryLeftImage = 0;
	var inactiveButtonOpacity = .5;
	var imagesCount = $("#scrolled_items").children().length;
	var currentNews = $('#control_items a.selected');
	var newsSelected = 1;
	var newsCount = $("#scrolled_items").children().length;
	var arrPos = new Array();

	
	
	//alert($("#scrolled_items").children()[0].innerHTML);
	var duplicate = $("#scrolled_items").clone().children()[0];
	
	$("#scrolled_items").append(duplicate);
	//alert($("#scrolled_items .scrolled_item").last().html());
	$("#scrolled_items .scrolled_item").last().attr('id', 'scrolled_item_'+(newsCount + 1));
	
	for(i = 1; i <= newsCount+1; i++){
		arrPos.push($('#scrolled_item_'+i).position().top);
	}
	
	Cufon.replace('#scrolled_items h3', {fontFamily: 'Gotham Rounded Medium',  textShadow: '#54831C 0px 2px' });
	Cufon.replace('#scrolled_items a', { fontFamily: 'Gotham Rounded Medium' ,  textShadow: '#333 1px 1px'});
	
	$("#scrolled_items").css("top",'0');	

	

		function selectNews(n){
			var num = n.attr('title');
			num--;
			currentNews.removeClass('selected');
			//document.title = num;
			if(num == 1){
				$('#control_item1 a').removeClass('selected');
			}
			n.addClass('selected');
			currentNews=n;
			
			$("#scrolled_items").animate({
				top: (-(arrPos[num])+10) + 'px'
			}, duration, function() {			
				//document.title = num;
				if(num == newsCount){
					$("#scrolled_items").css('top', '0');
					$('#control_item1 a').addClass('selected');
				}
			});
	}

	

	function autoNews(){
		if(newsSelected <= newsCount){
			newsSelected++;
		}else{
			newsSelected = 2;
		}
		readP();
		interval = setTimeout(autoNews, 8000);
		selectNews($('.control_item a').eq(newsSelected-1));
	}	

	var interval = setTimeout(autoNews, 3000);	

	$('.control_item a').click(function(){clearTimeout(interval);interval=setTimeout(autoNews,12000);selectNews($(this));newsSelected=$(this).html();return false});	
	
	
	
	
	
	var arr_partnerzy = $('header #slideshow img');
	var c = 0;

	function readP() {
		//document.title += $('header #slideshow img').eq(c);
		//$('header #slideshow img').eq(c).hide('normal',moveContent);
		$('header #slideshow').animate({
			opacity: 0
		  }, 1000, function() {
			//$(this).css('display', 'none');
			moveContent();
		  });

	}

    function moveContent() { 
          $('header #slideshow img').eq(c).css('top','300px');
			c++;
			$('header #slideshow img').eq(c).css('top','0');	  

			if(c >= arr_partnerzy.length){
			c = 0;
			$('header #slideshow img').eq(c).css('top','0');
		} 

		showNewContent();	

      } 	

	

	function showNewContent() {
        //$('header #slideshow img').eq(c).show('normal');setTimeout(readP, 5000); 
		//$('header #slideshow').css('display', 'block');
		$('header #slideshow').animate({
			opacity: 1
		  }, 1000, function() {
			//setTimeout(readP, 5000);
		  });
    }  */

	
	
  });

 function ajaxLoad(n){
	 var cat = $(n).attr("rel");
	 var userData = '';
	 var msg = 'ładuję...';
		if($(".pl #s1 .box_335_inner").length != 0){
			$(".home #s1 .box_335_inner").html("<h3 style=\"padding-bottom: 50px\">ładuję...</h3>");
			$(".home #s1 .box_335_inner").load('/ajax-loader/',{cat_name:cat}, function(){Cufon.replace('h3', { fontFamily: 'klavika rg' });});
			Cufon.replace('h3', { fontFamily: 'klavika rg' });
		}else{
			if(cat != '89'){
				targ = "#product_description_";
			}else{
				userData = $(n).attr("name");
				targ = "#thnx";
				cat = '';
				msg = 'wysyłam...';
			}
			if($(targ+cat).length != 0){
				$(targ+cat).css('display','block');
				if($(targ+cat).html().length < 20 || targ == "#thnx"){
					//document.title += '-------------------------';
					$(targ+cat).html("<h3 style=\"margin-bottom: 15px\">"+msg+"</h3>");
					$(targ+cat).load('/ajax-loader/',{cat_name:cat, user_data:userData}, function(){Cufon.replace('h3', { fontFamily: 'klavika rg' });});
					Cufon.replace('h3', { fontFamily: 'klavika rg' });
				}
			}
		}
		return false;
	}
	
	 function ajaxUnload(n){
		 var cat = $(n).attr("rel");
		 if(cat != '89'){
				targ = "#product_description_";
			}else{
				targ = "#thnx";
			}
		 if($(targ+cat).length != 0){
			$(targ+cat).css('display','none');
		 }
		return false;
	}
