
	var worker = htroot+'worker.php'
	var album_mode = false;
	var cId = 0;

	function facebook_init()
	{
		FB.init({
			appId  : fb_key,
			status : true,
			cookie : true,
			xfbml  : true
		});
	}

	function get_current_pic_id()
	{
		if($('#dvPicBigThumb img').length>0) return $('#dvPicBigThumb img').attr('id').split('thumb')[1];
		else return false;
	}

	function get_xnp(id)
	{
		if($('#licthumb'+id).length>0) return $('#licthumb'+id).attr('xnp').split('|');
		else return false;
	}
	function get_firstLiKey()
	{
		if($('.dvCarousel ul li:first a').length>0) return $('.dvCarousel ul li:first a').attr('href').split('#')[1];
		else return false;
	}
	function get_lastLiKey()
	{
		if($('.dvCarousel ul li:last a').length>0) return $('.dvCarousel ul li:last a').attr('href').split('#')[1];
		else return false;
	}

	function load_next_pic(id)
	{
		cId = id;
		var xnp = get_xnp(id);

		if(!xnp) return false;

		if(xnp && xnp[1].length>1)
		{
			location.hash='#'+xnp[1];
			jCl.forward();
		}
		else
		{
			location.hash='#'+get_firstLiKey();
			jCl.toBegining();
		}

	}

	function load_prev_pic(id)
	{
		cId = id;
		var xnp = get_xnp(id);

		if(!xnp) return false;

		if(xnp[1].length>1)
		{
			location.hash='#'+xnp[1];
			jCl.backward();
		}
		else
		{
			location.hash='#'+get_lastLiKey();
			jCl.toEnd();
		}

	}

	function carousel_currents()
	{
		$('.carousel_thumb.current').removeClass('current');
		$('#icthumb'+cId).addClass('current');
	}

	function load_pic()
	{
		var key 	 = location.href.split('#')[1];
		var dvpic = $('#dvPicHolder');
		var dvfbk = $('#dvFeedback');

		$.post(worker, {what: 'load picture please', key: key}, function(r)
		{
			if(r.status == 'ok')
			{
				dvpic.html(r.pic);
				dvfbk.html(r.fbk);

				$('link[rel=image_src]').attr('href', $('#dvPicBigThumb img').attr('src'));
				$('meta[name=fbimg]').attr('content', $('#dvPicBigThumb img').attr('src'));

				cId = get_current_pic_id();

				carousel_currents();

				facebook_init();
			}
			//else alert(r.status);
		}, 'json');
	}


	$(window).bind('hashchange', function()
	{
		if(location.hash.length>1 && album_mode) load_pic();
	});

	$(document).ready(function()
	{
		if($('#dvPicCarousel .dvCarousel').length>0)
		{
			$('#dvPicCarousel .dvCarousel').jMyCarousel({
				visible: '400px',
				auto : false,
				vertical : true,
				mouseWheel: true,
				circular: false,
				speed : 200,
				step: 60,
				eltByElt: true,
				evtStart: 'mousedown',
				evtStop: 'mouseup',
			});
		}

		album_mode = ($('#dvPic').length>0);

		if(album_mode)
		{
			cId = get_current_pic_id();
			carousel_currents();
			if(location.hash.length>1)	load_pic();
		}

		facebook_init();
	});

