jQuery.fn.round = function( settings ){
	var defaults = {
	color: '',
	top: true,
	bottom: true
	}
	settings = jQuery.extend(defaults, settings);
	$this = $( this ); 
	if( settings.top ) jQuery( $this ).prepend( '<div class="top'+settings.color+'"></div>' );
	if( settings.bottom ) jQuery( $this ).append( '<div class="bottom'+settings.color+'"></div>' );

	//jQuery( $this ).css({zIndex: 1});
	return $this;
}


jQuery(document).ready(function(){

//		$('#leftmenu-flash').flash({swf:'/images/menuleft.swf',height:387,width:225,base:'http://www.plomba.ru/bitrix/templates/plomba2/'});

		$(".pricebox").round();
		$(".priceboxWhite").round({color:'_white'});
		
		$('#banners ul').innerfade({
			speed: 1000,
			timeout: 6000,
			type: 'sequence',
			containerheight: '325px',
			containerwidth: '247px'
		});

		//при загрузке страницы, обновляем регион в блоке
		if(m_getCookie('r_name')){
			$('#curregion a').text(m_getCookie('r_name'));
		}
 
		toggleFreeText(); 
	
		//regions
		$("#curregion .c_reg").click(
		  function ()
		  {
			$("#banner").toggle()
			$("#shadow").fadeIn("fast")
			$("#regions").fadeIn("fast")
			return false;
		  }
		)
		$("#shadow").click(
		  function ()
		  {
			closeRegions()
		  }
		)
		$("#regions .closer").click(
		  function ()
		  {
			closeRegions()
		  }
		)
/*При выборе региона МОСКВА И ПОДМОСКОВЬЕ или любого другого, список городов должен закрываться.*/
		$("#regions a").click(
		  function ()
		  {
			m_setCookie('p_region', $(this).attr('class'), "Mon, 01-Jan-2012 00:00:00 GMT", "/");
			m_setCookie('r_name', $(this).text(), "Mon, 01-Jan-2012 00:00:00 GMT", "/");
			window.location.reload();
			closeRegions();
			return this.text
		  }
		)
/*Слева в МЕНЮ при наведении мыши должен меняться цвет, как в верхнем меню при наведении.*/
		$("#leftMenu tr").mouseover(
			function()
			{
				this.className="cur"
			}
		)

		$("#leftMenu tr").mouseout(
			function()
			{
				this.className=""
			}
		)

		if( $(".form-table input[name='web_form_submit']").length > 0)
			$(".form-table input[name='web_form_submit']")[0].value="Отправить";


		var n = $('#mycarousel li').length;
		if(n>2){
			$('#mycarousel').jcarousel({
				wrap: 'circular',
				vertical: true,
				scroll: 1
			});
		}

});  	

function closeRegions()
{
  $("#regions").fadeOut("fast")
  $("#shadow").fadeOut("fast")
  $("#banner").toggle()
}
function m_setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function toggleFreeText(){
	if( !jQuery("#freeText") ) return;
	var h = (jQuery("#freeText").css("height")!="59px") ? "59px" : "auto";
	jQuery("#freeText").css("height",h);
}
function m_getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


$(document).ready(function(){
	if ($('#leftMenuActive').length == 0)
	{
		$('#leftMenu').children('li:first').attr('id', 'leftMenuActive').children('img').removeClass('hidden');
		Cufon.replace('#leftMenu a', { fontFamily: 'Myriad Pro' });
	}
});
