var Num=0;
var tid=0;
var rCount=0;

$(function(){

	$('#top #nav1 img').attr("src","/common/img/navbtn1_ov.gif");
	$('#profile #nav2 img').attr("src","/common/img/navbtn2_ov.gif");
	$('#aerosol #nav3 img').attr("src","/common/img/navbtn3_ov.gif");
	$('#feature #nav4 img').attr("src","/common/img/navbtn4_ov.gif");
	$('#service #nav5 img').attr("src","/common/img/navbtn5_ov.gif");

	$('.bnav_inner li:nth-child(2n)').css("margin","0 0 0 0");

	$('#side_anime li').each(function(){
		$(this).css("opacity","0");
	});
	$('#side_anime li:first-child').css("opacity","1");
	tid=setInterval("sideAnime();",150);

});



function sideAnime(){
	if(Num < 10){
		var hideNum=Num;
		var showNum=Num+1;
		var elements=$('#side_anime ul').children();
		$(elements[hideNum]).css("opacity","0");
		$(elements[showNum]).css("opacity","1");
		Num++;
	}else if(Num == 10){
		setTimeout( function() {
			var elements=$('#side_anime ul').children();
			$(elements[10]).css("opacity","0");
			$(elements[11]).css("opacity","1");
			Num++;
		}, 1000);
		if(rCount == 1){
			clearInterval(tid);
		}
	}else if(Num == 11){
		setTimeout( function() {
			var elements=$('#side_anime ul').children();
			$(elements[11]).css("opacity","0");
			$(elements[0]).css("opacity","1");
			Num=0;
			rCount++;
		}, 3000);
	}
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
	var popup=window.open(theURL,winName,features);
	popup.focus();
}



function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	if(title == 'big'){
		$("#header_fontbox_btn1").attr("src", "/common/img/header_fontbox_btn1_1.gif");
		$("#header_fontbox_btn2").attr("src", "/common/img/header_fontbox_btn2_2.gif");
	}else if(title == 'normal'){
		$("#header_fontbox_btn1").attr("src", "/common/img/header_fontbox_btn1_2.gif");
		$("#header_fontbox_btn2").attr("src", "/common/img/header_fontbox_btn2_1.gif");
	}
	var userAgent = window.navigator.userAgent.toLowerCase();
	var appVersion = window.navigator.appVersion.toLowerCase();
//	if (userAgent.indexOf("msie") > -1) {
//		if (appVersion.indexOf("msie 6.0") > -1) {
//			if(reloadCheck != 1){
//				window.location.reload();
//				reloadCheck=1;
//			}
//		}
//	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
		) return a.getAttribute("title");
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

