/*
* shared.js with jQuery
*
*/


//Popup
function openPopup1(url, name, w, h) {
	var newPopup;
	var options = ",toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes";
	var x = (screen.availWidth - 680)/2;
	var y = (screen.availHeight - 560)/2;
	newPopup = window.open('privacy.html', name,"width=680,height=560,left=" + x + ", top=" + y + options);
	newPopup.focus();
}

function openPopup2(url, name, w, h) {
	var newPopup;
	var options = ",toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes";
	var x = (screen.availWidth - 680)/2;
	var y = (screen.availHeight - 560)/2;
	newPopup = window.open('../privacy.html', name,"width=680,height=560,left=" + x + ", top=" + y + options);
	newPopup.focus();
}

function openPopup3(url, name, w, h) {
	var newPopup;
	var options = ",toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes";
	var x = (screen.availWidth - 680)/2;
	var y = (screen.availHeight - 300)/2;
	newPopup = window.open('http://www.facebook.com/plugins/like.php?href=http://www.akb48cho.jp/campaign/index.html', name,"width=680,height=300,left=" + x + ", top=" + y + options);
	newPopup.focus();
}

function openPopup4(url, name, w, h) {
	var newPopup;
	var options = ",toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes";
	var x = (screen.availWidth - 680)/2;
	var y = (screen.availHeight - 300)/2;
	newPopup = window.open('http://www.facebook.com/plugins/like.php?href=http://www.akb48cho.jp/cm/index.html', name,"width=680,height=300,left=" + x + ", top=" + y + options);
	newPopup.focus();
}

function openPopup5(url, name, w, h) {
	var newPopup;
	var options = ",toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes";
	var x = (screen.availWidth - 680)/2;
	var y = (screen.availHeight - 300)/2;
	newPopup = window.open('http://www.facebook.com/plugins/like.php?href=http://www.akb48cho.jp/web/index.html', name,"width=680,height=300,left=" + x + ", top=" + y + options);
	newPopup.focus();
}



//Scroll
function smartScroll (){	
	var easing = 0.2;
	var interval = 30;
	var allLinks = document.links;
	
	for (var i=0;i<allLinks.length;i++){
		var lnk = allLinks[i];
		
		if ((lnk.href && lnk.href.indexOf('#') != -1) && ((lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname))){
			var myHash = lnk.hash.replace(/#/g,"");
			if (!(myHash.length == 0)){
				lnk.onclick = function (){
				
					var hash = this.hash;
					var targetId = hash.replace(/#/g,"");
				
					if (!document.getElementById(targetId)) return;
					
					var element = document.getElementById(targetId);
					var targetY = 0;
					while(element){
					   targetY += element.offsetTop;
					   element = element.offsetParent;
					}					
					
					var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
					
					var windowHeight = window.innerHeight || document.documentElement.clientHeight;
					var bodyHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
					var footHeight = bodyHeight - targetY;
					var adjust = windowHeight - footHeight;
					
					
					if (windowHeight > footHeight){				
						var toY = targetY - scrollTop - adjust;
					} else	{
						var toY = targetY - scrollTop;
					}
										
					function windowScroll (){
						var moveY = Math.floor(toY*easing);	
						window.scrollBy(0,moveY);
						toY -= moveY; 
						myTimer = setTimeout(windowScroll,interval);
						if (moveY == 0) clearTimeout(myTimer);
					}								
					windowScroll();	
					return false;					
				};
			}
		}
	}	
}



(function($) {	
	
	var rollover = function (){
			$('img.rollover').not('[src*="_on."]').mouseover(function(){
				$(this).attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_on$2'));
			}).mouseout(function(){
				$(this).attr('src',$(this).attr('src').replace(/^(.+)_on(\.[a-z]+)$/, '$1$2'));
			}).each(function(){
				$('<img>').attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_on$2'));
			});
			$('input.rollover').not('[src*="_on."]').mouseover(function(){
				$(this).attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_on$2'));
			}).mouseout(function(){
				$(this).attr('src',$(this).attr('src').replace(/^(.+)_on(\.[a-z]+)$/, '$1$2'));
			});
			$(window).unload(function(){});
	}
	var fadeover = function (){
			$('img.fadeover').not('[src*="_on."]').mouseover(function(){
				$(this).animate({opacity:0},350,"swing")
			}).mouseout(function(){
				$(this).animate({opacity:1},250,"swing")
			});
			$(window).unload(function(){});
	}
	$(function(){
			rollover();
			fadeover();
	});
})(jQuery);

