jQuery.noConflict();
var j$ = jQuery;

j$(function() {
	/* Aside Toggle */
	j$('#aside #nav-iepco > .section').mouseover(function(){
		j$("h3",this).addClass("hover");
	});
	
	j$('#aside #nav-iepco > .section').mouseout(function(){
		j$("h3",this).removeClass("hover");
	});
	
	j$('#aside #nav-iepco > .section > .category-list > li > span').mouseover(function(){
		j$(this).addClass("hover");
	});
	
	j$('#aside #nav-iepco > .section > .category-list > li > span').mouseout(function(){
		j$(this).removeClass("hover");
	});
	
	/*j$('#aside #nav-iepco > .section > h3, #aside #nav-iepco ul.category-list > li > span').click(function(){
		j$("+ ul",this).slideToggle();
		
	});*/
	
	j$('#aside #nav-iepco > .section > h3, #aside #nav-iepco .about ul.category-list > li > span, #aside #nav-iepco .effect ul.category-list > li > span').click(function(){
		j$("+ ul",this).slideToggle();
	});
	
	/*j$('#aside #nav-iepco .field ul.category-list > li > span').click(function(){
		j$("+ ul",this).slideToggle();
		testCookie(3);
	});*/
	
	j$("#aside #nav-iepco .field > ul.category-list > li").each(function(index){
		var cat_num = index + 1;
		var show_flag = readCookie(cat_num);
		
		j$('span',this).click(function(){
			var click_flag = readCookie(cat_num);
			
			if(click_flag == 1){
				j$("+ ul",this).slideUp();
				removeCookie(cat_num);
			} else {
				j$("+ ul",this).slideDown();
				setCookie(cat_num);
			}
		});
		
		if(show_flag == 1){ j$('ul',this).show(); }
	});
	
	//removeCookieAll();
	//testCookie(3);
	
	/* init FancyZoom */
	setupZoom();
	
	/* Anchor Scroll */
	j$('a[href^=#]').click(function() {
		var href= this.hash;
		var $target = j$(href == '#_top' ? 'body' : href); 

		if($target.size()) {
			var top = $target.offset().top; 
			j$(j$.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 800, 'swing');
		}
		return false;
	});
 
	/* External Link */
	var baseUrl = "http://plastron.co.jp/";
	j$("a[href^=http://]").not("[href^="+baseUrl+"]").click(function() {
		window.open(j$(this).attr("href"));
		return false;
	});
 
	/* File Link */
	j$("a[hrefj$=.pdf], a[hrefj$=.doc], a[hrefj$=.docx], a[hrefj$=.xls], a[hrefj$=.xlsx]").click(function() {
		window.open(j$(this).attr("href"));
		return false;
	});
 
	/* Rollover */
	var conf = {
		className : "btn",
		postfix : 'o'
	};
		
	j$('.'+conf.className).each(function(){
		this.orgSrc = this.src;
		this.overSrc = this.orgSrc.replace(/(\.gif|\.jpg|\.png)/, conf.postfix+"$1");
		preloadImage(this.overSrc);
	}).hover(function(){
		this.src = this.overSrc;
	},function(){
		this.src = this.orgSrc;
	});
});

/* Preload IMG Fnc */
preloadImages = [];
var l = null;
function preloadImage(url){
	var p = preloadImages;
	var l = p.length;
	p[l] = new Image();
	p[l].src = url;
}


/* ------------------------------------

   Fnc.Cookie

   --------------------------------------- */
function readCookie(num) {
	var cookie_name = "cat_id" + num;
	return j$.cookie(cookie_name);
}

function setCookie(num) {
	var cookie_name = "cat_id" + num;
	j$.cookie(cookie_name, 1, { expires:1,path:'/' });
}

function removeCookie(num) {
	var cookie_name = "cat_id" + num;
	j$.cookie(cookie_name, '', { expires:-1,path:'/' });
}

function removeCookieAll() {
	j$.cookie('cat_id0', '', { expires:-1,path:'/' });
	j$.cookie('cat_id1', '', { expires:-1,path:'/' });
	j$.cookie('cat_id2', '', { expires:-1,path:'/' });
	j$.cookie('cat_id3', '', { expires:-1,path:'/' });
	j$.cookie('cat_id4', '', { expires:-1,path:'/' });
	j$.cookie('cat_id5', '', { expires:-1,path:'/' });
	j$.cookie('cat_id6', '', { expires:-1,path:'/' });
	j$.cookie('cat_id7', '', { expires:-1,path:'/' });
	j$.cookie('cat_id8', '', { expires:-1,path:'/' });
	j$.cookie('cat_id9', '', { expires:-1,path:'/' });
	j$.cookie('cat_id10', '', { expires:-1,path:'/' });
	j$.cookie('cat_id11', '', { expires:-1,path:'/' });
	j$.cookie('cat_id12', '', { expires:-1,path:'/' });
	j$.cookie('cat_id13', '', { expires:-1,path:'/' });
	j$.cookie('cat_id14', '', { expires:-1,path:'/' });
	j$.cookie('cat_id15', '', { expires:-1,path:'/' });
	j$.cookie('cat_id16', '', { expires:-1,path:'/' });
	j$.cookie('cat_id17', '', { expires:-1,path:'/' });
	j$.cookie('cat_id18', '', { expires:-1,path:'/' });
	j$.cookie('cat_id19', '', { expires:-1,path:'/' });
	j$.cookie('cat_id20', '', { expires:-1,path:'/' });
}

