var MZSP = {
	construct: function() {		
		MZSP.clearInput("query");
		MZSP.bigBoxSlider();
	}/* constructor END */,
	clearInput: function(input) {
		input = "input[name="+input+"]";
		var inputValue = $(input).val();
		$(input).focus(function() {
			if($(this).val()==inputValue) {
        		$(input).val("");
			}
		});
		$(input).blur(function() {
			if($(input).val()=="") {	
				$(input).val(inputValue);
			}
		});
	},
	
	bigBoxSlider: function() {
		var slides = $(".bigNewsBox").size();
		$("#bigBoxContent div").each(function() { $(this).hide(); });
		
		var rand = Math.floor(Math.random()*slides);
		var randBox = $("#bigBoxContent .bigNewsBox").eq(rand);
		randBox.show();
		randBox.find("div").show();
		$("#bigBoxNav a").eq(rand).addClass("bigBoxActive");
		
		function toggleSlides(slideID) {
			$("#bigBoxContent div").each(function() { $(this).hide(); });
			$(".bigNewsBox .wrapperBox").eq(slideID).css("display", "block");
			$(".bigNewsBox").eq(slideID).fadeIn("slow");
			$(".bigBoxActive").attr("class", "");
			$("#bigBoxNav a").eq(slideID).addClass("bigBoxActive");
		}
				
		$("#bigBox").everyTime(7000, function(){
			rand++;
			if(rand==slides) rand = 0;
			toggleSlides(rand);
		});
		
		var bigBoxClick = $("#bigBoxNav a").click(function() {
			$("#bigBox").stopTime();
			toggleSlides(bigBoxClick.index(this));
			return false;
		});
	},

	trimDate: function() {
		$(".entryDate").each(function() {
			var dateToTrim = $(this).html();
			$(this).html(dateToTrim.split(" ")[0]);
		});
	},

	




	// FCKEditor image properties translator
	applyImageSpace: function() {
		if (!$.browser.msie) {
			$(".entry img").each(function(){
				var properties = {
					"hspace": $(this).attr("hspace"),
					"vspace": $(this).attr("vspace"),
					"direction": $(this).attr("align")
				};
				if(properties.direction=="left" || properties.direction=="right") {
					// odwrocenie kierunku l-r
					var paddingDir = (properties.direction=="left") ? "right" : "left";
					$(this).css("margin-"+paddingDir, properties.hspace+"px");
				}
				$(this).css({
					"margin-top": properties.vspace/2 + "px",
					"margin-bottom": (properties.vspace/2 > 0) ? properties.vspace/2 + "px" : "10px"
				});
				//alert(properties.vspace/2);
			});
		}
	},
	applyImageCentering: function() {
		$(".entry p img").each(function() {
			if ($(this).parent().css('text-align') == 'center' && $(this).css('float')=='none') {
				var border = $(this).css("border-width");
				var imgWidth = $(this).attr("width");
				var parWidth = $(this).parent().width();
				var margin = (parWidth - imgWidth) / 2;
				$(this).parent().css('margin-left', margin+'px');
			}
		})
	}
}

$(document).ready(function() { MZSP.construct(); });


