var enableSlide = false;
var slideTimer;
var slideDirection = "left";

function menuSlideLeft(event){
	enableSlide = true;
	blockEvent(event);
	slideDirection="left";
	slideTimer =  setInterval("menuSlide()",1);
	
}

function menuSlideRight(event){
	enableSlide = true;
	blockEvent(event);
	slideDirection="right";
	slideTimer =  setInterval("menuSlide()",2);
	
}

function menuSlide(){
	if(enableSlide){
		if(slideDirection == "left"){
			$("#menu_list_wrapper").animate({ marginLeft :'-=2px' },5);	
		}else if (slideDirection == "right"){
			$("#menu_list_wrapper").animate({ marginLeft :'+=2px' },5);	
		}
	}
	if((($("#menu_right_anchor").offset().left<$("#menu_right_arrow").offset().left)&&(slideDirection=="left")) ||(($("#menu_left_anchor").offset().left>$("#menu_left_arrow").offset().left+$("#menu_left_arrow").innerWidth())&&(slideDirection=="right")) ) {
//		alert("Stop sliding!" +$("#menu_right_anchor").offset().left+" "+ $("#menu_right_arrow").offset().left+" " +$("#menu_left_anchor").offset().left );
		menuStopSlide();
	}
}

function menuStopSlide(){
	$("#menu_list_wrapper").stop(true);	
	enableSlide = false;
	clearInterval(slideTimer);
}

//функция, блокирующая всплытие событий
function blockEvent(event)
{
    if (!event)
    {
        event = window.event;
    }
    if(event.stopPropagation) event.stopPropagation();
    else event.cancelBubble = true;
    if(event.preventDefault) event.preventDefault();
    else event.returnValue = false;
}


//



function wrappTextImage(){
	var i=0;
	$(".text_img").each(function(i){
				$(this).wrap("<div class='text_image_wrapper' id='img"+i+"'></div>");
				var imageWrapper = $("#img"+i);
				var imageWidth = parseFloat($(this).attr("width"),10);
				var imageHeight = parseFloat($(this).attr("height"),10);
				
				$(this).before("<div id='tiw_lt'></div><div id='tiw_rt'></div><div id='tiw_ct'></div><div class='clear'></div><div id='tiw_lm'></div><div id='tiw_rm'></div>");
				$(this).after("<div class='clear'></div><div id='tiw_lb'></div><div id='tiw_rb'></div><div id='tiw_cb'></div><div class='clear'></div>");	
				$(this).wrap("<div id='tiw_cm'></div>");
				$(imageWrapper).css({
								 'float':$(this).css("float"),
								 'marginLeft':$(this).css("marginLeft"),
								 'marginRight':$(this).css("marginRight")///,
								// 'width':$("#text_image_wrapper img").attr("width")
																		   });
				$(imageWrapper).css({'width':(imageWidth+44)+'px'});
				$("#tiw_ct",$(imageWrapper)).css({'width':(imageWidth-10)+'px'});
				$("#tiw_cb",$(imageWrapper)).css({'width':(imageWidth-7 )+'px'});
				$("#tiw_lm",$(imageWrapper)).css({'height':imageHeight+'px'});		
				$("#tiw_rm",$(imageWrapper)).css({'height':imageHeight+'px'});
				$("img",$(imageWrapper)).css({'float':'none','margin':'0px','padding':'0px'});				
				i++;
	});
}
