$(document).ready(function(){

	$('#prev-link,#next-link').click(function() {
		var t = $('#border-image');
		var el = $(this);
		count_image = t.find('img').size()-2;
		cur_image = t.find('img').not('.border-image').filter(':visible');
		index = t.find('img').not('.border-image').index(cur_image);
		
		$('.tablo div.list_collection').animate({'opacity':0},500);
		cur_image.stop().animate({'opacity':0},500,function(){
			$(this).hide();
			
			$('.tablo div.list_collection').stop().hide();
			
			if(el.hasClass('prev-link'))
			{
				if(index==0)
					next_image = count_image;
				else
					next_image = index - 1;
			}
			else
			{
				if(index==count_image)
					next_image = 0;
				else
					next_image = index + 1;
			}
			
			$('.tablo div.list_collection').stop().eq(next_image).css('opacity',0).show().animate({'opacity':1});
			
			t.find('img:eq('+next_image+')').css('opacity',0).show().animate({'opacity':1});
		});
		return false;
	})
	
	var search = $('input[name=search_query]');
	
	$('.print').click(function(){
		print();
	})
	
	search.focus(function() {
		if(search.val()=='Поиск')
			search.val('');
	})
	
	search.blur(function() {
		if(search.val()=='')
			search.val('Поиск');
	})
	
	$('.ajax_polls').click(function(){
        
        if($(this).attr('href')=='')
        	return false;
        
        var id = $(this).attr('href');
        $('.ajax_polls').attr('href','').addClass('removed_link');

        $.ajax( {
                url:"/poll/?id="+id,
                dataType: 'json',
                success:function(data,textStatus)
                {
                	$.each(data,function(i){
						$('.otvet span').eq(i).html(data[i].value);
					})

                	$('.polls_holder .hidden').show();
               	}
        });
		
		return false;
	})
	
	
	$('#caolaction_table .left_nav a').click(function(){

		$('#caolaction_table .left_nav a').removeClass('f_nav');
		$(this).addClass('f_nav');
		
		$('.collection_holder div.collect').hide();
		$('.collection_holder div.collect').eq( $('#caolaction_table .left_nav a').index(this) ).show();
		
		return false;
	})
	
	$('.photos').click(function(){
		var div = $('#caolaction_table div.cd-div').eq( $('.photos').index(this) );
				
		if(div.is(':visible'))
		{
			if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7))
			{
				$(this).next('span').stop()
									.show();
			}
			else
			{
				$(this).next('span').stop()
									.animate({opacity:100});
			}
			
			div.slideUp();
		}
		else
		{
			if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7))
			{
				$(this).next('span').stop()
									.hide();
			}
			else
			{
				$(this).next('span').stop()
									.animate({opacity:0});
			}
			
			div.slideDown();
		}

		return false;
	})
})
