/*
edikud main javascript
Author: edikud
Update: 2009/10/02
Author URI: http://www.mcoooo.com/
If you  found something wrong please contact me that would be very friendly of you.Thank you!
Copyright (c) 2009 edikud
*/
(function(){
function SetCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());
}
window['PHC'] = {};
window['PHC']['SetCookie'] = SetCookie;
})();

jQuery.getPos = function (e){
 var l = 0;
 var t = 0;
 var w = jQuery.intval(jQuery.css(e,'width'));
 var h = jQuery.intval(jQuery.css(e,'height'));
 var wb = e.offsetWidth;
 var hb = e.offsetHeight;
 while (e.offsetParent){
 l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
 t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
 e = e.offsetParent;
 }
 l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
 t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
 return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e){
 if (e) {
 w = e.clientWidth;
 h = e.clientHeight;
 } else {
 w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document
.body.offsetWidth;
 h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : 
document.body.offsetHeight;
 }
 return {w:w,h:h};
};
jQuery.getScroll = function (e){
 if (e) {
 t = e.scrollTop;
 l = e.scrollLeft;
 w = e.scrollWidth;
 h = e.scrollHeight;
 } else {
 if (document.documentElement && document.documentElement.scrollTop) {
 t = document.documentElement.scrollTop;
 l = document.documentElement.scrollLeft;
 w = document.documentElement.scrollWidth;
 h = document.documentElement.scrollHeight;
 } else if (document.body) {
 t = document.body.scrollTop;
 l = document.body.scrollLeft;
 w = document.body.scrollWidth;
 h = document.body.scrollHeight;
 }
 }
 return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v){
 v = parseInt(v);
 return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
 o = jQuery.speed(s);
 return this.each(function(){
 new jQuery.fx.ScrollTo(this, o);
 });
};
jQuery.fx.ScrollTo = function (e, o)
{
 var z = this;
 z.o = o;
 z.e = e;
 z.p = jQuery.getPos(e);
 z.s = jQuery.getScroll();
 z.clear = function(){clearInterval(z.timer);z.timer=null};
 z.t=(new Date).getTime();
 z.step = function(){
 var t = (new Date).getTime();
 var p = (t - z.t) / z.o.duration;
 if (t >= z.o.duration+z.t) {
 z.clear();
 setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
 } else {
 st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
 sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
 z.scroll(st, sl);
 }
 };
 z.scroll = function (t, l){window.scrollTo(l, t)};
 z.timer=setInterval(function(){z.step();},13);
};
$(document).ready(function(){
	$(".openentry").click(function(){
		var id = $(this).parent().parent().attr('id');
		if($(this).parent().next().text() == ''){
			var postId = id.slice(5);
		}
		$(this).attr('title','open entry/close entry.').parent().next().slideToggle();$(this).toggleClass("closeentry");
		}); 
	$('.openentry').each(function(index) {
		if(index > 2) {
			$(this).click();
		}
	});
	 $(document).ready(function(){
			if($.browser.msie && $.browser.version == 6) {$('#share,#loading,.b2t,.g2b').remove();
			}
	 });	


	 
	 $('a').click(function(){$('#loading').fadeIn(300).addClass('#loading');setTimeout(function(){$('#loading').fadeOut(500);}, 500);});
	$(".wp-smiley-select,.g2b,.b2t,.ing").fadeTo("fast", 0.8); 
	$(".wp-smiley-select,.g2b,.b2t,.ing").hover(function(){
	$(this).fadeTo("500", 1.0); 
	},function(){
	$(this).fadeTo("slow", 0.5); 
	});	


//tab2
$(".post-tab span").mouseover(function(){
		$(".post-tab span").removeClass("tab-current");
		$(this).addClass("tab-current");
		$(".post-tab div").hide();
		$("."+$(this).attr("id")).fadeIn("slow"); });			
	
$(".g2b").click(function(){$.scrollTo("#footer",420);return false});	
$(".b2t").click(function(){$.scrollTo("#page",420);return false});	
$('.ing').click(function(){
$('#rcbox').fadeIn(300);
setTimeout(function(){$('#rcbox').fadeOut(600);}, 12000);});
$(".dbx ul li").each(function(){var A=$(this).find("a").attr("href");var C=A.replace("http://","");C=C.split("/")[0];
var B="http://www.google.com/s2/favicons?domain="+C;$(this).css({"background":"url('"+B+"') no-repeat 0 0","padding-left":"16px"})});
$("#linkspageico li.linkcat").css({"background":"none"});
$("a").bind("focus",function(){if(this.blur){ this.blur();}});
$('#postail,#box,#rcbox,.jclock').css({'-moz-border-radius':'7px','-webkit-border-radius':'7px','border-radius':'7px'});
$(".email").click(function(){
var A="edikud"
var B="gmail.com"
var C=A+"@"+B;
$(this).parent().append("<img src='http://edikud.appspot.com/themes/mcooo/img/ajax-loader.gif' />");
$(this).hide();
setTimeout(function(){
var D=$(".email");
D.next().hide();
D.text(C);
D.attr("href","mailto:"+C).unbind("click");
D.fadeIn(1000)
},3000)
})
})

function loadPostentry(id, data) {
	$('#' + id + ' .post-entry').html(data);
}

jQuery(document).ready(function(){
     tooltip();
	$("#share").hover(
		function(){
			$(this).find("ul").attr({
				"style": 'display:inline'
			});
			$(this).find("ul").animate({opacity: 1, top: "-220"}, {queue:false, duration:400});
		}, 
		function(){
			$(this).find("ul").animate({opacity: 0, top: "-250"}, {queue:false, duration:400}, "linear",
				function(){
					$(this).find("ul").attr({"style": 'display:none'});			
				}
			);
		});
});


this.tooltip = function(){
	xOffset = 10;
	yOffset = 20;
	$("[title]").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("slow");
	},function(){
		this.title = this.t;
		$("#tooltip").remove();
	});
	
	$("[title]").mousemove(function(e){
		$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
	});
};

