jQuery.fn.gallery = function() {
	var $gallery = $(this);
	var $leng = $('.gallery li').size()+1;
	var anim = false;
	var imgW = 44;
	var imgMargin = 10;
	var amount = 7;
	var currPage;
	
	if (jQuery.browser.msie){
		$(".gallery").css({'left':-20,'width':370});
	}
	
	var _sort = function() {
		for(i=0;i<$leng;i++){
			$(".gallery li").eq(i).css({
				'display': 'block',
				'position':'absolute',
				'width': imgW,
				'top':0,
				'left':i * (imgW+imgMargin)
			});
		}
	}
		
	$("#prev").click(
		 function () {
			if(currPage>1){
				prev();
				butnActivity();
			}
		}
	);
	$("#next").click(
		 function () {
			if(currPage<($leng-amount)){
				next();
				butnActivity();
			}
		}
	);
	
	var prev = function() {
		if(anim) return;
		anim= true;
		$gallery.find('li').each(function(i){
			$(this).animate({'left': parseFloat($(this).css('left')) + (imgW + imgMargin) }, 'normal', function(){anim = false;});
		});
		currPage--;
	};
	var next = function() {
		if(anim) return;
		anim= true;
		$gallery.find('li').each(function(i){
			$(this).animate({'left': parseFloat($(this).css('left')) - (imgW + imgMargin) }, 'normal', function(){anim = false;});
		});
		currPage++;
	};
	
	var butnActivity = function() {
		if(currPage == 1){
			$("#prev").attr({src: "/img/arrowGrayL.gif"});
			$("#next").attr({src: "/img/arrowGreenR.gif"});
		}else if(currPage == $leng-amount){
			$("#prev").attr({src: "/img/arrowGreenL.gif"});
			$("#next").attr({src: "/img/arrowGrayR.gif"});
		}else{
			$("#prev").attr({src: "/img/arrowGreenL.gif"});
			$("#next").attr({src: "/img/arrowGreenR.gif"});
		}
	}

	$gallery.find('li').each(function(i){
		$(this).tipsy({fallback: $(".gallery li a").eq(i).attr("ttitle"), gravity: 's', fade: true});
	});

	$(".gallery li a").click(
	function () {
		document.location = $(this).attr("link");
	});

	$("#newsTitle").click(
	function () {
		document.location = $(this).attr("link");
	});
	
	$("#bimg").click(
	function () {
		document.location = $(this).attr("link");
	});
	
	currPage = 1;
	_sort();
	butnActivity();
};
jQuery.fn.gallery2 = function() {
		var $gallery = $(this);
		var $leng = $('.gallery2 li').size();
		var anim = false;
		var imgW = 153;
		var imgMargin = 10;
		var currPage;
		
		if (jQuery.browser.msie)
			$(".gallery2").css({'margin':0,'width':160});
		
		var _sort = function() {
			for(i=0;i<$leng;i++){
				$(".gallery2 li").eq(i).css({
					'display': 'block',
					'position':'absolute',
					'width': imgW,
					'left':i *(imgW + imgMargin)
				});
			}
		}
		$("#prev2").click(
			 function () {
				if(currPage>1){
					prev();
					butnActivity();
				}
			}
		);
		$("#next2").click(
			 function () {
				if(currPage<$leng){
					next();
					butnActivity();
				}
			}
		);
			
		var prev = function() {
			if(anim) return;
			anim= true;
			$gallery.find('li').each(function(i){
				$(this).animate({'left': parseFloat($(this).css('left')) + (imgW + imgMargin) }, 'normal', function(){anim = false;});
			});
			currPage--;
			
		};

		var next = function() {
			if(anim) return;
			anim= true;
			$gallery.find('li').each(function(i){
				$(this).animate({'left': parseFloat($(this).css('left')) - (imgW + imgMargin) }, 'normal', function(){anim = false;});
			});
			currPage++;
		};
		
		var butnActivity = function() {
			if(currPage == 1 && $leng!==1){
				$("#prev2").attr({src: "/img/arrowGrayL.gif"});
				$("#next2").attr({src: "/img/arrowGreenR.gif"});
			}else if(currPage == $leng && $leng!==1){
				$("#prev2").attr({src: "/img/arrowGreenL.gif"});
				$("#next2").attr({src: "/img/arrowGrayR.gif"});
			}else{
				$("#prev2").attr({src: "/img/arrowGreenL.gif"});
				$("#next2").attr({src: "/img/arrowGreenR.gif"});
			}
		}
		
		currPage = 1;
		_sort();
		butnActivity();
		
};