function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' )+'</div>';
}
function setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function 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);
}
	jQuery().ready(function(e){
		var scrollBar = jQuery('.project-pics').find('ul');
		var scrollElements = scrollBar.find('li');
		var elemCount = scrollElements.length-1;
		
		var k=0;
		var galleryCookie = getCookie("hidden");
		if (galleryCookie && galleryCookie == '1')
		{
			jQuery('.tabberlive').toggle();
			jQuery('.gallery-hider').find('span').text('Развернуть').addClass('gallery-hidden').parent().css('line-height', '300px');
		}
		else if (!galleryCookie)
			setCookie("hidden", "0");
		
		jQuery('a[rel=project-1]').fancybox({showNavArrows:true,titlePosition:'inside',titleFormat:formatTitle});
		jQuery('a[rel=project-2]').fancybox({showNavArrows:true,titlePosition:'inside',titleFormat:formatTitle});
		jQuery('a[rel=fancybox]').fancybox({showNavArrows:true,titlePosition:'inside',titleFormat:formatTitle});
		
		jQuery('.left-arrow').hide();
		
		jQuery('.gallery-hider').find('span').bind('click', function(e){
			e.preventDefault();
			jQuery('.tabberlive').toggle();
			if (jQuery(this).parent().css('line-height') == '52px')
			{
				jQuery(this).text('Развернуть').addClass('gallery-hidden').parent().css('line-height', '300px');
				setCookie("hidden", "1");
			}
			else
			{
				jQuery(this).text('Свернуть').removeClass('gallery-hidden').parent().css('line-height', '52px');
				setCookie("hidden", "0");
			}
		});
		
		jQuery('.left-arrow').bind('click', function(e){
			e.preventDefault();
			if (k>0)
			{
				scrollBar.animate({'left':'+=455px'},500, function(){
					if (jQuery('.project-pics').find('ul').css('left') == '0px')
						jQuery('.left-arrow').hide();
					else
						jQuery('.right-arrow').show();
				});
				k--;
			}
		});
		
		jQuery('.right-arrow').bind('click', function(e){
			e.preventDefault();
			if (k<elemCount)
			{
				scrollBar.animate({'left':'+=-455px'},500, function(){
					if (jQuery('.project-pics').find('ul').css('left') == '-'+elemCount*455+'px')
						jQuery('.right-arrow').hide();
					else
						jQuery('.left-arrow').show();
				});
				k++;
			}
		});
	});
