$(document).ready(function(){
switchFontsize();
smoothScroll();
});

//FUNCTION switchFontsize
var switchFontsize = function () {
	$('#resizer').css('display','block');
	if($.cookie('TEXT_SIZE')) {
		$('body').addClass($.cookie('TEXT_SIZE'));
		$('#resizer a').removeClass();
		$('#resizer dd').each(function() {
			if($(this).attr('class') == $.cookie('TEXT_SIZE')){
			$(this).children('a').addClass('selected');
			}
		});
	}
	$('#resizer a').click(function() {
		var textSize = $(this).parent().attr('class');
		$('body').removeClass('small medium large').addClass(textSize);
		$('#resizer a').removeClass();
		$(this).addClass('selected');
		$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
		return false;
	});
}

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

//FUNCTION smoothScroll
var actX;
var actY;
var tarY = 0;
var tarX = 0;
var scrollInt;
var smoothScroll = function () {
	jQuery('a').each(function(){
		var anc = this.href.split('#')[1];
		if( anc && /#/.test(this.href)  && this.href.match(location.href) && jQuery('#'+anc)[0]){
			this.href="javascript:void(0);";
			jQuery(this).bind('click', function  (){
				tarX = (jQuery(document).width() > jQuery('#'+anc).position().left + jQuery(window).width())
					? jQuery('#'+anc).position().left
					: jQuery(document).width() - jQuery(window).width();
				tarY = (jQuery(document).height() > jQuery('#'+anc).position().top + jQuery(window).height())
					? jQuery('#'+anc).position().top
					: jQuery(document).height() - jQuery(window).height();
			  actX = jQuery(document).scrollLeft();
			  actY = jQuery(document).scrollTop();
				clearInterval(scrollInt);
				scrollInt = setInterval('setScroll()', 20);
			});
		}
	});
}

function setScroll(){
	actY += (tarY - actY) / 6;
	actX += (tarX - actX) / 6;
	if(Math.abs(tarX - actX) < 2 && Math.abs(tarY - actY) < 2){
		clearInterval(scrollInt);
	}
	scrollTo( Math.round(actX), Math.round(actY));
}

function blankToPop () {
	jQuery('a.commonPop').each(function(){
		$(this).removeAttr("target");
		$(this).attr('popURL', this.href);
		( $(this).attr("rel") ? "" : $(this).attr("rel","") );
		this.href = "javascript:;";
		$(this).click(function () {
			eval("commonPop('"+$(this).attr("popURL")+"',"+$(this).attr("rel")+")");
		});
	});
}
