﻿// /*
// 파일명	: topGnbProduct.js
// 파일기능	: GNB영역의 TOP 상품 목록

// 수정일	: 
// 수정내용	:
// */
		function setCookie(c_name, value, expiredays) {
			var todayDate = new Date();
			todayDate.setDate(todayDate.getDate() + expiredays);
			document.cookie = c_name + "=" + escape(value) + "; expires=" + todayDate.toGMTString() + "; path=/";
		}
		function getCookie(c_name) {
			if (document.cookie.length > 0) {
				c_start = document.cookie.indexOf(c_name + "=");
				if (c_start != -1) {
					c_start = c_start + c_name.length + 1;
					c_end = document.cookie.indexOf(";", c_start);
					if (c_end == -1) c_end = document.cookie.length;
					return unescape(document.cookie.substring(c_start, c_end));
				}
			}
			return null;
		}		
		$(document).ready(function() {

			$(".avOpen").click(function() {
				clearInterval(autoTime);
				setCookie("TopAreaGnbMode", "Open", 1);
				$("#allView").removeClass("rolClass");
				if ($.browser.version == 6.0) {
					var allHeight = $("#allView ul").height() + 20;
				} else {
					var allHeight = $("#allView ul").height() + 17;
				}
				$("#allView").animate({
					height: allHeight
				}, 500, function() {
					$(".smallEvent").addClass("hide");
					$(".bigEvent").removeClass("hide");
					$(".avOpen").addClass("hide");
					$(".avClose").removeClass("hide");
					$("#allView ul li").css("background-image", "url('/images/common/allView_bar.gif')");
				});
				return false;
			});

			$(".avClose").click(function() {
				setCookie("TopAreaGnbMode", "Closed", 1);
				autoTime = setInterval($.testRolling, 3000);
				$("#allView").addClass("rolClass");
				$("#allView").animate({
					height: "34"
				}, 500, function() {
					$(".bigEvent").addClass("hide");
					$(".smallEvent").removeClass("hide");
					$(".avClose").addClass("hide");
					$(".avOpen").removeClass("hide");
					$("#allView ul li").css("background-image", "url('/images/common/allView_bar2.gif')");
				});
				return false;
			});
			$.extend({
				testRolling: function() {
					$(".rollingLi").each(function() {
						var avTxt = $(this).find(".av_txt");
						$(this).find(".av_txt span:first").slideUp(1000, function() {
							var aHtml = $(this).html();
							avTxt.append("<span class='nameGoods'>" + aHtml + "</span>");
							$(this).remove();
						});
					});
				}
			});


			$("#allView ul").hover(
				function() {
					if ($("#allView").height() == 34) clearInterval(autoTime);
				},
				function() {
					if ($("#allView").height() == 34) {
						autoTime = setInterval($.testRolling, 3000);
					}
				}
			);

			autoTimeExecute();





		});
		function autoTimeExecute() {
			var mode = getCookie("TopAreaGnbMode");
			
			if(mode == null) mode = "Open";
			if(mode =="Closed") {
				autoTime = setInterval($.testRolling, 3000);
				$("#allView").height(34) ;
				$("#allView ul li").css("background-image", "url('/images/common/allView_bar2.gif')");				
			}			
		
		}
