
/*メインのjs
---------------------------------------------------------------------------------------------------- */
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

if (isiPad || isiPhone) {
} else {
}


function onLoadParts(){
	initIE();
	
	//corners
	$('.news-image').corners("5px");
	$('#photobook').corners("5px");
	$('.corner').corners("5px");
	
	//
	$('.gaku, .b_brand').jrumble({
		rangeX:0,
		rangeY:5,
		rangeRot:1,
		rumbleSpeed:100
	});
	$('img.bubble').jrumble({
		rangeX:0,
		rangeY:0,
		rangeRot:5,
		rumbleSpeed:100
	});
	$('.banner').jrumble({
		rangeX:1,
		rangeY:1,
		rangeRot:1,
		rumbleSpeed:200
	});
	
	$('.b_pagetop img, .b_back img').jrumble({
		rangeX:0,
		rangeY:0,
		rangeRot:4,
		rumbleSpeed:100
	});
	
	$('.b_brand0 a, .b_brand1 a, .b_brand2 a, .b_brand3 a').jrumble({
		rangeX:0,
		rangeY:0,
		rangeRot:2,
		rumbleSpeed:100
	});
	$('.b_brand0s a, .b_brand1s a, .b_brand2s a, .b_brand3s a').jrumble({
		rangeX:0,
		rangeY:0,
		rangeRot:2,
		rumbleSpeed:100
	});
	
	//ro
	$('.fade').hover(
		function() { $(this).fadeTo(100, 0.5); $(this).fadeTo(300, 1.0); },
		function() { $(this).fadeTo(100, 0.5); $(this).fadeTo(300, 1.0); }
	);
	var image_cache = new Object();
	$('.swap').each(function(i) {
		if(!$(this).attr('imgsrc_def')) $(this).attr('imgsrc_def', this.src);
		
		$(this).attr('imgsrc', $(this).attr('imgsrc_def'));
		$(this).attr('imgsrc_off', this.src.replace("_def.", "_off.")); 
		$(this).attr('imgsrc_on', this.src.replace("_def.", "_on."));
		$(this).unbind("mouseover");
		$(this).bind("mouseover", function(e){
			this.src = $(this).attr('imgsrc_on');
		});
		$(this).unbind("mouseout");
		$(this).bind("mouseout", function(e){
			this.src = $(this).attr('imgsrc');
		});
		//
		image_cache[this.src] = new Image();
		image_cache[this.src].src = $(this).attr('imgsrc_on');
	});
	
	//btn active
	$('.act').not(".swap").each(function(i) {
		$(this).unbind("mouseover");
		$(this).unbind("mouseout");
		$(this).attr('imgsrc_on', this.src.replace("_def.", "_on.")); 
		this.src = $(this).attr('imgsrc_on');
	});
	
	$('.off').each(function(i) {
		$(this).unbind("mouseover");
		$(this).unbind("mouseout");
		$(this).attr('imgsrc_off', this.src.replace("_def.", "_off.")); 
		this.src = $(this).attr('imgsrc_off');
		$(this).parents("a").attr('href','#');
		$(this).parents("a").each(function(){
			$(this).replaceWith($(this).html());
		});
	});
	
	//
	$('.navi-bar').scrollFollow();
	
	//
	$('a:not(.scrollto, .thickbox, .popup, .pop)').each(function(){
		try {
			if($(this).attr('href').substring(0,1) == '#') return;
			if($(this).attr('href').substring(0,5) == 'index') return;
			if($(this).attr('target') == '_blank') return;
			$(this).pageswitch({
				properties:{opacity: 0},
				options:{ duration:600}
			});
		} catch(e){};
	});
	
}

function initIE(){
	//ieのみ実行
	if ($.browser.msie && $.browser.version <= 6 ) {
		
		//#followme
		$('#followme').css('position','absolute');
		
		//透過
		//DD_belatedPNG.fix('.ddpng');
		var oldFixPng = DD_belatedPNG.fixPng;
	   	DD_belatedPNG.fixPng = function (el) {
	    	oldFixPng(el);
	    	if (el.vml && el.vml.image.fill.getAttribute("src").match(/_def?./)) {
	    	    el.vml.image.shape.attachEvent('onmouseenter', function() {
	    	        var image = el.vml.image.fill;
	    	        image.setAttribute("src", image.getAttribute("src").replace("_def.", "_on."));
	    	    });
	    	    el.vml.image.shape.attachEvent('onmouseleave', function() {
	    	        var image = el.vml.image.fill;
	    	        image.setAttribute("src", image.getAttribute("src").replace("_on.", "_def."));
	    	    });
			}
		};
		DD_belatedPNG.fix('.ddpng');
	}		
}


//onload
function onLoadNavi(n){
	//
	$('#navi-inner li img').each(function(i) {
		if(i == n) {
			$(this).removeClass('swap');
			$(this).addClass('act');
		}
	});
	onLoadParts();
	//console.log(n);
	
	var h = 900;
	if (isiPad) h = 1024;
	else if (isiPhone) h = 1024;
	
	//
	if($('#contents').height() < h) {
		$('#contents').height(h);
	} else {
		$('#navi').scrollFollow();
		$('#left').height($('#main').height() - 200);
		//$('#left').height($('#footer').offset().top - 300);
	}
	
}

function onLoadLeft(n){
	onLoadNavi(-1);
}










/* 外部リンクを_blankに変更
---------------------------------------------------------------------------------------------------- */
$(function() {
	$("a[href^='http://']").attr("target","_blank");
});


/* opwin
---------------------------------------------------------------------------------------------------- */
function opwin(url, width, height, trg){
	if (!!window && url) {
		if (!trg) trg = "_blank";
		options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,favorites=no";
		var whop = "width="+width+",height="+height+","+options;
		win = window.open(url, trg, whop);
		win.focus();
	}
}

function opwin_c(url, trg, w, h, scroll) {
	var win_width = (screen.width - w) / 2;
	var win_height = (screen.height - h) / 2;
	win_detail = 'height='+h+',width='+w+',top='+win_height+',left='+win_width+',scrollbars='+scroll;
	win = window.open(url, trg, win_detail)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//<a onClick="return refreshLink(this)" href="http://www.google.com" target="_blank">
function refreshLink(url) {
	var url = el.href;
	w = window.open();
	w.document.write('<meta http-equiv="refresh" content="0;url='+url+'">');
	w.document.close();
	return false;
}


/* rollover - swapfade
----------------------------------------------------------------------------------------------------
$(function() {
  var image_cache = new Object();
  $('.swapfade').each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    $(this).hover(
      function() { $(this).fadeTo(320, 0.5); $(this).fadeTo(240, 1.0); this.src = imgsrc_on; },
      function() { $(this).fadeTo(240, 0.5); $(this).fadeTo(240, 1.0); this.src = imgsrc; });
  });
});
*/

/* rollover - swapfade
---------------------------------------------------------------------------------------------------- */
$(function() {
  var image_cache = new Object();
  $('.swapfade').each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    
    var name = "swapfade"+i;
	$(this).parent().append('<img src="'+imgsrc_on+'" class="'+name+'">');
    $(this).css("position", "absolute");
    $("."+name).css("position", "absolute");
    $("."+name).fadeTo(0, 0.0);
    $("."+name).hover(
      function() { $("."+name).fadeTo(320, 1.0);$("."+name).fadeTo(20, 0.2);$("."+name).fadeTo(100, 1.0); },
      function() { $("."+name).fadeTo(320, 0.0); });
    
  });
});


/* rollover - swap
---------------------------------------------------------------------------------------------------- */
/* プリロード無し
$(function() {
  var image_cache = new Object();
  $('.swap').each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    $(this).hover(
      function() { this.src = imgsrc_on; },
      function() { this.src = imgsrc; });
  });
});
*/
/*
$(function() {
	if (!document.getElementById) return
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className == 'swap') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
	var aImagesInput = document.getElementsByTagName('input');
	for (var i = 0; i < aImagesInput.length; i++) {
		if (aImagesInput[i].className == 'swap') {
			var src = aImagesInput[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);
			aImagesInput[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aImagesInput[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			aImagesInput[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
});
*/

/* flash - liquid
---------------------------------------------------------------------------------------------------- */

function chageHeight(h)
{
	$('#index').height(h);
}


