$(window).load(function () {
	// $('body').prepend('<div id="loding"></div>');
	$('#loading').fadeOut('fast');
});


Cufon.replace('#info div', {hover: true});

google.setOnLoadCallback(function() {
	

	var gallery = $("#horizontal-gallery");
	var element = $("#horizontal-gallery li");
	
	var next = $("#next-img");
	var prev = $("#prev-img");
	
	var distance = 20; // margin size	
	var elementNr = element.length; // numver of elements
	
	var elementsWidth = 0;
	element.find("img").each(function() {
		elementsWidth = $(this).attr('width') + elementsWidth;
	}); // total width's of elements
	
	var galleryWidth = elementNr * distance + elementsWidth; // total width's of elements + margin
	
	gallery.width(galleryWidth + 285); // set width to the holder
	// inner mar a csoda ...
	
	$("#horizontal-gallery").css("padding", 0);
	$("#horizontal-gallery li:first").addClass("first current");
	var cloneHtml = $('.copyright').html();
	$("#horizontal-gallery li:last").addClass("last").append('<p class="copyright-inner">' + cloneHtml + '</p>').after('<div class="back"><a href="#"><span>back</span></a></div>');
	var lastPos = (elementsWidth - $("#horizontal-gallery li:last").width() + ((elementNr - 1) * distance));


	next.click(function() {
			
		if(gallery.offset().left != - (lastPos)) {
		// if() {
			var position = gallery.offset().left;
			
			var currentPos = $('.current').offset().left;
			var nextPos = $('.current').next().offset().left;
			
			gallery.stop().animate({
				'left':  position - nextPos + 265
			}, 250, function() {
				$("li.current").removeClass("current").next().addClass("current")
			})
			
			return false;
		} else {
			return false;
		}
				
	});
	
	prev.click(function() {
			
			if(gallery.offset().left != 0 ) {
				var position = gallery.offset().left;
				
				var currentPos = $('.current').offset().left;
				var prevPos = $('.current').prev().offset().left;
				
				gallery.stop().animate({
					'left':  position - prevPos + 265
				}, 250, function() {
					$("li.current").removeClass("current").prev().addClass("current")
				})
				
				return false;	
			} else {
				return false;
			}
				
	});
	
	$('.back a').click(function() {
			
			gallery.stop().animate({
				'left':  0
			}, 250, function() {
				$("li.current").removeClass("current");
				$("#horizontal-gallery li:first").addClass("current");
			})
			return false;
				
	});
	
	$("#categories li:not(.current_page_item)").hover(
	      function () {
	        // $(this).find('img').css("top", "-14px")
			$(this).find('img').stop().animate({top: "-14px"}, 200)
	      }, 
	      function () {
	        $(this).find('img').stop().animate({top: "0px"}, 200)
	      }
	    );

	
});
