//monthlySelect
var monthlySelectTimerID;
var monthlySelectFlag1 = true;
var monthlySelectFlag2 = true;
var categorySelectTimerID;
var categorySelectFlag1 = true;
var categorySelectFlag2 = true;
var listItemData = new Object();

document.observe('dom:loaded', function(){
	$('monthlySelect').style.display = "none";
	$('monthlySelectTitle').onmouseover = function(){monthlySelectFlag1 = false;};
	$('monthlySelectTitle').onmouseout = function(){monthlySelectFlag1 = true;};
	$('monthlySelect').onmouseover = function(){monthlySelectFlag2 = false;};
	$('monthlySelect').onmouseout = function(){monthlySelectFlag2 = true;};
	$('categorySelect').style.display = "none";
	$('categorySelectTitle').onmouseover = function(){categorySelectFlag1 = false;};
	$('categorySelectTitle').onmouseout = function(){categorySelectFlag1 = true;};
	$('categorySelect').onmouseover = function(){categorySelectFlag2 = false;};
	$('categorySelect').onmouseout = function(){categorySelectFlag2 = true;};

	$$('.more').each(function(more) {
		more.style.display = "block";
	});
	$$('.entryMore').each(function(entryMore) {
		listItemData[entryMore.id] = { height: entryMore.offsetHeight, effect: "" };
		entryMore.setStyle({ height: 0, overflow: "hidden" });
	});
	effectInit();
});

function monthlyPulldown(){
	$('monthlySelect').style.display = "block";
	if(monthlySelectTimerID != null){
		clearInterval(monthlySelectTimerID);
	}
	monthlySelectTimerID = setInterval(monthlyPulldownOff, 10);
}

function monthlyPulldownOff(){
	if(monthlySelectFlag1 && monthlySelectFlag2){
		$('monthlySelect').style.display = "none";
		clearInterval(monthlySelectTimerID);
	}
}

function categoryPulldown(){
	$('categorySelect').style.display = "block";
	if(categorySelectTimerID != null){
		clearInterval(categorySelectTimerID);
	}
	categorySelectTimerID = setInterval(categoryPulldownOff, 10);
}

function categoryPulldownOff(){
	if(categorySelectFlag1 && categorySelectFlag2){
		$('categorySelect').style.display = "none";
		clearInterval(categorySelectTimerID);
	}
}


function moreOpen(id){
//	$('entryMore' + id).style.display = "block";
	accordion(id, "open");
	$('morebtn' + id).style.display = "none";
	$('closebtn' + id).style.display = "block";
}

function moreClose(id){
//	$('entryMore' + id).style.display = "none";
	accordion(id, "close");
	$('morebtn' + id).style.display = "block";
	$('closebtn' + id).style.display = "none";
}



function accordion(id, action){
	var target = "entryMore" + id;
	if(listItemData[target].effect){
		listItemData[target].effect.cancel();
	}
	var fromH = $(target).offsetHeight, toH;
	if(action == "open"){
		toH = listItemData[target].height;
	}else{
		toH = 0;
	}
	listItemData[target].effect = new Effect.yAccordion(target, {
		transition: Effect.Transitions.easeOutQuint,
		duration:   0.5,
		from:       fromH,
		to:         toH
	});
}



function effectInit(){

Effect.yAccordion = Class.create(Effect.Base, {
    initialize: function(element) {
        this.element = $(element);
        var options = Object.extend({}, arguments[1] || {});
        this.start(options);
    },
    update: function(position) {
        this.element.style.height = Math.round(position) + "px";
    }
});

if (Effect.Transitions) {
    Object.extend(
        Effect.Transitions,
        {
            easeNone: function(pos) {
                return pos;
            },    
            easeInQuad: function(pos) {
                return pos*pos;
            },    
            easeOutQuad: function(pos) {
                return -(pos)*(pos-2);
            },    
            easeInOutQuad: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t;
                return -0.5 *((--t)*(t-2) - 1);
            },    
            easeInCubic: function(pos) {
                return pos*pos*pos;
            },    
            easeOutCubic: function(pos) {
                return (t=pos-1)*t*t + 1;
            },    
            easeInOutCubic: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t*t;
                return 0.5*((t-=2)*t*t + 2);
            },    
            easeOutInCubic: function(pos) {
                if(pos < 0.5) return 0.5*Effect.Transitions.easeOutCubic(pos*2);
                return 0.5+0.5*Effect.Transitions.easeInCubic((pos*2)-1);
            },    
            easeInQuart: function(pos) {
                return pos*pos*pos*pos;
            },    
            easeOutQuart: function(pos) {
                return -((t=pos-1)*t*t*t - 1);
            },    
            easeInOutQuart: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t*t*t;
                return -0.5 *((t-=2)*t*t*t - 2);
            },    
            easeOutInQuart: function(pos) {
                if(pos < 0.5) return 0.5*Effect.Transitions.easeOutQuart(pos*2);
                return 0.5+0.5*Effect.Transitions.easeInQuart((pos*2)-1);
            },    
            easeInQuint: function(pos) {
                return pos*pos*pos*pos*pos;
            },    
            easeOutQuint: function(pos) {
                return (t=pos-1)*t*t*t*t + 1;
            },    
/*
            easeInOutQuint: function(t, b, c, d) {
                if((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
                return c/2*((t-=2)*t*t*t*t + 2) + b;
            },    
            easeOutInQuint: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutQuint(t*2, b, c/2, d);
                return Effect.Transitions.easeInQuint((t*2)-d, b+c/2, c/2, d);
            },    
            easeInSine: function(t, b, c, d) {
                return -c * Math.cos(t/d *(Math.PI/2)) + c + b;
            },    
*/
            easeOutSine: function(pos) {
                return Math.sin(pos *(Math.PI/2));
            },    
            easeInOutSine: function(pos) {
                return -1/2 *(Math.cos(Math.PI*pos) - 1);
            },    
/*
            easeOutInSine: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutSine(t*2, b, c/2, d);
                return Effect.Transitions.easeInSine((t*2)-d, b+c/2, c/2, d);
            },    
*/
            easeInExpo: function(pos) {
                return(pos==0) ? 0 : Math.pow(2, 10 *(pos - 1)) - 0.001;
            },    
            easeOutExpo: function(pos) {
                return(pos==1) ? 1 : 1.001 *(-Math.pow(2, -10 * pos) + 1);
            },    
/*
            easeInOutExpo: function(t, b, c, d) {
                if(t==0) return b;
                if(t==d) return b+c;
                if((t/=d/2) < 1) return c/2 * Math.pow(2, 10 *(t - 1)) + b - c * 0.0005;
                return c/2 * 1.0005 *(-Math.pow(2, -10 * --t) + 2) + b;
            },    
            easeOutInExpo: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutExpo(t*2, b, c/2, d);
                return Effect.Transitions.easeInExpo((t*2)-d, b+c/2, c/2, d);
            },    
*/
            easeInCirc: function(pos) {
                return -(Math.sqrt(1 -pos*pos) - 1);
            },    
            easeOutCirc: function(pos) {
                return Math.sqrt(1 -(t=pos-1)*t);
            },    
/*
            easeInOutCirc: function(t, b, c, d) {
                if((t/=d/2) < 1) return -c/2 *(Math.sqrt(1 - t*t) - 1) + b;
                return c/2 *(Math.sqrt(1 -(t-=2)*t) + 1) + b;
            },    
            easeOutInCirc: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutCirc(t*2, b, c/2, d);
                return Effect.Transitions.easeInCirc((t*2)-d, b+c/2, c/2, d);
            },    
            easeInElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d)==1) return b+c;  if(!p) p=d*.3;
                if(!a || a < Math.abs(c)) { a=c; s=p/4; } else s = p/(2*Math.PI) * Math.asin(c/a);
                return -(a*Math.pow(2,10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )) + b;
            },    
            easeOutElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d)==1) return b+c;  if(!p) p=d*.3;
                if(!a || a < Math.abs(c)) { a=c; s=p/4; } else s = p/(2*Math.PI) * Math.asin(c/a);
                return(a*Math.pow(2,-10*t) * Math.sin((t*d-s)*(2*Math.PI)/p ) + c + b);
            },    
            easeInOutElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d/2)==2) return b+c;  if(!p) p=d*(.3*1.5);
                if(!a || a < Math.abs(c)) { a=c; s=p/4; }       else s = p/(2*Math.PI) * Math.asin(c/a);
                if(t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )) + b;
                return a*Math.pow(2,-10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )*.5 + c + b;
            },    
            easeOutInElastic: function(t, b, c, d, a, p) {
                if(t < d/2) return Effect.Transitions.easeOutElastic(t*2, b, c/2, d, a, p);
                return Effect.Transitions.easeInElastic((t*2)-d, b+c/2, c/2, d, a, p);
            },    
*/
            easeInBack: function(pos, s) {
                if(s == undefined) s = 1.70158;
                return pos*pos*((s+1)*pos - s);
            },    
            easeOutBack: function(pos, s) {
                if(s == undefined) s = 1.70158;
                return (t=pos-1)*t*((s+1)*t + s) + 1;
            },    
/*
            easeInOutBack: function(t, b, c, d, s) {
                if(s == undefined) s = 1.70158;
                if((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
                return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
            },    
            easeOutInBack: function(t, b, c, d, s) {
                if(t < d/2) return Effect.Transitions.easeOutBack(t*2, b, c/2, d, s);
                return Effect.Transitions.easeInBack((t*2)-d, b+c/2, c/2, d, s);
            },    
            easeInBounce: function(t, b, c, d) {
                return c - Effect.Transitions.easeOutBounce(d-t, 0, c, d) + b;
            },    
*/
            easeOutBounce: function(pos) {
                if((pos) <(1/2.75)) {
                    return 7.5625*pos*pos;
                } else if(pos <(2/2.75)) {
                    return 7.5625*(pos-=(1.5/2.75))*pos + .75;
                } else if(pos <(2.5/2.75)) {
                    return 7.5625*(pos-=(2.25/2.75))*pos + .9375;
                } else {
                    return 7.5625*(pos-=(2.625/2.75))*pos + .984375;
                }
            }
/*,    
            easeInOutBounce: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeInBounce(t*2, 0, c, d) * .5 + b;
                else return Effect.Transitions.easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b;
            },    
            easeOutInBounce: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutBounce(t*2, b, c/2, d);
                return Effect.Transitions.easeInBounce((t*2)-d, b+c/2, c/2, d);
            }
*/
            
        });
}

}
