﻿(function() {
    jQuery.fn.cumulativeOffset = function(e) {
        var t = 0,
        l = 0;
        do {
            t += e.offsetTop || 0;
            l += e.offsetLeft || 0;
            e = e.offsetParent
        }
        while (e);
        return [l, t]
    };
    var feed_mouseover_tid = null;
    var feed_mouseout_tid = null;
    jQuery(document).ready(function() {
        jQuery('a[rel*="external"]').click(function() {
            window.open(this.href);
            return false
        });
        jQuery('a[href!="#"][href!="#ViewPollResults"][href^="#"]').click(function() {
            jQuery.scrollTo(this.href.replace(/^.*#/g, '#'), 400, {
                offset: 0
            });
            return false
        });
        jQuery('div.post').each(function() {
            var _post = this;
            var id = jQuery(_post).attr('id');
            if (/^post\-[0-9]+$/.test(id)) {
                if (/blank_content/i.test(jQuery(_post).find('.content').attr('class'))) {
                    var toggle = jQuery('<a title="展开" href="javascript:void(0);" class="toggle collapse"></a>');
                    toggle.toggle(function() {
                        expand(id, _post)
                    },
                    function() {
                        collapse(_post)
                    })
                } else {
                    var toggle = jQuery('<a title="收缩" href="javascript:void(0);" class="toggle expand"></a>');
                    toggle.toggle(function() {
                        collapse(_post)
                    },
                    function() {
                        expand(id, _post)
                    })
                }
                toggle.prependTo(jQuery(_post))
            }
        });
    });
    function expand(id, post) {
        if (jQuery(post).find('.content').text() == '') {
            loadPost(id)
        }
        jQuery(post).find('.content').slideDown();
        jQuery(post).find('a.toggle').removeClass('collapse').addClass('expand').attr({title:"收缩"})
    }
    function collapse(post) {
        jQuery(post).find('.content').slideUp();
        jQuery(post).find('a.toggle').removeClass('expand').addClass('collapse').attr({title:"展开"})
    }
    function loadPost(id) {
        var postId = id.slice(5);
        jQuery.ajax({
            type: 'GET',
            url: '?action=load_post&id=' + postId,
            cache: false,
            dataType: 'html',
            contentType: 'application/json; charset=utf-8',
            beforeSend: function(data) {
                loadPostContent(id, '<p class="ajax-loader">Loading...</p>')
            },
            success: function(data) {
                loadPostContent(id, data)
            },
            error: function(data) {
                loadPostContent(id, '<p>Oops, failed to load data. <small><a href="javascript:void(0);" onclick="POS.loadPost(\'' + id + '\');">[Reload]</a></small></p>')
            }
        })
    }
    function loadPostContent(id, data) {
        jQuery('#' + id + ' .content').html(data)
    }
})();
$(document).ready(function(){
	var say=$('#philna_say');
	say.click(function(){
	$.ajax({
	url: window.location.href,
	type:'POST',
	data: "refresh=philna_say",
	dataType:'html',
	beforeSend:function(){
		say.css('color','#000').hide('slow');
		setTimeout(function(){say.html('<span id="sayload"></span>').show('fast');},500);
		},
	error:function(request){
		say.html('Whoops! Something went wrong.Sorry');
		},
	success:function(data){
	setTimeout(function(){say.hide();say.html(data).show('slow');},2000);
	say.css('color','#8E8E8E');
	}
	})
	})
})

var mouseover_tid = [];
var mouseout_tid = [];
 jQuery(document).ready(function(){
	jQuery('.content > #subscribe').each(function(index){
		jQuery(this).hover(
			function(){
				var _self = this;
				clearTimeout(mouseout_tid[index]);
				mouseover_tid[index] = setTimeout(function() {
					jQuery(_self).find('ul:eq(0)').slideDown(200);
				}, 400);
			},
			function(){
				var _self = this;
				clearTimeout(mouseover_tid[index]);
				mouseout_tid[index] = setTimeout(function() {
					jQuery(_self).find('ul:eq(0)').slideUp(200);
				}, 400);
			}
 		);
	});
});

jQuery(document).ready(function() {
   jQuery("#thecomments li:odd").addClass("evencomment");
   }); 

$(document).ready(function() {
	$("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])")
	.addClass("external")
	.attr("target","_blank");
}); 

$(document).ready(function(){
	$(".contact_email").click(function(){
		var A="wei333"
		var B="wei333.com & pwei333"
		var C=A+"@"+B
		var D="gmail.com"
		var E=C+"@"+D;
		$(this).text(E);
	})
})

$(document).ready(function(){
    $(".post img,.cattag img,#posts img,#comments img,#sidebar img").lazyload({
        placeholder : "http://files.wei333.com/img/lazyload/grey.gif",
        effect : "fadeIn"
    });
});