var common = {};
with(common){
with({ my: function() { return this; } }){
with({ my: my(), ns: common }){
	my.initRollOverImages = function(){
		  var image_cache = new Object();
		  $("img.ov,input.ov").each(function(i) {
		    var imgsrc = this.src;
		    var dot = this.src.lastIndexOf('.');
		    var imgsrc_ov = this.src.substr(0, dot) + '_ov' + this.src.substr(dot, 4);
		    image_cache[this.src] = new Image();
		    image_cache[this.src].src = imgsrc_ov;
		    $(this).hover(
		      function() { this.src = imgsrc_ov; },
		      function() { this.src = imgsrc; });
		  });
	};
	
	// お気に入りに追加
	$(function(){
		if(!jQuery.support.checkOn){
			$("#ctL .btn_favorite, #ctR .btn_add_bookmark").hide();
		}else{
			ns.addBookmark = function(title,url) {
						if (window.sidebar) {
										window.sidebar.addPanel(title, url,"");
						} else if( document.all ) {
										window.external.AddFavorite( url, title);
						} else if( window.opera && window.print ) {
										return true;
						}
			};
		}
	});
	
	// モーダルを開く
	ns.openModal = function(url){
		tb_show('', url);
	};

    // タグ除去
	ns.escapeTag = function(str) {
    	str = str.replace(/&/g,"&amp;") ;
	    str = str.replace(/"/g,"&quot;") ;
	    str = str.replace(/'/g,"&#039;") ;
	    str = str.replace(/</g,"&lt;") ;
	    str = str.replace(/>/g,"&gt;") ;
	    return str ;
	};
    
	// 初期化
	ns.initPage = function(){
		my.initRollOverImages();
	};
	
}}}


// 初期化
$(function(){
	var my = common;

	// init
	my.initPage();
	
	/**
	 * event
	 */
	$(".btn_add_bookmark").unbind('click').click(function(){
		my.addBookmark('ドラクエ・パラダイス', 'http://www.dragonquest.jp/');
        return false;
    });
	// footer
    $("#shareArea a.facebook, .shareBox a.facebook, .shareArea a.facebook").bind("click", function() {
    	var url = $(this).attr('url') ? $(this).attr('url') : 'http%3A%2F%2Fwww.jp.square-enix.com%2Fcommon%2Fr%2Fshare%2Fportal_dq%2Fr_fb.html';
        window.open(
            'http://www.facebook.com/share.php?u='+url+'&t=%E3%83%89%E3%83%A9%E3%82%B4%E3%83%B3%E3%82%AF%E3%82%A8%E3%82%B9%E3%83%88%E5%85%AC%E5%BC%8F%E3%82%B5%E3%82%A4%E3%83%88',
            'winFacebook',
            'toolbar=no,status=no,location=no,directories=no,menubar=no,scrollbars=no,width=720,height=400'
        );
    });
    $("#shareArea a.mixi, .shareBox a.mixi, .shareArea a.mixi").bind("click", function() {
    	var url = $(this).attr('url') ? $(this).attr('url') : 'http://www.jp.square-enix.com/common/r/share/portal_dq/r_mx.html';
        window.open(
            'http://mixi.jp/share.pl?u='+url+'&amp;k=48914ac2f4e4cec0466f363696d284da77127a3b',
            'winmixi',
            'toolbar=no,status=no,location=yes,directories=no,menubar=no,scrollbars=no,width=720,height=400'
        );
    });
});


//popup
var childwin;
function popupWin(URL,Winname,Wwidth,Wheight){
	var WIN;
	WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
	WIN.focus();
	childwin = WIN;
}

function popupWinNoResizable(URL,Winname,Wwidth,Wheight){
	var WIN;
	WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no");
	WIN.focus();
}

function popupWinOptions(URL,Winname,Wwidth,Wheight,WOptions){
	var WIN;
	WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+"," + WOptions );
	WIN.focus();
}

function closePop(){
	window.close();
}
function openPopup(view, args){
    var popupUrl = '';
    var winName = view;
    var winWidth = 0;
    var winHeight = 0;
    
    switch(view){
    case "apply":
        popupUrl = 'https://form.square-enix.com/a.p/644/';
        winWidth = 760;
        winHeight = 600;
        winName = 'apply';
        break;
    default:
        return;
    }
    popupWin(popupUrl, winName, winWidth, winHeight);
}


// page scroll
$(function(){
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
			|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html,body')
			.animate({scrollTop: targetOffset}, 200);
			return false;
			}
		}
	});
});


//banner effect
$(function(){
	
	$(".bannerEffect img").hover(function(){
			$(this).stop(true,false).fadeTo(100,0.7);
		},function(){
			$(this).fadeTo(200,1);
		});
		
	// for IE6 bugfix
	$("#mainBnr a").hover(function(){
			$(this).children("img").stop(true,false).fadeTo(100,0.7);
		},function(){
			$(this).children("img").fadeTo(200,1);
		});

});

