/*
   mostly it's my own code [otherwise a proper link will be given as a comment], 
   feel free to use it as you like
@author = "Michał `zeroos` Barciś"
*/

function setOpacity(obj, v){
	obj.opacity = v;
	obj.style.filter = 'alpha(opacity = ' + (v*100) + ')';
	obj.style.opacity = v;
}
function getOpacity(obj, v){
	if(typeof obj != 'undefined') return obj.opacity;
	return 1;
}

//modulo bug
Number.prototype.mod = function(n) {
	return ((this%n)+n)%n;
}


function setActiveStyleSheet(title) {
// based on http://www.alistapart.com/articles/alternate/
//dynamically change stylesheets
	var i, a, main;

	if(title == null){//use preferred stylesheet	
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
			if(a.getAttribute("rel").indexOf("style") != -1 
				&& a.getAttribute("rel").indexOf("alt") == -1
				&& a.getAttribute("title")) {
				title = a.getAttribute("title");
			}
		}
	}

	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}




//listPostsWidget functions
function cyclePosts(){
	if(cyclePosts.work){
		if(typeof changeActPost.act == "undefined"){
			changeActPost.act = 0;
			changeActPost(0);
		}
		else changeActPostBlurred((changeActPost.act+1)%6);
	}
	setTimeout("cyclePosts()", 4000);
}
cyclePosts.work = true;

function changeActPostBlurred(n){
	if(n==changeActPost.act) return;
	changeActPostBlurred.el1 = document.getElementById("listPostsWidget_img_frame_"+changeActPost.act);
	changeActPostBlurred.el2 = document.getElementById("listPostsWidget_img_frame_"+n);


	el1 = changeActPostBlurred.el1;
	el2 = changeActPostBlurred.el2;

	setOpacity(el1, 1.0);
	setOpacity(el2, 0.0);
	el2.style.display = "block";
	changeActPostBlurred.run = true;
	document.getElementById("listPostsWidget_link_"+changeActPost.act).className = "";	
	document.getElementById("listPostsWidget_link_"+(n)).className = "active";
	changeActPost.act = n;
	changeActPostBlurredR();
}
function changeActPostBlurredR(){
	el1 = changeActPostBlurred.el1;
	el2 = changeActPostBlurred.el2;
	if(getOpacity(el1) > 0 && changeActPostBlurred.run){
		setOpacity(el1, getOpacity(el1)-0.05);
		setOpacity(el2, getOpacity(el2)+0.05);
		setTimeout("changeActPostBlurredR()", 50);
	}else if(!changeActPostBlurred.run){ //interrupted
		setOpacity(el1, 1.0);
		setOpacity(el2, 1.0);
	}else{ //normal end
		el1.style.display = "none";
		el2.style.display = "block";
		setOpacity(el1, 1.0);
		setOpacity(el2, 1.0);
		changeActPostBlurred.run = false;
	}
}
function changeActPost(n){
	if(changeActPostBlurred.run){
		changeActPostBlurred.run = false;
		changeActPostBlurred.el1.style.display = "none";
	}
	document.getElementById("listPostsWidget_link_"+changeActPost.act).className = "";
	document.getElementById("listPostsWidget_img_frame_"+changeActPost.act).style.display = "none";

	changeActPost.act = n;
	document.getElementById("listPostsWidget_link_"+(n)).className = "active";
	document.getElementById("listPostsWidget_img_frame_"+(n)).style.display = "block";
}
function mouseOverPost(n){
	changeActPost(n);
	cyclePosts.work = false;
}
function mouseOutPost(n){
	changeActPost.act = n;
	cyclePosts.work = true;
}

