$(document).ready(function() {
	// FORMULARZ ZGLOSZENIOWY
	$("div.wpcf7-2-column-row-container input[type=text], div.wpcf7-2-column-row-container textarea").addClass("editable");
	$("div.wpcf7-2-column-row, div.wpcf7-2-column-row-50").append("<div class='clear'></div>");
	$(".wpcf7-submit-button input#wpcf7-submit-button").addClass("radius");
	$("div.wpcf7-2-column-row-container input[type=checkbox]").click(function() {
		if($(this).is(":checked")) {
			$(this).parent().parent().parent().parent().parent().addClass("green-highlight");
		} else {
			$(this).parent().parent().parent().parent().parent().removeClass("green-highlight");
		}
		
	});
	$("div.wpcf7-2-column-row-container").hover(
		function() {
			$(this).addClass("wpcf7-2-column-row-container-hovered");
		},
		function() {
			$(this).removeClass("wpcf7-2-column-row-container-hovered");
		}
	);
	
	$("span.Forum-PPP-Liczba-Egzemplarzy input").addClass("inline-input");
	$("span.Forum-PPP-Liczba-Egzemplarzy").parent().children("br").remove();
	
	// CLOCK IN THE WIDGETS
	$(".widget-clock").wrap('<div class="widget-clock-container radius" />');
	$(".widget-clock-container").wrap('<div class="widget-clock-container-container" />');
	$(window).load(function() {
		$('#clock-losangeles').jclock({
			utc: true,
			utc_offset: -8
		});	
		$('#clock-saopaulo').jclock({
			utc: true,
			utc_offset: -2
		});
		$('#clock-london').jclock({
			utc: true,
			utc_offset: 0
		});
		$('#clock-warsaw').jclock({
			utc: true,
			utc_offset: 1
		});
		$('#clock-moscow').jclock({
			utc: true,
			utc_offset: 4
		});
		$('#clock-bombaj').jclock({
			utc: true,
			utc_offset: 5.5
		});
		$('#clock-shanghai').jclock({
			utc: true,
			utc_offset: 8
		});
		$('#clock-sydney').jclock({
			utc: true,
			utc_offset: 11
		});

	});

	// STATPRESS WIDGET
		var total_visits = parseFloat($("strong#page-total-visits-stat").text());
		var total_total_visits = total_visits+31000;
		$("strong#page-total-visits-stat").text(total_total_visits)
	
	// WP TABLE RELOADED
		$("table.wp-table-reloaded").wrap('<div class="wp-table-reloaded-container" />');
		$("table.wp-table-reloaded tbody tr").hover(
			function() {
				$(this).addClass("hovered");
			},
			function() {
				$(this).removeClass("hovered");
			}
		);
	// Fix thumbnail layout
		$(".ippp-blog-post-image a").not(".ippp-blog-post-image a:has('img')").parent().remove();
		
	// Format bottom links
		// DELETE CATEGORY HEADERS WHEN THERE IS ONLY ONE
		$("#ippp-bottom-page-links li h2:contains('[x]')").remove();
		
		// ONE LEVEL MENU
		$("ul#ippp-bottom-page-links li.linkcat").css("clear","both");
		$("ul#ippp-bottom-page-links li > a:first-child").parent().addClass("sublinks");
		$("ul#ippp-bottom-page-links li.sublinks").each(function() {
			$(this).children("a").removeAttr("title");
			$(this).children("a").wrap("<div />");
			var link_content = $(this).children("div").html();
			$(this).children("div").remove();
			var text_content = $(this).text();
			$(this).html('<div class="bottom-links-text"></div>');
			$(this).children("div.bottom-links-text").html(text_content);
			$(this).prepend(link_content);
		});
		$("ul#ippp-bottom-page-links li.sublinks a").hover(
			function() {
				$(this).parent().addClass("hovered");
			},
			function() {
				$(this).parent().removeClass("hovered");
			}
		);

		$("ul#ippp-bottom-page-links li.sublinks").addClass("radius");
		$("ul#ippp-bottom-page-links li.sublinks:odd").addClass("odd");
		$("ul#ippp-bottom-page-links li.sublinks:even").addClass("even");
		$("ul#ippp-bottom-page-links li.sublinks:nth-child(2n+1)").css("clear","both");
		// TWO LEVEL MENU

		
	// PDF Files Formatting
		$(".pdf-file-container").addClass("rightradius");
		$(".pdf-file-container:odd").addClass("odd");
		$(".pdf-file-container:even").addClass("even");
		$(".pdf-file-container").next("br").remove();
		$(".pdf-file-container:nth-child(2n+1)").css("clear","both");
		$(".public-pdf").hover(
			function() {
				$(this).addClass("public-pdf-hovered");
			},
			function () {
				$(this).removeClass("public-pdf-hovered");
			}
		);
		
	// Fancy list signs on the front page
		$("div.front-page-widget-content p strong:contains('♦')").each(function() {
			$(this).html('<span class="front-page-widget-list-point"></span>');
			$(this).parent().css("margin-left","10px");
		});
		
	// Fix "justify" on front page
		$(".front-page-widget-content div.textwidget p").css("text-align","left");
		
	// Clock widgets center
		$(".ippp-widget-content div table tbody tr td div:has('object')").css("margin-left","auto").css("margin-right","auto").css("margin-bottom","15px").css("position","relative");
	// Clock widgets remove link
		$(".ippp-widget-content div table tbody tr td div:has('object') a img").unwrap();
		$(".ippp-widget-content div table tbody tr td div:has('object')").append('<div class="world-clock-overlay"></div>');
	// Clock widgets main title
		$(".widget-title:contains('World Clock')").text("Czas na świecie");
		
		
	// Breadcrumbs formatting
		$("#ippp-breadcrumbs span.breadcrumb:last-child").addClass("bold");
		
	// Footer Information formatting
		$("div#footer-information-right ul li:last-child a").addClass("bottomrightradius");
		
	// Menu Parent Link FIX - get the href from the first child
		$("div#ippp-menu > ul > li > ul > li:first-child").each(function() {
			var first_link = $(this).children("a").attr("href");
			$(this).parent().parent().children("a").attr("href",first_link);
			
		});
		
	// Menu Rounded Corners
		$("div#ippp-menu > ul > li:first, div#ippp-menu > ul > li:first > a").addClass("topradius");
		$("div#ippp-menu > ul > li:last-child, div#ippp-menu > ul > li:last-child > a").addClass("bottomradius");
		
	// Menu Arrows Bottom
		$("div#ippp-menu ul > li:has('ul')").append('<div class="arrow-on"></div>');
	// Submenu Show / Hide
		$("div.arrow-on").click(function() {
			$(this).parent().children("ul").slideToggle(500);
			$(this).toggleClass("arrow-on").toggleClass("arrow-off");
		});
		$("div#ippp-menu ul li.current_page_item, div#ippp-menu ul li.current_page_parent, div#ippp-menu ul li.current_page_ancestor > a").each(function() {
			$(this).children("ul").show();
			$(this).children(".arrow-on").toggleClass("arrow-on").toggleClass("arrow-off");
		});
	// Animate Go To top
		$("a.go-to-top").click(function() {
			$('html,body').animate({scrollTop: 0}, 600);
		});
	
	// Footer Members Formatting
		
		$("#ippp-members-links").find("li").slice(0,6).wrapAll("<ul/>");
		$("#ippp-members-links").find("li").slice(6,12).wrapAll("<ul/>");
		$("#ippp-members-links").find("li").slice(12,18).wrapAll("<ul/>");
		$("#ippp-members-links").find("li").slice(18,24).wrapAll("<ul/>");
		$("#ippp-members-links").find("li").slice(24,30).wrapAll("<ul/>");
		$("#ippp-members-links").find("li").slice(24,36).wrapAll("<ul/>");
		// Vertical Align
		$(window).load(function() {
		// Create Blocks
			 $("#ippp-members-links ul li").each(function() {
				var image_height = parseFloat($(this).children("a").children("img").height());
				var container_height = parseFloat($(this).height());
				if(container_height > image_height) {
					var height_difference = container_height - image_height;
					var padding = height_difference / 2;
					$(this).children("a").css("padding-top",padding);
				};
			}); 
			
			$("#ippp-members-links").cycle({
				fx: 'fade',
				speed: '1000',
				timeout: '5000'
			});
			$("div#ippp-slideshow-container ul").cycle({
				fx: 'fade',
				speed: '1000',
				timeout: '7000'				
			}).css("background","#FFF");
			$("div#ippp-slideshow-container ul li").show();

		});
		
	// Loop Widgets
		$("div.front-page-widget-container:even").addClass("first-widget");
		$("div.front-page-widget-container:odd").addClass("second-widget");
		$("div.front-page-widget-container a.readmore").addClass("radius");
		$("div.front-page-widget-content:has('a.readmore')").addClass("contains-readmore");
		
	// Rounded Corners to forms in Right Widgets
		$("form#loginform input#wp-submit").addClass("radius");
		$("#searchform div input#searchsubmit ").addClass("radius");
		
		
		

		
});
