$(document).ready(function(){

//загрузка счетчика посещений
countFlag = $("#currentUrl");
if(countFlag.length > 0){ 
	currentUrlV = encodeURIComponent($("#currentUrl").val());
	currentTextV = encodeURIComponent($("h1:first").text());
		if(currentTextV == '') currentTextV = 'Заголовок не указан';
	$("#count").load('http://www.vfps.ru/count.php?query=' + currentUrlV + '&text=' + currentTextV);
}

//плеер
$(".player").each(function(i){
	$(this).attr('id', 'el_' + i);
	$(this).prepend('<span class="button"></span>');
	
	fileToPlay = $(this).attr('href'); 
		flowplayer("el_" + i, "/flash/flowplayer-3.2.5.swf", {
			plugins: {
				controls: {
					url: '/flash/flowplayer.controls-3.2.3.swf', 
					slowForward: false, 
					mute: false, 
					time: true
				}, 
				pseudo: { 
					url: '/flash/flowplayer.pseudostreaming-3.2.5.swf' 
				}
				
			},
			clip: {
				autoPlay: true, 
				autoBuffering: true, 
				scaling: 'scale', 
				start: 62,
				provider: 'pseudo'
			}, 
			playlist: [ // an array of Clip objects
						{
							autoPlay: true, 
							autoBuffering: true,
							start: 62,
							provider: 'pseudo', 
							url: fileToPlay
						}
			]
		});
});



	$(".topSubItem a").click(function(){
		elem = $(this).attr('rel');
		flag = $("#sub_" + elem);
		if(flag.length > 0){
		
			$(".topSubItem").removeClass('top1Active');
			$(this).parent().addClass('top1Active');
		
			$(".menuSub").show();
			$(".menuSub ul").hide();
			$("#sub_" + elem).show(300);

			return false;
		}
	});
	$(".subMenu a").click(function(){
		elem = $(this).attr('rel');
		flag = $("#sub_" + elem);
		if(flag.length > 0){
			
			$(".subMenu li").removeClass('top2Active');
			$(this).parent().addClass('top2Active');
			
			$(".subMenu3").hide();
			$("#sub_" + elem).find('ul').show();
			$("#sub_" + elem).show(300);
			

			return false;
		}
	});
	
	var obFlag = true;
	$(".ob-all-link").click(function(){
		$('#obList div').toggleClass('hide');
		
		nText = !obFlag == true ? 'Все объявления' : 'Свернуть';  
		obFlag = !obFlag;
		$(this).html(nText);
		
		return false;
	});
	
	var obForm = true;
	$('#send-ob-link').click(function(){
		$(this).toggleClass('active');
		
		if(obForm == true){
			$('.ob-list-head').prepend('<div id="ob-list-form-cont"></div>');
			$("#ob-list-form-cont").load('/ob_form.php', function(){
				initAjax();
			});
			
			topB = $('.ob-list-head').offset().top - 100; 
			$(window).scrollTop(topB);
			
		} else {
			$('#ob-list-form-cont').remove();
		}
		obForm = !obForm;
		
		return false;
	});
	
	function initAjax(){
		
		$("a.close").click(function(){
			$('#send-ob-link').trigger('click');
			
			return false;
		});
		
		$("#ob-list-form-cont form").unbind().submit(function() {
			$.ajax({
			    beforeSend: function(request) {
					request.setRequestHeader( 'Cookie', document.cookie );
				},
				type: "POST",
				cache: false,
				url: '/ob_form.php',
				success: function(responseText, statusText){
					$("#ob-list-form-cont").html(responseText);
					initAjax();
				},
			    data: $(this).serializeArray()
			});
			
			return false;
		});
		
	}
	
	
	
	
});
