$(function() {
   if( $.browser.opera ) {
      var clss = 'image-border-css';
      $('img.' + clss).each( function() {
         $(this).replaceWith('<span class="' + clss + '" style="background:url(' + $(this).attr('src') + ') 0 0 no-repeat; height:' + $(this).height() + 'px; width:' + $(this).width() + 'px;"></span>');
      });
   }
	$("div.question").click(function(){
		$('#popup').css("top", $(window).scrollTop() + ( $(window).height() - $('#popup').height() ) / 2  ).css("right", ( $(window).width() - $('#popup').width() ) / 2 );
		$('#popup').show();
	});
	$("div.pop-close").click(function(){
		$('#popup').hide();
	});
	$('.search input:first').blur(function(){
		if($(this).val() == '') $(this).val( $(this).is('.en' ) ? 'Search' : 'Поиск');
	});
	$('.search input:first').click(function(){
		if( ( $(this).val() == 'Поиск' ) || ( $(this).val() == 'Search' ) ) $(this).val('');
	});
	
	$('#slider-globe').click(function(){
		if( $('a.nivo-imageLink:visible').length ) window.location = $('a.nivo-imageLink:visible').attr('href');
	});
	
	$(".deal-city a").click(function(){
		$('#deal-popup').show();
	});
	
	$("#deal-pop-mid a").click(function(){
		$("#deal-pop-mid span").text($(this).text());
		$(".deal-city a").text($(this).text());
		$("#russia-map div.active").removeClass("active");
		var id = $(this).attr("name");
		$("#point" + id).addClass("active");
		$("div.deal-city-list:visible").hide();
		$("#address" + id).show("slow");	
		$('#deal-popup').hide();
	});
	
	$("div.map-point").click(function(){
		if( !$(this).hasClass("active") ) {
			$("#deal-pop-mid span").text($(this).text());
			$(".deal-city a").text($(this).text());
			$("#russia-map div.active").removeClass("active");
			point_id = $(this).attr("id").match(/point(\d+)/i);
			$(this).addClass("active");
			$("div.deal-city-list:visible").hide();
			$("#address" + point_id[1]).show("slow");	
		}
	});
	if( $("#tenders li ul li a.active").length ) {
		$("#tenders li ul li a.active").parents("ul:eq(0)").show();
	}
	$("#tenders > li > a").click(function(){
		$(this).next().toggle();
	});
});
