$(function() {
// украшательства
	//$('#qs').corner("bl");
	//$('#fav,#inout,#pc').corner("3px");

if (document.cookie.match(/\bdaily=1/))
{
	$('#long').hide();
	$('#longads').hide();
	$('#daily').show("slow");
	$('#dailyads').show("slow");
}
	
$('.adv-vertical,.agency').corner("10px");

// инициализация библиотеки facebox
	$(document).ready(function() {
		$('a[rel*=facebox]').fancybox();
		$('a[rel*=face2]').fancybox();
	})
	
	$('.various').fancybox({
		maxWidth	: 600,
		maxHeight	: 800,
		fitToView	: false,
		width		: '80%',
		height		: '80%',
		autoSize	: true,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	})
	
	$('a[rel*=ajax]').each(function(){
		if ($(this).attr('href').substring(0,1)!=='#')
		$(this).attr('href', '/ajax'+$(this).attr('href')).removeAttr('rel');
	})
	
	$('a[rel*=face2]').each(function(){
		ajax_suff = ($(this).attr('href').indexOf('?')==-1)?'?ajax':'&ajax';	
		$(this).attr('href', $(this).attr('href')+ajax_suff);
	})
// помечаем все 

$('a[rel*=showlong]').click(function(){
	var expiredays = 360
	var exdate = new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie="daily=0; path=/; expires="+exdate.toGMTString()
	$('#daily').hide();
	$('#dailyads').hide();
	$('#long').show("slow");
	$('#longads').show("slow");
	return false;
})

$('a[rel*=showdaily]').click(function(){
	var expiredays = 360
	var exdate = new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie="daily=1; path=/; expires="+exdate.toGMTString()
	$('#long').hide();
	$('#longads').hide();
	$('#daily').show("slow");
	$('#dailyads').show("slow");
	return false;
})
/*
	$('.flat-service a[href*="short-request"]').click(function(){
		flatid = this.parentNode.parentNode.id.substring(1);
		$('#form-short-request input[name="flatid"]').val(flatid);
		return false;
	})
*/
/*	
	$('.flat-service a[rel="unfav"]').click(function(){
		flatid = this.parentNode.parentNode.id.substring(1);
		favorite(flatid);
		return false;
	})

	$('.flat-service a[rel="tofav"]').click(function(){
		flatid = this.parentNode.parentNode.id.substring(1);
		favorite(flatid);
		return false;
	})
	
	$('.flat-service a[href*="censure"]').click(function(){
		flatid = this.parentNode.parentNode.id.substring(1);
		$('#form-censure input[name="flatid"]').val(flatid);
		return false;
	})
	*/
	$('#intro div').mouseover(function(){$(this).toggleClass('introhover');}).mouseout(function(){$(this).toggleClass('introhover');})
});


function show(id)
{
	el = document.getElementById(id);
	if (el) el.className='on';
}

function hide(id)
{
	el = document.getElementById(id);
	if (el) el.className='off';
}

function showhide(id)
{
	el = document.getElementById(id);
	if (el) 
	{
		if (el.className=='off')
		{
			el.className='on'
		}
		else
		{
			el.className='off'
		}
	}
}

function cancel(input_name)
{
	els = document.getElementsByName(input_name);
	for(i=0; i<els.length; i++)
	{
		els[i].checked='';
	}
}

function select_cities(reg)
{
	var reg_arr = new Array('moscow', 'mo', 'russia');
	var found = false;
	city_li = document.getElementById('cities');
	for(i=0; i<reg_arr.length; i++)
	{
		city_sel = document.getElementById('city_'+reg_arr[i]);
		if (city_sel)
		{
			if (reg_arr[i] == reg)
			{
				city_sel.className='on';
				found = true;
				if (reg=='moscow')
					select_metro();
				else
					select_metro_hide();
			}
			else
			{
				city_sel.className='off';
			}
		}
		if (city_li && found)
			city_li.className='on';
		else
			city_li.className='off';
	}
}

function select_metro()
{
	metro_li = document.getElementById('metro');
	metro_li.className='on';
	remoteness_li = document.getElementById('remoteness');
	if (remoteness_li)
	remoteness_li.className='on';
}

function select_metro_hide()
{
	metro_li = document.getElementById('metro');
	metro_li.className='off';
	remoteness_li = document.getElementById('remoteness');
	if (remoteness_li)
	remoteness_li.className='off';
}


