var $j = jQuery.noConflict();

			


$j(document).ready(function(){
							
							
					// menu accordion
	$j(".podkategorie").hide();	
	//$j('.trig2:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
	$j(".trig2").toggle(function(){
				$j(this).addClass("active"); 
					}, function () {
				$j(this).removeClass("active");
				});		
	$j(".trig2").click(function(){
			$j(this).next(".podkategorie").slideToggle("slow,");			
		});	
	if( $j("h2#active").next().is(':hidden') ) { //If immediate next container is closed...
		$j('h2.trig2').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		//$j(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
		 $j("h2#active").removeClass("active").click();		  
	}



// this code uses "toggle_trigger" instead of just "trigger"
// functions to allow open all toggle_containers
// and activate all toggle_triggers

//function toggle_all_on() {
//$j(".toggle").slideDown();
//$j(".trig2").not('.active').addClass("active").toggle(function(){
//$j(this).addClass("active");
//}, function () {
//$j(this).removeClass("active");
//});
//}

//function toggle_all_off() {
	//$j(".toggle").slideUp();
	//$j(".trig2.active").removeClass("active").toggle(function(){
						//$j(this).addClass("active");
						//}, function () {
						//$j(this).removeClass('active').next().slideUp(); 
	//});
//}

//$j(".toggleon").click(toggle_all_on);
//$j(".toggleoff").click(toggle_all_off);

  
//Set default open/close settings
//$j('.toggle').hide(); //Hide/close all containers
//$j('.trig:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
//On Click
//$j('.trig').click(function(){
	//if( $j(this).next().is(':hidden') ) { //If immediate next container is closed...
		//$j('.trig').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		//$j(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
	//}
	//else {
	//	$j(this).removeClass('active').next().slideUp()
	//}	
	//return false; //Prevent the browser jump to the link anchor
//});
//$j('span#active').click();			
	
							
		
	var wysokosc1 = $j('#nowo').find('.oferta_n').height();
	$j('#nowo .boks_centrum_n').css("height", wysokosc1+60);
	$j('#nowo .szara_podkladka').css("height", wysokosc1+60);
	$j('#nowo .szara_podkladka div').css("height", wysokosc1+60);
	
	
	var wysokosc2 = $j('#promo').find('.oferta').height();
	$j('#promo .boks_centrum').css("height", wysokosc2+60);
	$j('#promo .szara_podkladka').css("height", wysokosc2+60);
	$j('#promo .szara_podkladka div').css("height", wysokosc2+60);
	

	
	
	//$j('.podkategorie').hide();
	//$j('.strzalka_l').hide();
	//$j('.strzalka_l_n').hide();
	
	//$j('.glowna_kategoria').click(function(){
	//	$j(this).toggleClass('wybrana').next('ul.podkategorie').slideToggle("slow");
	//	return false; 
	//});
	
	
	
	/* Tabs Activiation
	================================================== */
	var tabs = $j('ul#slider_bullets');
	
	tabs.each(function(i) {
		//Get all tabs
		var tab = $j(this).find('> li > a');
		tab.click(function(e) {
			
			//Get Location of tab's content
			var contentLocation = $j(this).attr('href') + "_img";
			
			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {
			
				e.preventDefault();
				
			
				//Make Tab Active
				tab.removeClass('selected_img');
				$j(this).addClass('selected_img');
				
				//Show Tab Content & add active class
				$j(contentLocation).show().addClass('selected_img').siblings().hide().removeClass('selected_img');
				
				return false;
				
			} 
		});
	}); 
	
	
	function slide(dir) {
		
		var iloscOfert_1 = $j('#promo').find('.oferta').length;
		var iloscOfert = parseInt(iloscOfert_1);
		var viewportW = $j('.boks_centrum').width();
		var moveWidth = $j('.oferta').outerWidth(true);
		var slideWidth = iloscOfert*moveWidth;
		var slideLeftCss = $j('.slides').css("left");
		slideLeft = parseInt(slideLeftCss);
		
		if (slideWidth>viewportW) {
			if (dir==0) {
				
				if (slideLeft==-(slideWidth/2)+moveWidth) {
					$j('.strzalka_p').hide();
				}
				
				if (slideLeft>0-moveWidth) {
					$j('.strzalka_l').show();
					}
				
				if (slideLeft>=(viewportW-slideWidth)+moveWidth) {
					$j('.strzalka_p').addClass("disabled");
					$j('.slides').animate({left: "-="+moveWidth}, "slow", function() { $j('.strzalka_p').removeClass("disabled"); });	
					}
				
			} else if (dir==1) {
				if (slideLeft+moveWidth<=0) {
					$j('.strzalka_l').addClass("disabled");
					$j('.slides').animate({left: "+="+moveWidth}, "slow", function() { $j('.strzalka_l').removeClass("disabled"); });
					}
				if (slideLeft>-(slideWidth/2)-moveWidth) {
					$j('.strzalka_p').show();
					}
				if (slideLeft==0-moveWidth) {
					$j('.strzalka_l').hide();
					}
				
				}
			}
		};
	
	
	$j('.strzalka_p').click(function(){
		if (!$j(this).hasClass("disabled")) slide(0);
	});
	
	$j('.strzalka_l').click(function(){
		if (!$j(this).hasClass("disabled")) slide(1);
		
	});
	
	
	function slide_n(dir) {
		
		var iloscOfert_1 = $j('#nowo').find('.oferta_n').length;
		var iloscOfert = parseInt(iloscOfert_1);
		var viewportW = $j('.boks_centrum_n').width();
		var moveWidth = $j('.oferta_n').outerWidth(true);
		var slideWidth = iloscOfert*moveWidth;
		var slideLeftCss = $j('.slides_n').css("left");
		slideLeft = parseInt(slideLeftCss);
		
		if (slideWidth>viewportW) {
			if (dir==0) {
				if (slideLeft>=(viewportW-slideWidth)+moveWidth) {
					$j('.strzalka_p_n').addClass("disabled");
					$j('.slides_n').animate({left: "-="+moveWidth}, "slow", function() { $j('.strzalka_p_n').removeClass("disabled"); });	
				} 
				if (slideLeft==-(slideWidth/2)+moveWidth) {
					$j('.strzalka_p_n').hide();
				}
				
				if (slideLeft>0-moveWidth) {
					$j('.strzalka_l_n').show();
					}
			} else if (dir==1) {
				if (slideLeft+moveWidth<=0) {
					$j('.strzalka_l_n').addClass("disabled");
					$j('.slides_n').animate({left: "+="+moveWidth}, "slow", function() { $j('.strzalka_l_n').removeClass("disabled"); });
				}
				if (slideLeft>-(slideWidth/2)-moveWidth) {
					$j('.strzalka_p_n').show();
					}
				if (slideLeft==0-moveWidth) {
					$j('.strzalka_l_n').hide();
				}
			}
		}
	};
	
	
	$j('.strzalka_p_n').click(function(){
		if (!$j(this).hasClass("disabled")) slide_n(0);
	});
	
	$j('.strzalka_l_n').click(function(){
		if (!$j(this).hasClass("disabled")) slide_n(1);
	});
	

		
	

	
});







