jQuery.noConflict();

(function($){
	$(function(){
		var $htmlViewer = $('textarea.html-viewer');
	
		var $generateLinks = $('a.generate-html');
		
		if($generateLinks.length > 0)
		{
			var hash = window.location.toString().indexOf('#');
			if(hash != -1) {
				window.location = window.location.toString().substring(0, hash);
			}
		}
		
		$generateLinks
			.each(function(){
				var $this = $(this);
				$this.data('href', $this.attr('href'));
			})
			.attr('href', window.location + '#html-viewer')
			.click(function()
			{
				var $this = $(this);
				var $image = $('img', $this);
			
				var html = '<a href="' + $this.data('href') + '" target="_blank" title="' + $this.attr('title') + '">' + "\n";
				
				if($image.length == 1) {
					html += "\t" + '<img width="' + $image.width() + '" height="' + $image.height() + '" border="0" src="' + $image.attr('src') + '" alt="' + $image.attr('alt') + '" />' + "\n";
				}
				
				html += '</a>';
				
				$htmlViewer.val(html);
			});
		
		$galleries = $('.netgroup-gallery');
		
		if($galleries.length > 0)
		{
			$galleries.each(function()
			{
				$gallery = $(this);
				$thumbs = $('.thumbs', $gallery);
							
				$thumbs.css('overflow-x', 'hidden').after('<div class="scroll-left"></div><div class="scroll-right"></div>');				
				
				$scrollLeft = $thumbs.next();
				
				$scrollLeft
					.width(15).height(17).css('cursor', 'pointer')
					.css('background-image', 'url(tl_files/images/arrow_prev.gif)')
					.mousedown(function()
					{
						return false;
					})
					.click(function()
					{
						var scrollLeft = $thumbs.attr('scrollLeft');
						$thumbs.animate({scrollLeft: scrollLeft - $thumbs.width() / 2}, 500);
						
						return false;
					});
				
				$scrollRight = $thumbs.next().next();
				
				$scrollRight
					.width(15).height(17).css('cursor', 'pointer')
					.css('background-image', 'url(tl_files/images/arrow_next.gif)')
					.mousedown(function()
					{
						return false;
					})
					.click(function()
					{
						var scrollLeft = $thumbs.attr('scrollLeft');
						$thumbs.animate({scrollLeft: scrollLeft + $thumbs.width() / 2}, 500);
						
						return false;
					});
			});
		}
	});
})(jQuery);
