function getmainurl() {
				$('#p_dist').val(0);
				$('#test38').val(0);
				$('form.selection').serialize();
				$('form.selection').submit();
				}
				
function getmainurl2() {
				$('input[name="p"]').val(0);
				$('#form_cool').serialize();
				$('#form_cool').submit();
				}

function scrollto(){
	var destination = $('div.pager_cool').eq(0).offset().top - 15;
	var w = $.browser.webkit ? $('body') : $('html');
	w.animate({ scrollTop: destination}, 400 );
}

function scrollUp(){
	var destination = $('div.paging').eq(0).offset().top - 70;
	var w = $.browser.webkit ? $('body') : $('html');
	w.animate({ scrollTop: destination}, 400 );
}

function getcookie(name) {  
	var aCookie = document.cookie.split(';');  
	for (var i = 0; i < aCookie.length; i++) {  
		while(aCookie[i][0] == ' ') {  
		   aCookie[i] = aCookie[i].substr(1);  
		}  
		var aCrumb = aCookie[i].split('=');  
		if (name == aCrumb[0]) {  
		   return unescape(aCrumb[1]);  
		}  
	}  
	return null;  
}

function mail(name, domain, style) {
	document.write('<a h'+'ref="'+'mai'+ 'lto:'+name+'@'+domain+'" style="'+style+'">'+name+'@'+domain+'</a>');
}


function check(myname,text) {
	if($(myname).attr('value')==text)
	{
		$(myname).val('');
	}
	else{
		if($(myname).attr('value')==''){
		$(myname).val(text);
		}
	}
}

		
$(window).ready(function() {
	
		if ($('#form_cool input').is(':checked') ) {
			$('#form_cool').parent('td').append('<a href="javascript: void(0)" title="" class="filter_clear">Искать по другим критериям</a>');
			$('.filter_clear').click(function() {
				$(':input','#form_cool').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');	
				$('#form_cool').submit();
			});
	}
})
		
$(document).ready(function() {
	
	$('.hidden_block').hide();
	$('.pseudo_link').click(function(){
		$(this).parent().next('.hidden_block').slideToggle('fast');		
	})

	
	$('a[href="/forum/"]').css('font-weight','bold');
	
	$center_b = true;
	setInterval(function(){
		if ($center_b){
			$('div.center_b').find('img.swn').fadeOut(500);
			$('div.center_b').find('img.hid').fadeIn(500);
			$center_b = false;
		}
		else {
			$('div.center_b').find('img.hid').fadeOut(500);
			$('div.center_b').find('img.swn').fadeIn(500);
			$center_b = true;
		}
	},3000);

	// tooltips on maps
	$('map *').each(function(){
		var title = $(this).attr('title');
		var alt = $(this).attr('alt');
		var middle = -60;
		var top = -60;
		middle = Math.round(alt.length/2)*(-6.6);
		if ( alt.length <= title.length )  middle = Math.round(title.length/2)*(-8.1);
		var icon = '<div id="icon"><div class="td_center"><div class="td_left"></div><span>'+title+'</span>';
		if (alt.length > 2) {icon = icon+'<br /><font>'+alt+'</font>';} else middle = -60;
		icon = icon+'<div class="td_right">&nbsp;</div></div></div>';
		
		if($(this).hasClass('big')){
			icon = '<div class="big_icon">'+title+alt+'</div>';
			middle = -78;
			top = -140;
		}
		
		$(this).tooltip({ 
			delay: 50, 
			showURL: false, 
			fixPNG: true,
			top: top,
			left: middle,
			track: true,
			fade: 200,
			bodyHandler: function() { 
				return icon;
			} 
		});
	});

	$('map *').click(function(){ return false; });
	$('map *').css('cursor', 'hover');

	$('div.pager').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$('#p_dist').val($page);
		$page2 = $('#new_url').val();
		$request = $('form.selection').serialize();
		$request = $request+'&p='+$page2;
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
				
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_filter_refresh.php",
			data: $request,
			success: function(msg){
			window.location.href='http://www.delo-bg63.ru/filter/?vid=9&p='+$page+$page2;
		    }
		});
		return false;
	});
	
	$('div#buypager').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$request = $('#form_buy').serialize();
		$request = $request+'&p='+$page;
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_buy_refresh.php",
			data: $request,
			success: function(msg){
				
				document.getElementById('ajax_insert').innerHTML = msg;
		    }
		});
		return false;
	});
	
	$('div.pager_cool').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$('input[name="p"]').val($page);
		$('#form_cool').submit();
		return false;
	});
	
	$('div.paging').find('a').live("click",function(){
		var page = $(this).find('span').text();
		$('input[name="p"]').val(page);
		$request = $('#sort_form').serialize();
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_5mln_refresh.php",
			data: $request,
			success: function(msg){
				$('#sort_form').submit();
		    }
		});
		return false;
	});
	
	$('a.ajax_podbor').click(function(){
		$request = $('form.selection').serialize();
		$page2 = $('#new_url').val();
		
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_filter_refresh.php",
			data: $request,
			success: function(msg){
					$('div#ajax_inner').html(msg);
		    }
		});
		return false;
	});
	
	$is_cool_first = false;
	
	$('a.cool_go').click(function(){
	
		if ($is_cool_first) {
			$('input[name="p"]').val(0);
		}
		$is_cool_first = true;
		$request = $('#form_cool').serialize();
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_cool_refresh.php",
			data: $request,
			success: function(msg){
				region_head = region_header();
				$('div#ajax_insert').html(region_head+msg);
		    }
		});
		return false;
	});
	
	$('#last_task').change(function(){
		$is_cool_first = true;
		$request = $('#form_cool').serialize();
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_cool_refresh.php",
			data: $request,
			success: function(msg){
				$('#ajax_inner').html(msg);
		    }
		});
		return false;
	});
	
	var act = $('#form_cool input[name="reg"]').val();
	$('#regions a#'+act).addClass('act');
	
	$('#regions a').click(function(){
		$('#regions a').removeClass('act');
		$(this).addClass('act');
		var a_id = $(this).attr('id');
		$('input[name="reg"]').val(a_id);
		$('input[name="p"]').val(0);
		$('#form_cool').submit();
		return false;
	});
	
	$('#sort_control').change(function(){
		$request = $('#sort_form').serialize();
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_5mln_refresh.php",
			data: $request,
			success: function(msg){
				$('#ajax_insert').html(msg);
			}
		});
		return false;
	});
	
	$('#find_buy').click(function(){
		$request = $('#form_buy').serialize();
		$.ajax({
			type: "GET",
			beforeSend: function(){},
			complete: function(){},
			url: "/ajax/ajax_buy_refresh.php",
			data: $request,
			success: function(msg){
				document.getElementById('ajax_insert').innerHTML = msg;
		    }
		});
		return false;
	});
	
	$('#find_buy').click();
	
	$toggle1 = true;
	$toggle2 = true;
	$toggle3 = true;
	$toggle4 = true;
	
	$toggle_buy = true;
	
	$('span.check_all_buy').click(function(){
		if($toggle_buy){
			$(this).parent().find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle_buy = false;
		}
		else{
			$(this).parent().find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle_buy = true;
		}
	});
	
	$('span#check_all_types').click(function(){
		if($toggle1){
			$('#filter_type').find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle1 = false;
		}
		else{
			$('#filter_type').find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle1 = true;
		}
	});
	$('span#check_all_districts').click(function(){
		if($toggle2){
			$('#filter_distr').find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle2 = false;
			$('#filter_distr a').text('Снять все');
		}
		else{
			$('#filter_distr').find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle2 = true;
			$('#filter_distr a').text('Отметить все');
		}
	});
	$('span#check_all_prices').click(function(){
		if($toggle3){
			$('#filter_price').find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle3 = false;
		}
		else{
			$('#filter_price').find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle3 = true;
		}
	});
	$('span#check_all_areas').click(function(){
		if($toggle4){
			$('#filter_area').find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle4 = false;
		}
		else{
			$('#filter_area').find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle4 = true;
		}
	});
	
	$toggle_cool1 = true;
	$toggle_cool2 = true;
	$toggle_cool3 = true;
	
	$('#check1').click(function(){
		if($toggle_cool1){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$toggle_cool1 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$toggle_cool1 = true;
		}
	});
	$('#check2').click(function(){
		if($toggle_cool2){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().next().next().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$(this).parent().next().find('a').text('Снять все');
			$toggle_cool2 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().next().next().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$(this).parent().next().find('a').text('Отметить все');
			$toggle_cool2 = true;
		}
	});
	$('#check3').click(function(){
		if($toggle_cool3){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$toggle_cool3 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$toggle_cool3 = true;
		}
	});
	
	$('.scroll h5 a').click(function(){
		if ($(this).text() == 'Отметить все') {
			$(this).parent('h5').next('div').find('input').attr('checked','checked');
			$(this).text('Снять все');
		}
		else {
			$(this).parent('h5').next('div').find('input').attr('checked','');
			$(this).text('Отметить все');
		}
	});
	
	$('a.cool_go').click();
	
	$('#last_task').change();
	
	$('#sort_control').change();
	//$('#sort_form').submit();
	
	$('.selection a#other').hide();
	$('span.other_districts').click(function(){
		if ($('div#filter_distr > div').hasClass('hidden')) {
			$('div#filter_distr > div').removeClass('hidden');
			$('a#other').show();
		}
		else {
			$('div#filter_distr > div').addClass('hidden');
			$('a#other').hide();
		}
		return false;
	});
	
	$('#filter_distr h5 a').click(function(){
		if ($(this).text() == 'Отметить все') {
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).text('Снять все');
		}
		else {
			$(this).parent().next().find('input').attr('checked','');
			$(this).text('Отметить все');
		}
	});

	$("#older_pred a").click(function() {
		if ($(this).attr("id")=="show_prod") {
			$(".visible").hide();
			$(".hide").show();
		}else{
			$(".visible").show();
			$(".hide").hide();
		};
		$("#older_pred li").removeClass("select");
		$(this).parent("li").addClass("select");
		return false;
	});
		

});

function region_header() {
	var region_header = '';
	smr = $('#form_cool div.smr input:checked').length;
	tlt = $('#form_cool div.tlt input:checked').length;
	other = $('#form_cool div.other input:checked').length;
	if ((smr == 10) && (tlt == 0) && (other == 0)) region_header = '<h2>Объекты в Самаре</h2>';
	if ((tlt == 4) && (smr == 0) && (other == 0))  region_header = '<h2>Объекты в Тольятти</h2>';
	return region_header;
}

function trim(string){
	return string.replace(/(^\s+)|(\s+$)/g, "");
}
	
/* кастомный input[type=file] */
var W3CDOM = (document.createElement && document.getElementsByTagName);
function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/images/resume_file_button.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}	
/* /кастомный input[type=file] */

	
	
$(document).ready(function(){
	initFileUploads();

	
	$(".ajax_podbor").click();

	i=1;
	setInterval(function(){
			if (i<3)
					  {
						 $('#blue_banner img').fadeOut(100,function(){
							$('#blue_banner img').attr('src','/images/blue_'+i+'.png');
							$('#blue_banner img').fadeIn(500);
						});
						i++;
					  }
					else
					  {
					  i=1;
					  $('#blue_banner img').fadeOut(500,function(){
							$('#blue_banner img').attr('src','/images/blue_'+i+'.png');
							$('#blue_banner img').fadeIn(500);
						});
					  }	
	},4500);
	
	$('.consultPerson .diamond').each(function(){
		var alt = $(this).attr('alt');
		var icon = '<div class="award_tooltip"><span>'+alt+'</span></div>';
		$(this).tooltip({ 
			delay: 50, 
			showURL: false, 
			fixPNG: true,
			top: -140,
			left: -145,
			track: true,
			fade: 200,
			bodyHandler: function() { 
				return icon;
			} 
		});
	});
	$('.consultPerson .diamond').click(function(){ return false; });
	$('.consultPerson .diamond').css('cursor', 'hover');
	
	$(".mini_gal a").fancybox({ 
			hideOnContentClick: false,
			overlayShow: true,
			overlayOpacity: 0.5,
			zoomSpeedIn: 500,
			zoomSpeedOut: 300,
			titlePosition: 'over',
			titleFormat: function(title, currentArray, currentIndex, currentOpts) {
							return '<span id="fancybox-title-over">Изображение ' + (currentIndex + 1) + ' из ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
							}
	});

});




	
