// jQuery_Auto 0.9
// Automatic functions for webpages (using the wonderful jQuery library)

// Copyright: (c) 2006, Michal Tatarynowicz (tatarynowicz@gmail.com)
// Licenced as Public Domain (http://creativecommons.org/licenses/publicdomain/)
// $Id: jquery_auto.js 426 2006-05-06 19:54:39Z Michał $


// prototype.js use $();
// jQuery       use $();
jQuery.noConflict();
var j$ = jQuery;


// Initialization

j$.auto = {
	init: function() {
		for (module in j$.auto) {
			if (j$.auto[module].init)
				j$.auto[module].init();
		}
	}
};

j$(document).ready(j$.auto.init);


// Auto-hidden elements

// j$.auto.hide = {
//	init: function() {
//		j$('.Hide').hide();
//	}
// };

// Mouse hover

j$.auto.hover = {
//init: function() {
//	$('IMG.hover')
//		.bind('mouseover', this.enter)
//		.bind('mouseout', this.exit)
//		.each(this.preload);
//},

 init: function() {
        j$('img.rollover, .nav img, .imgOver img, input.rollover, .imgOver input')
            .bind('mouseover', this.enter)
            .bind('mouseout', this.exit)
            .bind('click', this.exit)
            .each(this.preload);
        j$('li.current img, img.current')
        .bind('mouseover', this.current)
        .bind('mouseout', this.current)
        .each( function() {
            this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_current$2");
        });
    },

	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
	},

	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
	},

	exit: function() {
		this.src = this.src.replace(/^(.+)_on(\.[a-z]+)$/, "$1$2");
	},
	
  current: function(){
    if ( this.src.indexOf("_current.") == -1 ) {;
    this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_current$2");
        }
		}
};

// pulldown superfish
j$(function(){
 j$("#gnavi").superfish().find('ul').bgIframe({opacity:false});
}); 


// Switches tabs on click

j$.auto.tabs = {

	init: function() {

		j$('.tabContainer').each(function(){
			var f = j$.auto.tabs.click;
			var group = this;
			j$('.tab li, li.tab, ul.tablogout li, ul.tablogin li, ul#bizMenu li', group).each(function(){
				this.group = group;
				j$(this).click(f);
				j$('#'+this.id+'Body').hide();
			}).filter(':first').trigger('click');
		});

	},

	click: function() {
		var tab = j$('#'+this.id+'Body').get(0);
		j$('.tab li, li.tab, ul.tablogout li, ul.tablogin li, ul#bizMenu li', this.group).each(function(){
			j$(this).removeClass('active');
			j$('#'+this.id+'Body').hide();
		});

		j$(this).addClass('active');
		j$(tab).show();
		this.blur();

		return false;
	}

};

// Smooth scroll

j$(function() {
	j$('.pageTop a, a.scroll').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = j$(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 30;
				var scldurat = 1200;
				var targetOffset = target.offset().top - sclpos;
				j$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
});



// image change

j$(document).ready( function() {
    j$(".thumbnail a").click( function() {
        var changeSrc = j$(this).attr("href");
        j$("#target").attr("src", changeSrc);
        return false;
    });
});


// list even-odd
j$(function(){
    j$("#mainCol ul#newsList > li:nth-child(even)").addClass("even");
		j$("#mainCol ul#newsList > li:nth-child(odd)").addClass("odd");
		j$('#subCol #rankingList ol li:first-child').addClass('ranktop');
    j$("ul.answerList > li:nth-child(even)").addClass("even2");
		j$("ul.answerList > li:nth-child(odd)").addClass("odd2");
    j$("ul.errresList > li:nth-child(even)").addClass("even");
		j$("ul.errresList > li:nth-child(odd)").addClass("odd");
    j$("ul.resumeNews > li:nth-child(even)").addClass("even");
		j$("ul.resumeNews > li:nth-child(odd)").addClass("odd");
    j$("ul.expBookList > li:nth-child(even)").addClass("even");
		j$("ul.expBookList > li:nth-child(odd)").addClass("odd");
		j$("table.tblCategory tr:odd").addClass("odd");
    //j$("ul.errCategoryL > li:nth-child(even)").addClass("even");
		//j$("ul.errCategoryL > li:nth-child(odd)").addClass("odd");
    //j$("ul.errCategoryR > li:nth-child(even)").addClass("even");
		//j$("ul.errCategoryR > li:nth-child(odd)").addClass("odd");
    j$("ul.errtaList > li:nth-child(even)").addClass("even");
		j$("ul.errtaList > li:nth-child(odd)").addClass("odd");
    j$("ul.kozaList > li:nth-child(even)").addClass("even");
		j$("ul.kozaList > li:nth-child(odd)").addClass("odd");
    j$("ul.tableContetns > li:nth-child(even)").addClass("even");
		j$("ul.tableContetns > li:nth-child(odd)").addClass("odd");
    j$("ul.shikakuList > li:nth-child(even)").addClass("even");
		j$("ul.shikakuList > li:nth-child(odd)").addClass("odd");
		j$('ul#subBnr li:last-child').addClass('lastChild');
		j$('#subCol dl.subColMenu dd ul li:last-child').addClass('subCollast');
		j$("#expItemList ul.expBox > li:nth-child(odd)").addClass("expodd");
		j$("ul#cartItemList > li:nth-child(odd)").addClass("cartListodd");
		j$("ul#cartComList > li:nth-child(odd)").addClass("cartComodd");
		j$('ul#delDetaMem li:last-child').addClass('lastDelDeta');
		j$("#err_subMenu ul > li:nth-child(odd)").addClass("errSubMenuodd");
		j$("ul#historyDetaList > li:nth-child(odd)").addClass("historyDetaodd");
    j$("ul#historyList > li:nth-child(even)").addClass("historyEven");
		j$("#regist ul.enqForm > li:nth-child(odd)").addClass("formOdd");
    j$("ul#infoList > li:nth-child(even)").addClass("infoListE");
		j$("ul#infoList > li:nth-child(odd)").addClass("infoListO");
    j$("#infoSubCol ul#infoSubList > li:nth-child(even)").addClass("infoSubE");
		j$("#infoSubCol ul#infoSubList > li:nth-child(odd)").addClass("infoSubO");
		j$("ul#faqList > li:nth-child(odd)").addClass("faqOdd");
    j$("ul#faqCatList > li:nth-child(even)").addClass("faqCatEven");
		j$('#rightCol #newEntry ul li:last-child').addClass('calLast');
		j$('#rightCol #subMenu ul.archiveList li:last-child').addClass('aListLast');
		j$('#entryBox .listBody dl dd:last-child').addClass('ddlistLast');
});

/** 背景画像 複数指定
 * @author Terry Wooton
 * @desc Adds a background layer to an element
 * @version 1.1
 * @example
 * $("#element").add_background("url('/test.gif') bottom left no-repeat");
 * @license free
 * @param background css
 *
 */
j$(document).ready(function() {
  j$.fn.add_layer = function(bg,params) {
    j$(this).each(function() {
  
      s = j$(this).extend({},params || {});      
      
      j$last = (j$(this).find('.add_background:last').length > 0 ? j$(this).find('.add_background:last') : j$(this));
  		j$last.html('<div class="add_background"><div>'+j$last.html()+'</div></div>');
  		j$last = j$(this).find('.add_background:last');
  		j$last.css({'background':bg,'width':'100%','height':'100%'});

      j$last = j$(this).find('.add_background div:last');
            
      if(s.insideCss){
   		  j$last.css(s.insideCss);
  		}
      if(s.insideClass)
  		  j$last.addClass(s.insideClass);  		  
    });
  }      
});

//POPUP WIDNOW
jQuery.fn.popupwindow = function(p)
{

	var profiles = p || {};

	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		
		mysettings = (jQuery(this).attr("rel") || "").split(",");

		
		settings = {
			height:670,
			width:550,
			toolbar:0,
			scrollbars:0,
			status:0,
			resizable:1,
			left:0,
			top:0,
			center:0,
			createnew:1,
			location:0,
			menubar:0
		};

		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}

		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
			window.open(this.href, name, parameters).focus();
			return false;
		});
	});

};