var fontSize=readCookie('fontSize');
function changeSize(objs,increase){
	for(var i=0;i<objs.length;i++){
		var size=objs[i].style.fontSize.replace('px','');
		objs[i].style.fontSize=(16+increase)+'px';
	}
	if(isNaN(objs.length)){objs.style.fontSize=(16+increase)+'px';}
	return size;
}
function changeFontSize(obj,increase){
	obj=get(obj,null,null,1);
	if(obj.length<=0){return false;}
	if(isNaN(increase) || increase==''){increase=0;}
	fontSize+=increase;
	fontSize=Math.max(-6,Math.min(fontSize,6));
	for(var i=0;i<obj.length;i++){
		temp=obj[i];
		changeSize(temp,fontSize);
		objs=get(temp,null,null,1);
		changeSize(objs,fontSize);
		objs=get(null,null,temp,1);
		changeSize(objs,fontSize);
	}
	saveCookie('fontSize',fontSize,'10');
}

function saveCookie(cookieName,cookieValue,days){
	var date=new Date();
	var expires;
	if(days){
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires='EXPIRES='+date.toGMTString()+';';
	}
	if(document.cookie=cookieName+"="+cookieValue+";"+expires+"PATH=/"){
		return true;
	}
	return false;
}

function readCookie(cookieName){
	var cookieString=document.cookie;
	var index1=cookieString.indexOf(cookieName);
	if(index1<0 || cookieName==''){return "";}
	var index2=cookieString.indexOf(';',index1);
	if(index2<0){index2=cookieString.length;}
	return unescape(cookieString.substring(index1+(cookieName.length+1),index2));
}

function abreFoto(src){
	window.open("foto.php?src="+src, "Foto", "width=40,height=40,top=90,left=90,menubar=no,location=no,resizable=no,scrollbars=0,status=no");
}

function convertRGB(hex){
	var red=parseInt(hex.substring(1,3),16);
	var grn=parseInt(hex.substring(3,5),16);
	var blu=parseInt(hex.substring(5,7),16);
	return [red,grn,blu];
}

function rgb2hex(red,green,blue){
	var decColor=blue+256*green+65536*red;
	return decColor.toString(16);
}

//sexy-bookmarks

jQuery(document).ready(function() {

	// xhtml 1.0 strict way of using target _blank
	jQuery('.sexy-bookmarks a.external').attr("target", "_blank");

	// this block sets the auto vertical expand when there are more than 
	// one row of bookmarks.
	var sexyBaseHeight=jQuery('.sexy-bookmarks').height();
	var sexyFullHeight=jQuery('.sexy-bookmarks ul.socials').height();
	if (sexyFullHeight>sexyBaseHeight) {
		jQuery('.sexy-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: sexyFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: sexyBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// autocentering
	if (jQuery('.sexy-bookmarks-center') || jQuery('.sexy-bookmarks-spaced')) {
		var sexyFullWidth=jQuery('.sexy-bookmarks').width();
		var sexyBookmarkWidth=jQuery('.sexy-bookmarks:first ul.socials li').width();
		var sexyBookmarkCount=jQuery('.sexy-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(sexyFullWidth/sexyBookmarkWidth);
		var sexyRowWidth=Math.min(numPerRow, sexyBookmarkCount)*sexyBookmarkWidth;
		
		if (jQuery('.sexy-bookmarks-spaced').length>0) {
			var sexyLeftMargin=Math.floor((sexyFullWidth-sexyRowWidth)/(Math.min(numPerRow, sexyBookmarkCount)+1));
			jQuery('.sexy-bookmarks ul.socials li').css('margin-left', sexyLeftMargin+'px');
		} else if (jQuery('.sexy-bookmarks-center'.length>0)) {
			var sexyLeftMargin=(sexyFullWidth-sexyRowWidth)/2;
			jQuery('.sexy-bookmarks-center').css('margin-left', sexyLeftMargin+'px');
		}
		
	}
});