$(document).ready(function() {
	// font button
	$('#header #sizeMenu').css("display", "block");
	
	// popup link
	$('a.popup').each(function(){
		$(this).attr("ref", $(this).attr("href"));
		$(this).attr("href", "#"+$(this).attr("id"));
		$(this).removeAttr("id");
		$(this).removeAttr("target");
		//$(this).css("cursor","pointer");
	});
							   
	$('a.popup').click(function() {
		var url = $(this).attr("ref");
		var winid = $(this).attr("id");
		window.open(url,winid,'resizable=no,menubar=no,directories=no,status=no,location=no,scrollbars=no,width=1024,height=768');
	});
	
	
	// adjust font size	
	$('body').toggleClass('smalled'); //default
	
	if ($.cookie("fontsize")){
		changeFontSize($.cookie("fontsize"));
	}
	
	$('#sizeMenu li a').click(function(){
		var selectedSize = $(this).attr("href").replace("#","");
		$.cookie("fontsize", selectedSize, { expires: 365, path: '/' });
		location.reload();
	});
	
});

function changeFontSize(selectedSize){
	if(selectedSize == 'large'){
		$('body').toggleClass('larged');
		$('body').toggleClass('smalled');
			
		$('#article').css('font-size', '16px');
		$('#aside').css('font-size', '14px');
		if($('#container').attr("class") == "en"){
			$('#header #sizeMenu ul li#sm_small a').css('background-position', '0px -437px');
			$('#header #sizeMenu ul li#sm_large a').css('background-position', '-100px -437px');			
		}else{
			$('#header #sizeMenu ul li#sm_small a').css('background-position', '-274px -435px');
			$('#header #sizeMenu ul li#sm_large a').css('background-position', '-308px -435px');
		}
		//console.log("larger"); 
	}else{
		$('#article').css('font-size', '13px');
		$('#aside').css('font-size', '13px');
		if($('#container').attr("class") == "en"){
			$('#header #sizeMenu ul li#sm_small a').css('background-position', '-100px -437px');
			$('#header #sizeMenu ul li#sm_large a').css('background-position', '0px -437px');			
		}else{
			$('#header #sizeMenu ul li#sm_small a').css('background-position', '-206px -435px');
			$('#header #sizeMenu ul li#sm_large a').css('background-position', '-240px -435px');	
		}
		//console.log("smaller");
	}
}
