jQuery.preventDefaultEvent = function(e, options) {
    options = options || {shift:1, ctrl:1, alt:1, meta:1, wheel:1};
    var href = e.currentTarget.href;
    if(((options.shift && e.shiftKey)
        || (options.alt && e.altKey)
        || (options.ctrl && e.ctrlKey)
        || (options.meta && e.metaKey)
        || (options.wheel && e.button == 1))
        && href && href.indexOf('#') != 0
        && href.indexOf('javascript:') != 0
    ) return true;
    e.preventDefault();
    return false;
}

$(document).ready(function() {

    //Слайд-шоу
    //openPicasaEmbedFirstTime = true;

    $("#open-picasa-embed").click(function(e){
        if($.preventDefaultEvent(e)) return;

        //if (openPicasaEmbedFirstTime) {
            //openPicasaEmbedFirstTime = false;
            if (jQuery.browser.flash) {
                $("#picasa-embed").prepend('<embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="800" height="533" flashvars="host=picasaweb.google.com&captions=1&hl=ru&feat=flashalbum&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fborobororu%2Falbumid%2F5559212022638559857%3Falt%3Drss%26kind%3Dphoto%26hl%3Dru" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
            } else {
                $("#picasa-embed").prepend('<iframe src="http://picasaweb.google.com/borobororu/DropBox#slideshow" width="800" height="533" frameborder="0"></iframe>');
            }
        //}
        $("#picasa-embed").stop().slideDown(function(){
            $("#open-picasa-embed").hide();
            $("#close-picasa-embed").show();
        });

    });

    $("#close-picasa-embed").click(function(e){
        if($.preventDefaultEvent(e)) return;
        
        $("#picasa-embed").stop().slideUp(function(){
            $("iframe", this).remove();
            $("embed", this).remove();

            $("#close-picasa-embed").hide();
            $("#open-picasa-embed").show();
        });

    });
	
	//
    $("#nojs").attr("id", "js");

    // Если у ссылки пустой хреф
	$("a[href=]")
		.removeAttr("href")
		.click(function() { return false; } );
		
	$("del a")
		.addClass("del")
		.removeAttr("href")
		.click(function() { return false; } );

    // Подсвечиваем ссылки-дублёры вместе
    $("a").live("mouseover",
        function() {
            $("a[href=" + $(this).attr("href") + "]").addClass("pseudo-hover");
        }
    );

    $("a").live("mouseout",
        function() {
            $("a").removeClass("pseudo-hover");
        }
    );
	
	// Убираем title отовсюду
	$("*").removeAttr("title");
	
	
	// Про аватарки
	$("#avatar-q").click(function(event){
        event.preventDefault();
		$("#avatar-a").toggle();
	});
	
	// Бороборо потаскать
	if (!$.browser.msie) {            
		var boroboro = $.cookie('boroboro');
		if (boroboro) {
			$("h1 .home-logo").html(boroboro);
			$("h1 .link-logo a").html(boroboro);
		}
		$("h1 .home-logo")
			.css({"cursor": "move"})
			.mousedown(function() {
				return(false);
			})
			.sortable({
			tolerance: 'pointer',
			cursor: 'move',
			stop: function(){
				boroboro = $("h1 .home-logo").html();
				$.cookie('boroboro', boroboro, { expires: 366 });
			}
		});
	}
	
	// Бороборо потрясти
	/*$("#header .logo a").hover(
		function(){
			$(this).addClass("shake");
			shake_int = setInterval(function(){
				$(".shake").css({"left": Math.round(Math.random())+'px', "top": Math.round(Math.random())+'px'});
			}, 30);
		},
		function() {
			$(this)
				.removeClass("shake")
				.css({"left": 0, "top": 0});
			clearInterval(shake_int);			
		}
	);*/

    //Ответить

    $(".comment-reply-link").click(function(){
        $(".comment-reply-link").not(this).parents(".comment-container").removeClass("comment-container_to-answer");
        $(this).parents(".comment-container").addClass("comment-container_to-answer");
        $("#jsCommentLabel").text("Ваш ответ");
    });

    $("#cancel-comment-reply-link").click(function(){
        $(".comment-container").removeClass("comment-container_to-answer");
        $("#jsCommentLabel").text("Ваш комментарий");
    });
	

	
	// Убираем зацикленные ссылки
	$("a[href$=" + document.location + "]")
	.addClass("current")
	.removeAttr("href")
	.click(function() { return false; } );
	
	// Загрузить темы
    $("#themes-list.themes-list_category").children(".tag-cloud").prepend("<span style='font-size: 3em; margin-right: 20px;'><a href='http://boroboro.ru/' style='margin: 0;' class='black'>Все темы</a>:</span>");
	$("#themes-list a").not(".current").bind("click",function(event){
		event.preventDefault();
		$("#themes-list").hide();
		$("#themes").removeClass("themes-opened");
		$("#themes-load a")
			.removeClass("black")
			.text($(this).text());
		location.href = $(this).attr("href");
	});

	
	$("#themes-load a").click(function(event){
		event.preventDefault();
		if ($(this).hasClass("black")){
			$("#themes-list").hide();
			$("#themes").removeClass("themes-opened");
			$(this).removeClass("black");
		 } else {
			 $("#themes").addClass("themes-opened");
			 $("#themes-list").show();
			 $(this).addClass("black");
		 }
	});
	
	$("#themes").bind("click", function(event) {
    	event.stopPropagation();
	});
	
	$(document).bind("click", function() {
        $("#themes-list").hide();
		$("#themes").removeClass("themes-opened");
		$("#themes-load a").removeClass("black");
    });
	
	
	// Навигация «вверх-вниз»
	/*var linkPrev = $("#link-prev a").attr("href");
    var linkNext = $("#link-next a").attr("href");

    $(document).bind('keydown', 'ctrl+down', function(){
        if (linkPrev) {
            location.href = linkPrev;
        }
    });

    $(document).bind('keydown', 'ctrl+up', function(){
        if (linkNext) {
            location.href = linkNext;
        }
    });*/
	
	//Галерея	
	$(".fullsize img").fullsize();

    // Парагарафы с картинками
    $("p img").parent("p").addClass("image");


//	$(".home .author-n-time .time:first").hide();
	
	 //Фэйд-ин и -аут для постов
    /*$(".hentry").not(":first").animate({opacity: .5});

    if ($(".hentry").size() > 1) {
        $(".hentry").hover(
            function() {
                $(this).animate({opacity: 1});
            },
            function() {
                $(this).animate({opacity: .5});
            }
        );
    }*/

});
