function initcatalog()
{
	$(".catalogx").tabs(".catalogx ul.inner", {
		tabs: 'h3',
		effect: 'default',
		initialIndex: 'none'
	});
//	$(".catalogx").tabs(".catalogx ul.inner", {
//		tabs: 'li:visible',
//		effect: 'default',
//		initialIndex: (jQuery.url.attr("anchor") == null) ? 'none' : jQuery.url.attr("anchor")
//	});
//	$(".catalogy").tabs(".catalogy ul.inner", {
//		tabs: 'li:visible',
//		effect: 'default',
//		initialIndex: (jQuery.url.attr("anchor") == null) ? 'none' : jQuery.url.attr("anchor") 
//	});
}

function initmenu()
{
    $('.selector').mousedown(
        function() {$(document).bind("mouseup", function(e){closemenu(e)})}
    );
}

function searchfocus()
{
	var query = $('#q');
	var equery = $('#example_query')
	if(query.val() == equery.val()){
		query.attr("value", '');
		query.attr('class', 'active');
	}
}

function searchblur()
{
	var query = $('#q');
	var equery = $('#example_query')
	if(query.val() == "" || query.val() == " ")
	{
		query.attr("value", equery.val());
		query.attr("class","gray");
	}
}

function checksearch()
{
	if( $('#q').val() != $('#example_query').val() ) {
		$('#q').attr('class', '.active');
		$('#filter').attr('disabled', false);
	}
}

function closemenu(e)
{
	if($(e.target).attr('class') == 'drop')	
	{
		if($('.selector').find('div').css('display') == 'block')
		{
			$('.selector').find('div').hide(); 	
			$(document).unbind("mouseup");
//			$(document).unbind("mousedown");
		}
		else {
			$('.selector').find('div').show();
		}
	}
	else 
	{   
		var found = false;
		var parents = $(e.target).parents().get();
		for (var key in parents) 
		{
			if($(parents[key]).attr("id")=='main') break;
    		if($(parents[key]).attr("id")=='menu')  
    		{
    			found = true;
    			break;
			} 
		} 
		if (!found) 
		{	
			$('.selector').find('div').hide();
			$(document).unbind("mouseup");
//			$(document).unbind("mousedown");
		}
	}   
}

function changeRegion(regionId)
{
	$.cookie("sky_region", regionId, {expires: 90, path: "/"});
	$.cookie("sky_city", null, {expires: 90, path: "/"});
	location.reload();
}

function changeCity(cityId)
{
	$.cookie("sky_city", cityId, {expires: 90, path: "/"});
	$.cookie("sky_region", null, {expires: 90, path: "/"});
	location.reload();
}

$(document).ready(function () {
//	$('#q').bind("focus", searchfocus);
//	$('#q').bind("blur", searchblur);
//	$('#searchform').bind("submit", onsearch);
//    checksearch();
    initmenu();
    $("a[rel^='prettyPhoto']").prettyPhoto();
    $("#q").autocomplete2("http://skyinform.ru/suggest/", {});
//    $("#q").autocomplete2("/suggest.php", {});
});