function initCufon() {

    Cufon.replace('.switcher strong', { fontFamily: 'Eurostile' });
    Cufon.replace('#entry h1', { fontFamily: 'Eurostile' });
    Cufon.replace('.title h2', { fontFamily: 'Eurostile' });

}
function initOpen() {
    $('#sidebar').each(function() {
        var hold = $(this);
        var link = hold.find('.open-gallery');
        var box = hold.find('div.gallery');
        var h = box.outerHeight(true);

        box.css({ height: h });
        link.click(function() {
            if (!box.hasClass('opened'))
                box.addClass('opened').animate({ height: h }, 300);
            else
                box.removeClass('opened').animate({ height: 0 }, 300);
        });
    });
}
jQuery.fn.gallSlide = function(_options) {
    // defaults options	
    var _options = jQuery.extend({
        duration: 700
    }, _options);

    return this.each(function() {
        var _hold = $(this);
        var _speed = _options.duration;
        var _wrap = _hold.find('ul');
        var _el = _hold.find('ul > li');
        var _next = _hold.find('a.link-next1');
        var _prev = _hold.find('a.link-prev1');
        var _count = 0;
        var _count2 = _el.index(_el.filter(':last'));
        var der = 0;
        var _wrapHolderW = _wrap.parent().width() + 8;
        var rety = 0;

        _el.each(function(_i) {

            _count = _count + $(this).outerWidth(true);
            if (rety + _el.eq(_count2 - _i).outerWidth(true) <= _wrapHolderW) {
                der++;
                rety = rety + _el.eq(_count2 - _i).outerWidth(true);
            }
        });
        var _active = 0;
        var _w = 0;

        function scrollEl() {
            _wrap.eq(0).animate({
                marginLeft: -(_w) + "px"
            }, { queue: false, duration: _speed });
        }
        _next.click(function() {
            if (_w == _count - _wrapHolderW) _active = -1;
            _w = 0;
            _active++;
            for (var i = 0; i < _active; i++) {
                _w = _w + _el.eq(i).outerWidth(true);
            };
            if (_w > (_count - _wrapHolderW)) {
                _w = _count - _wrapHolderW;
                scrollEl();
            }
            else {
                scrollEl();
            }
            return false;
        });
        _prev.click(function() {
            if (_w == _count - _wrapHolderW) _active = _count2 - der + 2;
            _w = 0;
            _active--;
            for (var i = 0; i < _active; i++) {
                _w = _w + _el.eq(i).outerWidth(true);
            };
            if (_active == -1) {
                _w = _count - _wrapHolderW;
                scrollEl();
            }
            else {
                scrollEl();
            }
            return false;
        });
    });
}

$(document).ready(function() {
    initCufon();
    initOpen();
    if ($('#cbox').length != 0) {
        var temp = $('<ul></ul>');
        $('#cbox').append(temp);
        temp.jflickrfeed({
            qstrings: {
                id: usedID
            },
            itemTemplate:
		    '<li>' +
			    '<a rel="1" href="{{image}}" title="{{title}}">' +
				    '<img height="84" width="84" src="{{image_s}}" alt="{{title}}" />' +
			    '</a>' +
		    '</li>'
        }, function(data) {
            setTimeout(function() {
                $('div.gallery').gallSlide();
                $('a[rel = 1]').lightBox();
            }, 500);
        });
    } else {
        $('div.gallery').gallSlide();
        $('a[rel = 1]').lightBox();
    }
});