(function($){
    $(document).ready(function(){
		$(document).pngFix(); 
		// 00. GLOBAL CUNTIONS
			var total_visits = parseFloat($("#totalvisits").text());
			$("#totalvisits").text(total_visits+5372);
		
		// Odstępy w tabelach
		$("div.expresso-loop-content table tr td").css("padding-left","10px").css("padding-right","10px").attr("valign","top");
		$("div.expresso-loop-content table tr td:nth-child(2)").css("padding-top","30px");
		$("div.expresso-loop-content table tr td:nth-child(1)").css("padding-top","10px").css("padding-bottom","10px");
		
		
		
		// Obsługa panelu dla zagubionych klientów
			var popup_help_status = $.cookie('rosenthal_help');
			if(popup_help_status != 'closed') {
			$("#lost-user-question-bg").delay(20000).fadeIn(500);
			$("#lost-user-question-wrap").delay(20500).slideDown(500);
			$("#lost-user-question-close").delay(21000).fadeIn(200);
			}
			
			$("#lost-user-question-close").click(function() {
				$("#lost-user-question-close").fadeOut(100);
				$("#lost-user-question-wrap").slideUp(300);
				$("#lost-user-question-close").delay(300).fadeOut(400,function() {
					$("#lost-user-question-bg").remove();
					$("#lost-user-question-wrap").remove();
				})
				$.cookie('rosenthal_help', 'closed', { 
					expires: 1, 
					path: '/',
					domain: 'www.rosenthal.szczecin.pl'
				});
			});
		
		// Uzupełnianie marki
			var current_brand = $("#expresso-breadcrumbs a:nth-child(5)").text();
			if(current_brand == '') {
				var current_brand = $("#expresso-breadcrumbs span.expresso-current-page").text();
			}
			$("div.ngg-galleryoverview input.ask-for-item-brand").each(function() {
				$(this).val(current_brand);
			});
			$("body.page-id-32 .ask-for-item-form").remove();
			$("img.no-link").parent().parent().parent().children("form.ask-for-item-form").remove();
		
		// Wypełnianie formularza
			if($("#wpcf7-f3-p993-o1").length > 0) {
				var ask_product_name = $("div#product-name-form").text();
				var ask_product_link = $("div#product-name-link").text();
				var ask_product_brand = $("div#product-name-brand").text();
				
				$("div#wpcf7-f3-p993-o1 form input[name='marka']").val(ask_product_brand);
				$("div#wpcf7-f3-p993-o1 form input[name='opis']").val(ask_product_name);
				$("div#wpcf7-f3-p993-o1 form input[name='link']").val(ask_product_link);
				$("#ask-form-information").remove();
			}
			
		
			
		// Popup na pierwszej stronie 
			$("div.front-page-popup-container").hide();
			$("div.front-page-popup-bg").hide();
			
				$("input#mc_mv_EMAIL").val("Podaj swój adres e-mail").addClass("blured");
				$("input#mc_mv_FNAME").val("Podaj swoje imię").addClass("blured");
				$("input#mc_mv_LNAME").val("Podaj swoje nazwisko").addClass("blured");
				$("div.front-page-popup input").not("div.front-page-popup input#mc_signup_submit").focus(function() {
					if($(this).hasClass("blured")) {
						var empty_text = $(this).val();
						$(this).val("");
						$(this).removeClass("blured");
					}
				});
				$("div.front-page-popup input").not("div.front-page-popup input#mc_signup_submit").blur(function() {
					var input_value = $(this).val();
					var input_attr = $(this).attr("id");
					if(input_value == '') {
						$(this).addClass("blured");
						if(input_attr == 'mc_mv_EMAIL') { $(this).val("Podaj swój adres e-mail"); };
						if(input_attr == 'mc_mv_FNAME') { $(this).val("Podaj swoje imię"); };
						if(input_attr == 'mc_mv_LNAME') { $(this).val("Podaj swoje nazwisko"); };
					}
				});
				
				
				
				// Wypełnianie pól tekstowych wstępnymi informacjami
				
				// Loader na czas oczekiwania 
				$("div.front-page-popup .mc_signup_submit input").click(function() {
					$("#mc_message").html("<div class='front-page-loader'></div>");
				});
				
				
				// Zamykanie okna
				$("div.front-page-popup-close").click(function() {
					$("div.front-page-popup-close").fadeOut(200);
					$("div.front-page-popup-container").delay(200).slideUp(400);
					$("div.front-page-popup-bg").delay(600).fadeOut(600);
					$.cookie('rosenthal_popup', 'closed', { 
						expires: 3, 
						path: '/',
						domain: 'www.rosenthal.szczecin.pl'
					});
				});
				$("div.front-page-popup-bg").click(function() {
					$("div.front-page-popup-close").fadeOut(200);
					$("div.front-page-popup-container").delay(200).slideUp(400);
					$("div.front-page-popup-bg").delay(600).fadeOut(600);
					$.cookie('rosenthal_popup', 'closed', { 
						expires: 3, 
						path: '/',
						domain: 'www.rosenthal.szczecin.pl'
					});
				});
				
			// Pokazywanie popupu po klikniecu na guzik po prawej stronie
			$("div#side-newsletter-button").click(function() {
				$("div.front-page-popup-bg").fadeIn(1000);
				$("div.front-page-popup-container").delay(700).slideDown(600);
				$("div.front-page-popup-close").delay(1300).fadeIn(500);			
			});
			
			// Pokazywanie popupu na pierwszej stronie
			
			if($("body").hasClass("home")) {
				var popup_cookie = $.cookie('rosenthal_popup');
				// Pojawianie się okienka na pierwszej stronie
				if(popup_cookie != 'closed' && popup_cookie != 'subscribed') {
				$("div.front-page-popup-bg").delay(1000).fadeIn(1000);
				$("div.front-page-popup-container").delay(1700).slideDown(600);
				$("div.front-page-popup-close").delay(2300).fadeIn(500);
				}
			}
			

		
		// Product Table Formatting
			
			// Dodanie PLN do wszystkich cen
			$("table.wp-table-reloaded tr td.column-3").each(function() {
				var amount = parseFloat($(this).text());
				$(this).text(""+amount+" PLN")
			});
			// Dodanie klas do formatowania rzedow
			$("table.wp-table-reloaded tr:odd").addClass("odd-table");
			$("table.wp-table-reloaded tr.odd-table td img").parent().parent().removeClass("odd-table");
			// Zamiana linków na obrazki
			$("table.wp-table-reloaded tr td.column-4").each(function() {
				var img_link = $(this).text();
				
				$(this).empty();
				$(this).append("<div class='add-to-list-table'>Dodaj do listy</div>");
				if(img_link != '') {
					$(this).append("<a href='"+img_link+"' class='fancybox table-button'>Zobacz zdjęcie</a>");
				};
							
			});
			
			
			
			/* Hover w tabeli podczas najezdzania myszka */
			$("table.wp-table-reloaded tr").hover(
				function() {
					$(this).addClass("hovered");
				},
				function() {
					$(this).removeClass("hovered");
				}
			);
			
			
		
		
		// Statpress modification
			var total_amount = parseFloat($("strong#statpress-total-visits").text());
			var verified_amount = total_amount+400;
			$("strong#statpress-total-visits").text(verified_amount);
		
		// Subpages formatting
			$("ul.subpages-container li").not("ul.subpages-container li:has('div')").remove();
			$("ul.subpages-container li:nth-child(2n)").addClass("second-column");
			// $("ul.subpages-container li:nth-child(2n+1)").css("clear","both");
		

		
		// NEXTGEN FORMATTING
			$(".ngg-galleryoverview .ngg-gallery-thumbnail-box:nth-child(5n) .galleryblock").addClass("galleryblock-last");
			$(".ngg-albumoverview .galleryblock").append('<div class="clear"></div>');
		
		// RIGHT SIDEBAR LOGO FORMATTING
			$("h3.expresso-sidebar-widget-title:contains('Nasze marki')").remove();
			$("div.expresso-sidebar-widget-container ul.xoxo li:nth-child(2n)").addClass("second-logo");
			$("div.expresso-sidebar-widget-container ul.xoxo li").hover(
				function() {
					$(this).stop(true,true).animate({
						opacity: 0.6
					});
				},
				function() {
					$(this).stop(true,true).animate({
						opacity: 1.0
					});
				}
			);
		
		// 01. MAIN MENU
		// Menu on the top of the page
			// IE7 / IE6 FIX
				if(($.browser.msie && $.browser.version=="6.0") || ($.browser.msie && $.browser.version=="7.0")) { 
					
				} else {
					$("ul#expresso-page-header-menu ").css("width","auto");
				};
	
			
			// 01a. FIX FOR WHEN MENU IS A WIDGET
			$("ul#expresso-page-header-menu div").unwrap();
			$("div#expresso-page-header-menu-wrap div ul:first").attr('id','expresso-page-header-menu');
		
			// 01b. ANIMATIONS
				// First level animations
					$("ul#expresso-page-header-menu > li").hover(
						function() {
							$(this).children("ul").stop(true, true).slideDown(300);
						},
						function() {
							$(this).children("ul").stop(true,true).slideUp(100);
						}
					);
					
				// All levels but firstChild
					$("ul#expresso-page-header-menu li ul li").hover(
						function() {
							$(this).children("ul").stop(true,true).show(200);
						},
						function() {
							$(this).children("ul").stop(true,true).hide(100);
						}
					);
				
			// 01c. IE fix
				$("ul#expresso-page-header-menu li").hover(
					function() {
						$(this).addClass("hovered");
						$(this).children("ul").addClass("ul-hovered");
					},
					function() {
						$(this).removeClass("hovered");
						$(this).children("ul").removeClass("ul-hovered");
					}
				);
			
			// 01d. CORNERS
				$("ul#expresso-page-header-menu li").each(function() {
					// Overall Radius
					$(this).children("ul").addClass("bottomradius");
					
					// Bottom Radius
					$(this).children("ul").children("li:last").addClass("bottomradius");
					$(this).children("ul").children("li:last").children("a").addClass("bottomradius");

					// Top Corners of menu
					// $("#expresso-page-header-menu-wrap-wrap").addClass("topradius");
					// $("#expresso-page-header-menu-wrap-wrap-wrap li:first").addClass("topleftradius");
					// $("#expresso-page-header-menu-wrap-wrap-wrap li:first a:first").addClass("leftradius");
					
				});
			
			// 01e. CURRENT
				$("ul#expresso-page-header-menu li").hover(
					function() {
						$(this).addClass("currently-hovered");
						$(this).children("a").addClass("currently-hovered");

					},
					function() {
						$(this).removeClass("currently-hovered");
						$(this).children("a").removeClass("currently-hovered");

					}
				);
				$("ul#expresso-page-header-menu li.current_page_item, ul#expresso-page-header-menu li.current_page_ancestor").each(function() {
					$(this).addClass("expresso-current-page");
					$(this).children("a").addClass("expresso-current-page");
				});
			
			// 01f. LAST CLASSES
				$("#expresso-page-header-menu ul li:last-child").addClass("menu-last-li");
				$("ul#expresso-page-header-menu > li:last-child").addClass("first-level-last-li");

			// 01g. NAVIGATION ARROWS
				$("#expresso-page-header-menu > li:has('ul') > a").append("<span class='arrow'></span>");
				$("#expresso-page-header-menu li ul li:has('ul') > a").append("<span class='arrow'></span>");
		

				
		// 02. SECOND MENU
		// Secone menu at the bottom of the page
		
			// 02a. FIX FOR WHEN SECOND MENU IS A WIDGET
			$("div#expresso-second-menu-container ul div").unwrap();
			$("div#expresso-second-menu-container div ul:first").unwrap();
		
			// 02b. ANIMATE FIRST LEVEL SUBMENU
				// First level animations
					$("div#expresso-second-menu-container > ul > li").hover(
						function() {
							$(this).children("ul").stop(true, true).slideDown(300);
						},
						function() {
							$(this).children("ul").stop(true,true).slideUp(100);
						}
					);
			// 02c. ANIMATE SECOND LEVEL SUBMENU
					$("div#expresso-second-menu-container ul li ul li").hover(
						function() {
							$(this).children("ul").stop(true,true).show(200);
						},
						function() {
							$(this).children("ul").stop(true,true).hide(100);
						}
					);
			// 02d. ADD CORNERS TO MENU
				$("div#expresso-second-menu-container ul li").each(function() {
					// Overall Radius
					$(this).children("ul").addClass("shadow").addClass("bottomradius");
					
					// Bottom Radius
					$(this).children("ul").children("li:last").addClass("bottomradius");
					$(this).children("ul").children("li:last").children("a").addClass("bottomradius");

					// Top Right Radius for last ul
					
				});
			
			// 02e. CURRENT
				$("div#expresso-second-menu-container ul li.current_page_item, div#expresso-second-menu-container ul li.current_page_ancestor")
				.not("div#expresso-second-menu-container > ul > li.current_page_item")
				.not("div#expresso-second-menu-container > ul > li.current_page_ancestor")
				.each(function() {
					$(this).addClass("expresso-current-page");
					$(this).children("a").addClass("expresso-current-page");
				});
			$("div#expresso-second-menu-container > ul > li.current_page_item, div#expresso-second-menu-container > ul > li.current_page_ancestor").each(function() {
					$(this).addClass("expresso-current-page-first");
					$(this).children("a").addClass("expresso-current-page-first");
				});
			// 02f. LAST CLASSES
			
			// 02g. HOVER CLASSESS
				$("div#expresso-second-menu-container > ul > li").hover(
					function() {
						$(this).addClass("first-li-hover");
						$(this).children("a").addClass("first-a-hover");
					},
					function() {
						$(this).removeClass("first-li-hover");
						$(this).children("a").removeClass("first-a-hover");
					}
				);
				$("div#expresso-second-menu-container ul li li").hover(
					function() {
						$(this).addClass("li-hover");
						$(this).children("a").addClass("a-hover");
					},
					function() {
						$(this).removeClass("li-hover");
						$(this).children("a").removeClass("a-hover");
					}
				);
				
			// 02h. CHILDREN CLASSESS
				$("div#expresso-second-menu-container > ul > li").addClass("first-level-li");
				$("div#expresso-second-menu-container > ul > li > a").addClass("first-level-a");

			// 02i. NAVIGATION ARROWS
				$("div#expresso-second-menu-container > ul > li:has('ul') > a").append("<span class='arrow'></span>");
				$("div#expresso-second-menu-container ul li ul li:has('ul') > a").append("<span class='arrow'></span>");	
			
		// 03. ANIMATION
			// START ANIMATION
				// CODE FOR JQUERY CYCLE
								
				// CODE FOR NIVO SLIDER
									// Start the animation
					$(window).load(function() {
						$('#slider').nivoSlider({
							effect: 'boxRainGrow',
							pauseTime: 5000,
							animSpeed: 1000,
							captionOpacity:0.0,
							directionNav:false
						});
						// Add corners to caption
						$("div.nivo-caption").addClass("box");
						
						// Start Nivo for Gallery Widgets
						$("#gallery-widget-one div.nivoSlider").nivoSlider({
							effect: 'fold',
							directionNav:false,
							controlNav: false,
							captionOpacity:1.0,
							afterChange: function(){
								
							},
							pauseTime:3000
						});
						$("#gallery-widget-two div.nivoSlider").nivoSlider({
							effect: 'fold',
							directionNav:false,
							controlNav: false,
							captionOpacity:1.0,
							afterChange: function(){
								
							},
							pauseTime:3450
						});
						$("#gallery-widget-three div.nivoSlider").nivoSlider({
							effect: 'fold',
							directionNav:false,
							controlNav: false,
							captionOpacity:1.0,
							afterChange: function(){
								
							},
							pauseTime:3900
						});
						$("div.gallery-widget .nivo-caption").addClass("bottomradius");
						// Animation for Gallery Widget Hover
						$("div.gallery-widget").hover(
							function() {
								$(this).stop(true,true).animate({
									marginTop: '-10px'
								});
								$(this).parent().stop(true,true).animate({
									paddingBottom: '38px'
								});
								$(this).children("a.gallery-link").stop(true,true).animate({
									opacity: 0.7
								});
							},
							function() {
								$(this).stop(true,true).animate({
									marginTop: '0px'
								});
								$(this).parent().stop(true,true).animate({
									paddingBottom: '28px'
								});
								$(this).children("a.gallery-link").stop(true,true).animate({
									opacity: 0.0
								});
							}
						);
					});
									
				
				
		// 06. BREADCRUMBS
			// Add class bold to the first element
			$("#expresso-breadcrumbs span:last").addClass("bold");
			
			// Add bottom corners
			$("#expresso-breadcrumbs-container-wrap").addClass("bottomradius");
			
			// Animation Toggle
			$("div#expresso-animation-toggle").click(function() {
				$("div#expresso-show-animation").toggle();
				$("div#expresso-hide-animation").toggle();
				$("div#expresso-animation-container-wrap-wrap-wrap").slideToggle(500);
			});
				
				
		// 07. FOOTER WIDGETS
			// 07a. FIRST CLASS
			$("div.expresso-footer-widget-wrap:first").addClass("first-footer-widget-wrap");
			$("div.expresso-footer-widget:first").addClass("first-footer-widget");
			
			$("div.expresso-footer-widget-wrap:nth-child(2)")
				.addClass("second-footer-widget-wrap")
				.children("div.expresso-footer-widget")
				.addClass("second-footer-widget");
		
			$("div.expresso-footer-widget-wrap:nth-child(2)")
				.addClass("third-footer-widget-wrap")
				.children("div.expresso-footer-widget")
				.addClass("third-footer-widget");
		
			$("div.expresso-footer-widget-wrap:nth-child(2)")
				.addClass("fourth-footer-widget-wrap")
				.children("div.expresso-footer-widget")
				.addClass("fourth-footer-widget");
		
			$("div.expresso-footer-widget-wrap:nth-child(2)")
				.addClass("fifth-footer-widget-wrap")
				.children("div.expresso-footer-widget")
				.addClass("fifth-footer-widget");
		
		// 08. COPYRIGHT BAR
			// 08a. CURRENT CLASSESS
			$("div#expresso-copyright-container ul li.current_page_item, div#expresso-copyright-container ul li.current_page_ancestor").each(function() {
					$(this).addClass("expresso-current-page");
					$(this).children("a").addClass("expresso-current-page");
				});
			// 08b. HOVER CLASSESS
				$("div#expresso-copyright-container ul li").hover(
					function() {
						$(this).addClass("li-hover");
						$(this).children("a").addClass("a-hover");
					},
					function() {
						$(this).removeClass("li-hover");
						$(this).children("a").removeClass("a-hover");	
					}
				);
			// 08c. FIRST CLASS
				$("div#expresso-copyright-container ul li:first").addClass("first-li");
				$("div#expresso-copyright-container ul li:first a").addClass("first-a");
				$("div#expresso-copyright-container ul li:first").hover(
					function() {
						$(this).addClass("first-li-hover");
						$(this).children("a").addClass("first-a-hover");
					},
					function() {
						$(this).removeClass("first-li-hover");
						$(this).children("a").removeClass("first-a-hover");
					}
				);
				
				
				
		// 09. GLOBAL SCRIPTS
		// Used to handle the whole page and its elements
			
			// Show page after jQuery is executed
				$("body").show();
				$("div.mapp-container").css("width","auto");
				$("div.mapp-canvas-panel").css("width","auto").css("height","auto");

					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
				
				
				$("#expresso-body").show();
});
})(jQuery);
