jQuery(document).ready(function() {		
	
	$('#tagScroll').marquee('marq', {scrollamount: 1}).mouseover(function () {
		  $(this).trigger('stop');
	}).mouseout(function () {
	  $(this).trigger('start');
	}).mousemove(function (event) {
	  if ($(this).data('drag') == true) {
	    this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	  }
	}).mousedown(function (event) {
	  $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
	  $(this).data('drag', false);
	});
	
	$('a.lightbox').lightBox({
		fixedNavigation:true, 
		imageLoading: '/pub/css/lightbox/loading.gif',
		imageBtnClose: '/pub/css/lightbox/close.gif',	
		imageBtnPrev: '/pub/css/lightbox/prev.gif',	
		imageBtnNext: '/pub/css/lightbox/next.gif',	
		txtImage: 'фото',
		txtOf: 'из', 
		imageBlank: '/pub/css/lightbox/blank.gif'
	});
		
	$('input.placeholder').each(function(index) {
		var val = $(this).val();
		$(this).attr('placeholder', val);
		$(this).focus(function(){
			var placeholder = $(this).attr('placeholder');
			var val = $(this).val();
			if (val == placeholder) $(this).val('');
		});
		$(this).blur(function(){
			var placeholder = $(this).attr('placeholder');
			var val = $(this).val();
			if (val == '') $(this).val(placeholder);
		});
	});
	
	if ($('#mainNews').get(0)) {
		$('#mainNews ul.links a').hover(function () {
			var idLink = $(this).attr('id');
			var idPhoto = idLink + '_photo';
			$('#mainNews ul.links li').removeClass('active');
			$(this).parent().addClass('active');			
			$('#mainNews div.photos a').removeClass('active');
			$('#' + idPhoto).addClass('active');
		});
		$('#newsTape ul.newsList li:last-child').addClass('last');		
	}	
	
	function getCalendar(url) {
		$.getJSON(url, function(data) {
			if (data.result == true) {
				$('#calTbody').html(data.cal);
				$('#calCurMonth').html(data.month);
				$('#calPrev').attr('href', data.prev);
				$('#calNext').attr('href', data.next);
			}			  
		});
	}
	
	if ($('#calWrap').get(0)) {
		$('#calPrev').click(function(evt){
			evt.stopPropagation();
			var url = $(this).attr('href');
			getCalendar(url);
			return false;
		});
		$('#calNext').click(function(evt){
			evt.stopPropagation();
			var url = $(this).attr('href');
			getCalendar(url);
			return false;
		});
		$('#calMonthYearChanger').submit(function(evt){
			evt.stopPropagation();
			var url = $(this).attr('action');
			url = url + 'month/' + $('#calMYC_month').val() + '/year/' + $('#calMYC_year').val();
			getCalendar(url);
			return false;
		});
	}
	
	if ($('#noticeWrap').get(0)) {	
		$jScroller.add("#noticeWrap","#scroller","up",2);
		$jScroller.start();
	}
	
	if ($('#mediaTabs').get(0)) {	
		$('#mediaTabs div.blockTitle span.tab').click(function(){
			$('#mediaTabs div.blockTitle span.tab').removeClass('active');
			$(this).addClass('active');
			var idTab = $(this).attr('id');
			var idInner = idTab + 'Inner';
			$('#mediaTabs div.tabInner div.tabInn').removeClass('active');
			$('#' + idInner).addClass('active');			
		});
	}
	
	if ($('#openIdLogin').get(0)) {	
		$('#openIdLogin ul.tabs a').click(function(evt) {
			evt.stopPropagation();
			var li = $(this).parent();
			$('#openIdLogin ul.tabs li').removeClass('active');
			li.addClass('active');			
			var idTab = $(this).attr('id');
			var idInner = idTab + 'Inner';
			$('#openIdLogin div.inner div.tabInner').removeClass('active');
			$('#' + idInner).addClass('active');
			return false;
		});
	}
	
	
	
	
})
