// work : ¹ÚÁö¿µ
(function($){
	
	var aRecentViewProductsJson = null;
	var nRecentViewProductsCurrentPage = 0;
	
	$.draw = function(obj) {
		var idx = nRecentViewProductsCurrentPage * 5;
		var rowcount = idx + 5;

		var sTypeTitle = '<h5>ÃÖ±Ùº»»óÇ°<p class="paging18"><a href="javascript:jQuery.prevPage()" class="prev02">ÀÌÀü</a><a href="javascript:jQuery.nextPage()" class="next02">´ÙÀ½</a></p></h5>';
		var sTypeNoContent = '<li>ÃÖ±Ù º» »óÇ°ÀÌ ¾ø½À´Ï´Ù.</li>';
		//var sMovePage = '<p class="paging18"><a href="javascript:jQuery.prevPage()" class="prev02">ÀÌÀü</a><a href="javascript:jQuery.nextPage()" class="next02">´ÙÀ½</a></p>';
		var sHtml = sTypeTitle;
		sHtml = sHtml + '<ul>';
		if (aRecentViewProductsJson) {
			for(idx; idx<rowcount; idx++) {
				if(!aRecentViewProductsJson[idx]) break;
				sHtml = sHtml + '<li id="recentViewProducts_'+idx+'"><a href="'+aRecentViewProductsJson[idx].linkUrl+'"><span class="thumb"><img src="'+aRecentViewProductsJson[idx].imageUrl+'" alt="'+aRecentViewProductsJson[idx].productName+'" /></span><strong>'+aRecentViewProductsJson[idx].productName+'</strong></a><p class="goods_price"><em>'+aRecentViewProductsJson[idx].minPrice+'</em>¿ø</p></li>';
			}
		} else {
			sHtml = sHtml + sTypeNoContent;
		} 
		sHtml = sHtml + '</ul>';
		obj.html(sHtml);
	};
	
	$.nextPage = function() {
		var page = nRecentViewProductsCurrentPage+1;
		if(page >= nRecentViewProductsPage) {nRecentViewProductsCurrentPage = 0;} else {nRecentViewProductsCurrentPage = page;}
		$.draw($('.last_view_goods')); 
	};
	
	$.prevPage = function() {
		var page = nRecentViewProductsCurrentPage-1;
		if(page < 0) {nRecentViewProductsCurrentPage = nRecentViewProductsPage-1;} else {nRecentViewProductsCurrentPage = page;}
		$.draw($('.last_view_goods')); 
	};
	
	$.fn.loadContentNews = function(type) {
		
		var obj = $(this);

		if ($.trim(obj.html())!='') {
			return;
		}

		var sTypeTitle = '';
		if (type=='news') {
			sTypeTitle = '<h5>ÃÖ±Ùº»´º½º</h5>';
			sTypeNoContent = '<li>ÃÖ±Ùº»´º½º°¡ ¾ø½À´Ï´Ù.</li>';
		} else if (type=='scrap') {
			sTypeTitle = '<h5>³» ½ºÅ©·¦ ±â»ç<span class="news_more_view"><a href="http://bbs.danawa.com/point/MyNewsList.php">´õº¸±â</a></span></h5>';
			sTypeNoContent = '<li>½ºÅ©·¦ ±â»ç°¡ ¾ø½À´Ï´Ù.</li>';
		}
		
		var url = 'http://news.danawa.com/News_Right_Wing.php?jsoncallback=?&sType='+type;
		var params = {format: 'json'};
		$.getJSON(url, params, function(json) {

			var sHtml = sTypeTitle;
			sHtml = sHtml + '<ul>';
			if (json) {
				$.each(json, function(i,n) {
					sHtml = sHtml + '<li><a href="'+json[i].ViewUrl+'">'+json[i].sTitle+'</a></li>';
				});
			} else {
				sHtml = sHtml + sTypeNoContent;
			}				
			sHtml = sHtml + '</ul>';
			obj.html(sHtml);
		});
	};

	$.fn.loadContentProduct = function() {
		var obj = $(this);

		if ($.trim(obj.html())!='') {
			$.draw(obj);
			return;
		}

		var url = 'http://www.danawa.com/product/todayItemViewListJson.inc.php?jsoncallback=?';
		var params = {format: 'json'};
		$.getJSON(url, params, function(json) {

			if (json) {
				aRecentViewProductsJson = eval(json);
			}
			$.draw(obj); 
		});
			
		
	};
})(jQuery);

jQuery(document).ready(function($) {

	if ($('p#first_layer').next().length == 0){
		$('p#first_layer').css({marginTop:'20px'});
	}

	if ($('.hot_vs > .vs > .hot_vs_img').length < 3 ){
		$('.hot_vs > .vs ').css({marginLeft:'20px'});
	}

	if ($('#last_layer_main').length == 0){
		$('p#first_layer_main').css({marginTop:'40px'});
	}

	$('.last_menu li:eq(1)').css({marginBottom:'-4px'});


	$("li.category a").click(function(){
		$(this).blur();
		$('#category_price').toggleClass('show');
	});
	$('#category_price').mouseenter(function(){
		$('#category_price').addClass('show');
	});
	$('#category_price').mouseleave(function(){
		$('#category_price').addClass('none');
		$('#category_price').removeClass('show');
	});



	$('.seller,#seller').mouseover(function(){
		$('#seller').css({display:'block'});
	});
	$('.seller,#seller').mouseout(function(){
		$('#seller').css({display:'none'});
		$('#area').css({display:'none'});
	});

	$('.area,#area').mouseover(function(){
		$('#area').css({display:'block'});
	});
	$('.area,#area').mouseout(function(){
		$('#area').css({display:'none'});
		$('#seller').css({display:'none'});
	});


// footer
	$('#content_guide,#indicate_onlineDigitalContent').mouseover(function(){
		$('#indicate_onlineDigitalContent').addClass('show');
	});
	$('#content_guide,#indicate_onlineDigitalContent').mouseout(function(){
		$('#indicate_onlineDigitalContent').addClass('none');
		$('#indicate_onlineDigitalContent').removeClass('show');
	});

// scroll_banner
	// ÃÖ±Ù º» »óÇ°
	$('#last_view_goods').click(function(){
		$('.last_view_goods').addClass('show');
		if ($.trim($('.last_view_goods').html())=='') {
			$('.last_view_goods').loadContentProduct();
		}
	});

	$('#last_view_goods').hover(function(){
		}, function() {
		$('.last_view_goods').removeClass('show');
	});
	$('.last_view_goods').hover(function(){
		$('.last_view_goods').addClass('show');
	}, function() {
		$('.last_view_goods').removeClass('show');
	});
	
	// ÃÖ±Ù º» ´º½º
	$('#last_view_news').click(function(){
		$('.last_view_news').addClass('show');
		if ($.trim($('.last_view_news').html())=='') {
			$('.last_view_news').loadContentNews('news');
		}
	});

	$('#last_view_news').hover(function(){
		}, function() {
		$('.last_view_news').removeClass('show');
	});
	$('.last_view_news').hover(function(){
		$('.last_view_news').addClass('show');
	}, function() {
		$('.last_view_news').removeClass('show');
	});

	// ³»½ºÅ©·¦ ±â»ç
	$('#my_scrap_news').click(function(){
		$('.my_scrap_news').css({display:'block'});
		if ($.trim($('.my_scrap_news').html())=='') {
			$('.my_scrap_news').loadContentNews('scrap');
		}
	});
	
	$('#my_scrap_news').hover(function(){
		}, function() {
		$('.my_scrap_news').css({display:'none'});
	});
	$('.my_scrap_news').hover(function(){
		$('.my_scrap_news').css({display:'block'});
	}, function() {
		$('.my_scrap_news').css({display:'none'});
	});

	/*$('.new_lnb dl,#category_open dl,.lnb_top_menu dl').hover(function(){
		$(this).css({backgroundColor:'#e5eeff'});
	}, function(){
		$(this).css({backgroundColor:'#ffffff'});
	});*/

	$('.right_tab li').hover(function(){
		if (!$(this).hasClass('over')) {
		$('.right_tab li').removeClass('over');
		$(this).addClass('over');
		$('.left_goods > div').css({display:'none'});
		$('.left_goods > div:eq(' + $('.right_tab li').index(this) + ')').css({display:'block'});
		}

		}).mouseover(function() {
		$(this).addClass('over');
		$(this).removeClass('');

		}).mouseout(function() {
		$(this).addClass('');
		//$(this).removeClass('over');
	});

	$('.accessory_tab li').hover(function(){
		if (!$(this).hasClass('over')) {
		$('.accessory_tab li').removeClass('over');
		$(this).addClass('over');
		$('.goods_list > div').css({display:'none'});
		$('.goods_list > div:eq(' + $('.accessory_tab li').index(this) + ')').css({display:'block'});
		}

		}).mouseover(function() {
		$(this).addClass('over');
		$(this).removeClass('');

		}).mouseout(function() {
		$(this).addClass('');
		//$(this).removeClass('over');
	});

	$('.navigation > ul.menu > li#menu_11').hover(function(){
		$(this).children().next().css({display:'block'});
		$('#all_up').css({display:'block'});
		$('#all_down').css({display:'none'});

	}, function() {
		$(this).children().next().css({display:'none'});
		$('#all_up').css({display:'none'});
		$('#all_down').css({display:'block'});
	});




	$('.tab_category').bind('click', function(event){
		if($('#category_all_open').css('display') == 'none'){
			$('#category_all_open').css({display:'block'});
			$('.tab_category a.open').css({display:'none'});
			$('.tab_category a.close').css({display:'block'});
		}
		else {
			$('#category_all_open').css({display:'none'});
			$('.tab_category a.open').css({display:'block'});
			$('.tab_category a.close').css({display:'none'});
		}
	 });

	 $('.btn_close').click(function(){
		$('#category_all_open').css({display:'none'});
		$('.tab_category a.open').css({display:'block'});
		$('.tab_category a.close').css({display:'none'});
	});




	$("li.more_view a").click(function(){
			$(this).blur();
			$('#more_view').toggleClass('show');
		});
		$('#more_view').mouseover(function(){
			$('#more_view').addClass('show');
		});
		$('#more_view').mouseout(function(){
			$('#more_view').addClass('none');
			$('#more_view').removeClass('show');
		});

	 $('.section_menu_open h5').bind('click', function(event){
		if($('#menu_open_layer').css('display') == 'none'){
			$('#menu_open_layer').css({display:'block'});
			$('.section_menu_open h5 a.open').css({display:'none'});
			$('.section_menu_open h5 a.close').css({display:'block'});
		}
		else {
			$('#menu_open_layer').css({display:'none'});
			$('.section_menu_open h5 a.open').css({display:'block'});
			$('.section_menu_open h5 a.close').css({display:'none'});
		}
	 });


	 $('.new_snb h5').bind('click', function(event){
		if($('#category_open').css('display') == 'none'){
			$('#category_open').css({display:'block'});
			$('.new_snb h5 a.open').css({display:'none'});
			$('.new_snb h5 a.close').css({display:'block'});
		}
		else {
			$('#category_open').css({display:'none'});
			$('.new_snb h5 a.open').css({display:'block'});
			$('.new_snb h5 a.close').css({display:'none'});
		}
	 });


	 $('.lnb_sub_category_open').bind('click', function(event){
		if($('.lnb_top_menu').css('display') == 'none'){
			$('.lnb_top_menu').css({display:'block'});
			$('.category_open_button a.open').css({display:'none'});
			$('.category_open_button a.close').css({display:'block'});
			//$('.lnb_top_menu_box').css({marginTop:'-1px'});
		}
		else {
			$('.lnb_top_menu').css({display:'none'});
			$('.category_open_button a.open').css({display:'block'});
			$('.category_open_button a.close').css({display:'none'});
			//$('.lnb_top_menu_box').css({marginTop:'5px'});
		}
		});


		$('#cateListBox').css({display:'block'});

		$('.dnw_snb h5').bind('click', function(event){
		if($('#category_open').css('display') == 'none'){
			$('#category_open').css({display:'block'});
			$('.dnw_snb h5 a.open').css({display:'none'});
			$('.dnw_snb h5 a.close').css({display:'block'});
			$('ul.pLocation > li:eq(2)').css({zIndex:'-1'});
			if ( $.browser.msie && $.browser.version.substring(0, 1) == "6" && ($('#category_open dl').length > 5))
			{
				$('#cateListBox').css({display:'none'});
			}
		}
		else {
			$('#category_open').css({display:'none'});
			$('.dnw_snb h5 a.open').css({display:'block'});
			$('.dnw_snb h5 a.close').css({display:'none'});
			$('#cateListBox').css({display:'block'});
			
		}
		});


	$('a.new_target').click(function(){

		window.open(this.href);
		return false;
	});

	$(".lnb_top_menu_box, .lnb_top_menu, .dnw_snb, #dnw_header, #IFRAME_SrchOption, #container, #content_area, #con1, #con2, #con3, #TBL_Container, table").mouseover(function(){
		$("#menu_detail").hide();
	});

	/*$("#dnw_wrap").mouseout(function(){
		//$("#menu_detail").hide();
	});*/
});


