Cufon.replace('#navigation li');
Cufon.replace('#top-tabs li');
Cufon.replace('h1');





// Pictures scripts
function _picturesArrayIndex(__array, __level, __v) {
	var l = __array.length;
	for(var i = 0; i < l; i++) {
		if(__array[i][__level] == __v) {
			return i;
		}
	}
	return -1;
}

function picturesArrayIndex(__array, __level, __v) {
	var l = __array.length;
	for(var i = 0; i < l; i++) {
		if(__array[i]['picture'] == __v) {
			return i;
		}
	}
	return -1;
}

function loadImage(url, id) {
	//alert('loadImage '+ id);
	var prev_id = id == 0 ? pictures.length : id;
	var next_id = (id + 2) > pictures.length ? 1 : id + 2;
	
	$('#picture-no').text(id + 1);
	$('#picture a:first').attr('href', '#/'+ next_id);
	$('#picture img:first').attr('src', url + 'p'+ pictures[id]['picture'] +'_n.jpg');
	$('#caption').text(stripslashes(pictures[id]['caption'] == '' ? captionDefaultText : pictures[id]['caption']));
	$('.gallery-controls .previous').attr('href', '#/'+ prev_id);
	$('.gallery-controls .next').attr('href', '#/'+ next_id);
}




function addslashes(str) {
    // From PHP.js
    return (str+'').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

function stripslashes(str) {
	// From PHP.js
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}



var Slideshow = {
	_timer: 4000,
	_offset: -1,
	_len: 0,
	_els: null,
	_name: 'Slideshow',
	
	
	init: function(e) {
		var _this = Slideshow;
		
		$(e).find('li').css('display', 'none');
		$(e).find('li').css('cursor', 'pointer');
		$(e).find('li').click(function(evt) {
			_this.callBack();
		});
		
		this._els = $(e).find('li');
		this._len = this._els.length;
		if(this._len > 1) {
			this.callBack();
			var si = setInterval(this.callBack, this._timer);
		}
	},
	
	callBack: function() {
		var _this = Slideshow;
		var _old = _this._offset;
		var _new = (_this._offset + 1) == _this._len ? 0 : _this._offset + 1;
		$(_this._els[_new]).fadeIn(400);
		if(_old > -1) {
			$(_this._els[_old]).fadeOut(400);
		}
		_this._offset = _new;
	}
}









$(function(e) {
	$('.links li, .events-list li').click(function(e) {
		document.location.href = $(this).find('a:first').attr('href');
	});
	
	
	$('.form input, .form textarea, .form select').focus(function(e) {
		$(this).closest('li').addClass('focus');
	});
	
	$('.form input, .form textarea, .form select').blur(function(e) {
		$(this).closest('li').removeClass('focus');
	});
});

