
$(document).ready(function() {
	
	// SLIDESHOW
	$('#slideshow').after('<div id="slideNav" class="slideNav"><div>').cycle({
		fx:     'fade',
		speed:  '1000',
		timeout: '5000',
		pager:  '#slideNav DIV'
	});



	// DROPDOWN
        $('UL.drop').hide();
	
	    $('#mainNav UL LI').hover(
		function() {
		
		$('UL.drop',this).stop(true, true).slideDown(300);
		
		},
		function() {
		
		$('UL.drop',this).stop(true, true).slideUp(200);
		
		}
	    );
	    
	// STYLE SWITCH
	$('.colorSwitch UL LI A').styleSwitcher();
	
            $("DIV.colorSwitch UL").hide();
            $("DIV.colorSwitch").css('cursor','pointer').hover(function(){
                $("UL", this).stop(true, true).slideDown(300);
                }, function() {
                $("UL", this).stop(true, true).slideUp(300);
                });
	
            $("DIV.langSwitch UL").hide();
            $("DIV.langSwitch").css('cursor','pointer').hover(function(){
                $("UL", this).stop(true, true).slideDown(300);
                }, function() {
                $("UL", this).stop(true, true).slideUp(300);
                });
	
	// SPRAWDZANIE LOKACJI + ZAZNACZENIE

            //var loc = window.location.toString().split("/")

            //loc = loc[loc.length - 1]
            
            var loc = window.location.toString();


            $("#mainNav UL.main LI A:first[href=\""+loc+"\"]").attr("class","selected"); // dla nawigacji głównej
	    
            $("DIV#leftNav H3 A[href~=\""+loc+"\"]").parent().attr("class","selected"); // dla nawigacji produktów
				
				$("DIV#leftNav UL LI A[href~=\""+loc+"\"]").parent().attr("class","selected"); // dla nawigacji produktów
				
				$("DIV#leftNav UL LI A[href~=\""+loc+"\"]").parents('.group').children('h3').attr("class","selected"); // dla nawigacji produktów
	    
            //$("DIV#privatelabel DIV.nav UL LI A[href~=\""+loc+"\"]").attr("class","selected"); // dla nawigacji private label
            
	    
	    
	    
	// ROZWIJANE MENU Z LEWEJ STRONY
            $('div#leftNav H3[class!=selected]').next().hide();
                        
            $('div#leftNav H3').click(function() {
                $(this).next().slideToggle();
            });
            
	// ZMIANA WIDOKU (MINIATURY/LISTA)
            $("DIV#changeView A").click(function(event){
            	event.preventDefault();
					var url = $(this).attr('href');
					
            	if( $(this).hasClass('swap') )
            	{
   	         	var style = '';
      	      	$.post(url, { val: style } );
         	       $(this).removeClass("swap");
            	    $("UL#products").fadeOut("fast", function() {
                      $(this).fadeIn("fast").removeClass("thumb_view");
                   });            		
            	} else {
	            	var style = 'swap';
   	         	$.post(url, { val: style } );
      	         $(this).addClass("swap");
         	      $("UL#products").fadeOut("fast", function() {
            	      $(this).fadeIn("fast").addClass("thumb_view"); 
                  });
            	}
		
            });
	    
	// CZYSZCZENIE POLA INPUT PO KLIKNIĘCIU
		$.fn.clearDefault = function(){
				return this.each(function(){
					var default_value = $(this).val();
					$(this).focus(function(){
						if ($(this).val() == default_value) $(this).val("");
					});
					$(this).blur(function(){
						if ($(this).val() == "") $(this).val(default_value);
					});
				});
			};
	
	$('INPUT.clearme, TEXTAREA').clearDefault();
	

});
