$(document).ready(function() {
	$(".thumbs img").click(function(e) {
				e.preventDefault();
				cgal =$(this).parent().attr('id');
				$('<div id="trans"></div>').appendTo("body");
				$('#trans').height( get_sTop());
				img = $(this).attr("src");
				thumbID = $(this).index();
				$('<div id="gallery"><p style="text-align:right"><a name="close">close</a></p><p style="text-align:center" id="bimg"></p><p id="iswitch"><a name="left"><img src="tmpl/default/img/pf2.gif" width="19" height="21" alt="" /></a> <a name="right"><img src="tmpl/default/img/pf1.gif" width="19" height="21" alt="" /></a></p></div>').appendTo("body");
				$("#gallery").css("top", get_sTop());
				$("#bimg").html('<img src="'+img.replace("/th", "")+'">');
				$("#gallery a").click(function() {
					switch($(this).attr("name")){
						case 'left':
							thumbID--;
							if(thumbID==-1) thumbID = $("#"+cgal+" img").length - 1;
							img = $("#"+cgal+" img:eq("+thumbID+")").attr("src").replace("/th", "");
							$("#bimg").html('<img src="'+img+'">');	
						break;
						case 'right':
							thumbID++;
							if(thumbID==$("#"+cgal+" img").length) thumbID = 0;
							img = $("#"+cgal+" img:eq("+thumbID+")").attr("src").replace("/th", "");
							$("#bimg").html('<img src="'+img+'">');
						break;
						case 'close':
							$("#trans").remove();
							$("#gallery").remove();
						break;
					}
				});
				
			});
			$(".big_img").click(function(e) {
				$('<div id="trans"></div>').appendTo("body");
				$('#trans').height( get_sTop());
				img = $(this).attr("src").replace(".jpg", "_big.jpg");
				$('<div id="gallery"><p style="text-align:right"><a name="close">close</a></p><p style="text-align:center" id="bimg"></p></div>').appendTo("body");
				$("#gallery").css("top",  get_sTop());
				$("#bimg").html('<img src="'+img+'">');
				$("#gallery a").click(function() {
					switch($(this).attr("name")){
						case 'close':
							$("#trans").remove();
							$("#gallery").remove();
						break;
					}
				});
				
			});
			
			function get_sTop(){
				var pos = 0;
				if($.browser.safari) pos = $("body")
				else pos = $("html,body")
				return pos.scrollTop()+20;
			}
});
