var sub_menu_stop = 1;
$(function() {
//	/Cufon.replace('h1, h2, h3, h6, #motto, #phone, #navbar, #top-right-text, #partners .title, #footer .f_telephon', { fontFamily: 'aller-regular' });
});

			
$(function() {
//Obsługa menu na stronie głównej (duże zdjęcia)
	$('.big_link').attr('href', $(".menu .one").attr('href'));
	$(".menu .one").mouseover(function (){
		$(".inner-top-right").removeClass('inner-top-right_3');
		$('.text1').show();
		$('.text2, .text3').hide();
		$('.big_link').attr('href', $(this).attr('href'));
		Cufon.replace('.text1');
	});
	$(".menu .two").mouseover(function (){
		$(".inner-top-right").addClass('inner-top-right_3');
		$(".text3").show();
		$(".text1, .text2").hide();
		$('.big_link').attr('href', $(this).attr('href'));
		Cufon.replace('.text3');
	});
	/*$(".menu .three").mouseover(function (){
		$(".inner-top-right").removeClass('inner-top-right_2').addClass('inner-top-right_3');
		$(".text3").show();
		$(".text1, .text2").hide();
		$('.big_link').attr('href', $(this).attr('href'));
		Cufon.replace('.text3');
	});*/
	
});

$(function() {
//Obsługa boksu "nasi partnerzy";
	if($('#partners_list').length){
		var parH = $('#partners_list').height();
		
		if($('#partners_list').height()> 75){
			setInterval(function(){
				var parPos = $('#partners_list').position();	
				
			if((parPos.top-70) >= 80-parH){
				
				$('#partners_list').animate({
					top: parPos.top-75
				},"slow", "swing");
			}
			else{
				$('#partners_list').animate({
					top: 0
				},"slow", "swing");
			}
			
		}, 3000);
		}
		
	}	
});

//Obsługa "subpage menu"
$(function(){
	$('#subpage_menu .sbmenu_it').bind('click', function(){
		if($(this).hasClass('lastElement')){
			return true;
		}
		
		if(!$(this).parents('#subpage_menu').hasClass('sm_bramy')){
			$('.sbmenu_it').removeClass('sbmenu_it_act2');
			$(this).addClass('sbmenu_it_act2');
		}else{
			if(!$(this).hasClass('act_hover') && sub_menu_stop){
				
				sub_menu_stop = 0;
				toShow = this;
				$('.sbmenu_it_cont').hide();
				$('.sbmenu_it').removeClass('act_hover');
				$(this).addClass('act_hover').next('.sbmenu_it_cont').show(0,function(){
					sub_menu_stop = 1;
				});
			}
		}
		return false;
	});
	/*$('#subpage_menu .sbmenu_it').bind('mouseleave', function(){
		if (!$(this).parents('#subpage_menu').hasClass('sm_bramy')) {
			$(this).removeClass('sbmenu_it_act2');
		}else{
			
		}
	});*/
});

$(function() {
//Obsługa mapki
	if($('#content-bottom-map ul li').length){
		//pobranie pierwszej wartości
		firstAddress = $('#content-bottom-map').find('li:first');
		showMap(firstAddress);
		//przycisk "kolejny adres"
		$('#cmb_next').click(function(){
			$('#content-bottom-map ul li').each(function(){
				if($(this).hasClass('show')){
					$(this).removeClass('show');
					if($(this).next('li').length){
						actElement = $(this).next('li');
						
					}
					else{
						actElement = $('#content-bottom-map').find('li:first');
						
					}
					showMap(actElement);
					return false;
				}
			});
		});
	}	
});

function showMap(elem){
	$(elem).addClass('show');
	map_map = $(elem).find('.cmb_img').html();
	map_text = $(elem).find('.cmb_text').html();
	$('#cbm_map').fadeOut(200, function(){
		$(this).html(map_map);
	}).fadeIn(200);
	$('#cmb_address').html(map_text);
}

//jcarusel
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
	//Galeria na stronie produktowej
        
});
$(window).load(function() {

    jQuery('.prod_gallery_photo').jcarousel({
                auto: 2,
                wrap: 'both',
                        animation: 1000,
                        scroll: 2,
                initCallback: mycarousel_initCallback
            });
});
//Fancybox
$(function() {
	$(".prod_gallery li a, .psi_center a, .gate_form_schema a, .pp_wrap li a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	500, 
		'speedOut'		:	200
		
	});

});

$(function() {
	//submenu
	$('.submenu a').bind('mouseenter',function(){
		$('.submenu li').removeClass('act2');
		$(this).parents('li').addClass('act2');
	});
	$('.submenu a').bind('mouseleave',function(){
		$('.submenu li').removeClass('act2');
	});
});
$(document).ready(function(){	
	$(".tx-indexedsearch-whatis").next('.tx-indexedsearch-browsebox').remove();
	$(".browsebox li:first").addClass("prev");
	$(".browsebox li:last").addClass("next");
	$(".tx-indexedsearch-browsebox").addClass("wysz_pagina");
	$("#productPage").find(".wysz_menu ul li:last").addClass('active');
	$("#offerPage").find(".wysz_menu ul li:first").addClass('active');


        $('.order_field select').selectmenu({style:'dropdown'});

});
