// Скролл
$(document).ready(function(){
	if($('.galleryStripInner p').length > 4) {
		bindControls();
		$('.gallery .next').show();
	}
})
function rollStrip(dir) {
	unbindControls();
	dir = (dir=='next') ? -920 : 920;
	if ($('.galleryStripInner').is(':animated')) {
		alert('a')
	}
	$('.galleryStripInner').animate({ marginLeft:'+='+dir+'px' },function(){
		checkState();
		bindControls();
    })
}
function checkState() {
	prev = $('.gallery .prev');
	next = $('.gallery .next');
	offset = Math.abs(parseInt( $('.galleryStripInner').css('marginLeft') ))/920;
	screens = Math.ceil($('.galleryStripInner p').length/4);
	if (offset == 0) {
		prev.hide();
		next.show();
	} else if (offset == screens-1) {
		prev.show();
		next.hide();
	} else {
		prev.show();
		next.show();
	}
}
function unbindControls() {
	$('.gallery .prev').unbind();
	$('.gallery .next').unbind();
}
function bindControls() {
	setTimeout((function(){
	$('.gallery .prev').click(function(){ rollStrip('prev');return false; })
	$('.gallery .next').click(function(){ rollStrip('next');return false; })
	}),100)
}


///// ToolTip
function simple_tooltip(target_items, name){
	$(target_items).each(function(i){
		if ($(this).attr('title') !== '') {
			$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
			var my_tooltip = $("#"+name+i);
		}
		if ($(this).attr('title') !== '') {
			$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(100);
			}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			}).mouseout(function(){
				my_tooltip.fadeOut(100);
			});
		}
	});
}
$(document).ready(function(){
	simple_tooltip("a.tool","tooltip");
});



function Showhide_page(id){
	obj = document.getElementById(id);
	if(obj.style.display!='none'){
		obj.style.display = 'none';
	} else {
		$("div.help_popup").hide();
		$("div#"+id).fadeIn(700);
	}
}
function show(id) {
    $("div#"+id).show();
}
function hide(id) {
    $("div#"+id).hide();
}



