jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

$(window).load(function() {
    $('#imprint').click(function() {
        $('div.imprint').slideToggle('slow');
    });
});

$(document).ready(function() {
    var status = 0;
    var offset_ = 0;

    $('.scroller-inner').scrollTop($.cookie('scroll_offset'));

    $('.ctrl-down').bind('mouseover mouseout', function(event){ 
        if(event.type == 'mouseover'){ 
            $.cookie('scroll_offset', null);
            $('.scroller-inner').animate({"scrollTop": "+=2000px"}, 10000, 'linear');
        }else{ 
            $('.scroller-inner').stop(); 
            offset_ = $('.scroller-inner').scrollTop();
            $.cookie('scroll_offset', offset_, { path: '/' });
        } 
    }); 

    $('.ctrl-up').bind('mouseover mouseout', function(event){ 
        if(event.type == 'mouseover'){ 
            $('.scroller-inner').animate({"scrollTop": "-=2000px"}, 10000, 'linear'); 
        }else{ 
            $('.scroller-inner').stop(); 
            offset_ = $('.scroller-inner').scrollTop();
            $.cookie('scroll_offset', offset_, { path: '/' });
        } 
    })

    $('.show-all').click(function() {
        $('.scroller').css('width','auto').css('right', '125px').css('height','auto');
        $('.scroller-inner').css('width','auto').css('height','auto').css('margin-bottom','100px');
        $('.show-all').hide();
        $('.all').fadeIn();
        $('.viewer').hide();
        $('.ctrl-up').hide();
        $('.ctrl-down').hide();
        $('.even').css('margin-right', '10px');
        $('.scroller').css('margin-top:','-210px');
    });
    $('.all').click(function() {
        $('.scroller').css('width','336px').css('right', '').css('height','375px');
        $('.scroller-inner').css('width','336px').css('height','375px').css('margin-bottom','0');
        $('.show-all').fadeIn();
        $('.all').hide();
        $('.viewer').show();
        $('.ctrl-up').show();
        $('.ctrl-down').show();
        $('.even').css('margin-right', '0');
        $('.scroller').css('margin-top:','-220px');
    });

    $('#glasses_gallery').bxGallery({
    		maxwidth: '',              // if set, the main image will be no wider than specified value (in pixels)
    		maxheight: '',             // if set, the main image will be no taller than specified value (in pixels)
    		thumbwidth: 75,           // thumbnail width (in pixels)
    		thumbcrop: false,          // if true, thumbnails will be a perfect square and some of the image will be cropped
    		croppercent: .35,          // if thumbcrop: true, the thumbnail will be scaled to this 
    								   // percentage, then cropped to a square
    		thumbplacement: 'bottom',  // placement of thumbnails (top, bottom, left, right)
    		thumbcontainer: '',        // width of the thumbnail container div (in pixels)
    		opacity: .7,               // opacity level of thumbnails
    		load_text: '',             // if set, text will display while images are loading
    		load_image: 'http://i302.photobucket.com/albums/nn92/wandoledzep/spinner.gif',
    		                           // image to display while images are loading
    		wrapperclass: 'outer'      // classname for outer wrapping div
    	});
        
    $.vegas();
    
   /* var tip = $("#tip");

    $(".tip").hover(
        function(e) {
            alert("fail!");
            tip.text($(this).attr("title"));
            $(this).attr("title", "");
            tip.css("top",(e.pageY+5)+"px").css("left",(e.pageX+5)+"px").fadeIn("slow");
        }, 
        function() {
            $("#tip").fadeOut("fast");
            $(this).attr("title", tip.html());
        }
    );*/
    
    var recent_posts_count = 10;
            var recentPostsHtml = "";
            var size = tumblr_api_read.posts.length;
            for (var i = 0; i < size; i++) {
                var obj = tumblr_api_read.posts[i];
                
                var url = obj.url;
                var title;
                
                if (obj['regular-title'] == undefined) {
                    title = obj['photo-caption'];
                } else {
                    title = obj['regular-title'];
                }
                
                recentPostsHtml += "<div class='latest-news-item'><h3><a href='" + url + "' >" + title + "</a></h3></div>";
            }
            $("#recentPosts").html(recentPostsHtml);

});
