// JavaScript Document
/*$(function() {
	var offset1	= $('#twitterFollow').offset(),
	offset2	= $('#plzFeedBack').offset(),
	topPadding1 = 100,
	topPadding2 = 300;

	$(window).scroll(function() {
		if ($(window).scrollTop() > offset1.top) {
			$('#twitterFollow').stop().animate({
				top: $(window).scrollTop() + topPadding1
			});
			$('#plzFeedBack').stop().animate({
				top: $(window).scrollTop()  + topPadding2
			});
		} else {
			$('#twitterFollow').stop().animate({
				top: $(window).scrollTop() + topPadding1
			});
			$('#plzFeedBack').stop().animate({
				top: $(window).scrollTop() + topPadding2
			});
		}
		
	});
});*/


var intervalID;

function imgRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("__roll."))
			{
				images[i].onmouseover = function() {
					if(this.getAttribute("className")!="noroll" && this.getAttribute("class")!="noroll"){
						this.setAttribute("src", this.getAttribute("src").replace("__roll.", "__rollon."));
					}
				}
				images[i].onmouseout = function() {
					if(this.getAttribute("className")!="onactive" && this.getAttribute("class")!="onactive"){
						this.setAttribute("src", this.getAttribute("src").replace("__rollon.", "__roll."));
					}
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", imgRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", imgRollover);
}
$(document).ready(function(){

	if(!$.cookie("fontsize")){
		fontChange("M");
	}else{
		fontChange($.cookie("fontsize"));
	}

	
	$('#fontSizeS').click(function(){
		fontChange("S");
		return false;
	});
	$('#fontSizeM').click(function(){
		fontChange("M");
		return false;
	});
	$('#fontSizeL').click(function(){
		fontChange("L");
		return false;
	});

	
	$("a img").hover(
		function(){
			if(!$(this).attr('src').match("__roll.")){
				clearInterval(intervalID);
				rollAction($(this));
			}
		},
		function(){
			rollActionClear($(this));
		}
	);
	
	if(activeCategory){
		$.each($(".globalMenu a img"), function(i, val) {
			var matches = new RegExp(activeCategory +"__roll.jpg$");
			if($(val).attr("src").match(matches) != null){
				$(val).attr("src",$(val).attr("src").replace(/__roll.gif/ig , "__rollon.if"));
				$(val).attr("class",'onactive');
				$(this).unwrap();
			}
		});
	}
	
	$('a[href*=#]').click(function() {  
		var target = $(this.hash);  
		target = target.length && target;  
		if (target.length) {  
			var sclpos = 30;  
			var scldurat = 1000;  
			var targetOffset = target.offset().top - sclpos;  
			$('html,body')  
				.animate({scrollTop: targetOffset}, 1000,'swing');  
			return false;  
		}  
	});
	
	$("ul#gnavi li").hover(function() {
		$(this).children('ul').show();
	}, function() {
		$(this).children('ul').hide();
	});

	
	
});

function rollAction(obj){
	obj.animate({opacity:0.5},200);
	//obj.animate({opacity:0.5},200).animate({opacity:1},200);
	//intervalID = setInterval(function() {
	//	obj.animate({opacity:0.5},200).animate({opacity:1},200);
	//}, 500); 
}

function rollActionClear(obj){
	obj.animate({opacity:1},200);
	//clearInterval(intervalID);
}


function fontChange(sizeStr){
	if(sizeStr == 'S'){
		$('body').css('font-size','12px');
		$("#fontSizeS img").attr("src",$("#fontSizeS img").attr("src").replace(/__noactive.gif/ig , "__onactive.gif"));
		$("#fontSizeM img").attr("src",$("#fontSizeM img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$("#fontSizeL img").attr("src",$("#fontSizeL img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$.cookie("fontsize",'S', {expires: 365, path: '/'});
	}else if(sizeStr == 'L'){
		$('body').css('font-size','19px');
		$("#fontSizeS img").attr("src",$("#fontSizeS img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$("#fontSizeM img").attr("src",$("#fontSizeM img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$("#fontSizeL img").attr("src",$("#fontSizeL img").attr("src").replace(/__noactive.gif/ig , "__onactive.gif"));
		$.cookie("fontsize",'L', {expires: 365, path: '/'});
	}else{
		$('body').css('font-size','15px');
		$("#fontSizeS img").attr("src",$("#fontSizeS img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$("#fontSizeM img").attr("src",$("#fontSizeM img").attr("src").replace(/__noactive.gif/ig , "__onactive.gif"));
		$("#fontSizeL img").attr("src",$("#fontSizeL img").attr("src").replace(/__onactive.gif/ig , "__noactive.gif"));
		$.cookie("fontsize",'M', {expires: 365, path: '/'});
	}
	return;
}



