// best, new, md 상품을 보여 준다.
// ajax Call
function tab_goods(type) {
    if (type == "new") {
        // 이미지 위치를 변경.
        $('best_tab').style.backgroundPosition = "0px -21px";
        $('new_tab').style.backgroundPosition = "-80px 0";
        $('md_tab').style.backgroundPosition = "-160px -21px";
    } else if (type == "md") {
        // 이미지 위치를 변경.
        $('best_tab').style.backgroundPosition = "0px -21px";
        $('new_tab').style.backgroundPosition = "-80px -21px";
        $('md_tab').style.backgroundPosition = "-160px 0px";
    } else {
        // 이미지 위치를 변경.
        $('best_tab').style.backgroundPosition = "0px 0px";
        $('new_tab').style.backgroundPosition = "-80px -21px";
        $('md_tab').style.backgroundPosition = "-160px -21px";
    }

	var params  = {'section_tab' : type}
	var request = WEBROOT + '/index/section_tab/';

    new Ajax.Request(request, {method: 'POST', parameters: params, onComplete: tab_goods_view});
}

// 카테고리별 상품 탭
// ajax Call
function tab_category(type) {
    switch (type) {
        case "men" :
            $('category_tab').style.backgroundPosition = "0px -32px";
            break;

        case "merchandise" :
            $('category_tab').style.backgroundPosition = "0px -64px";
            break;
        
        case "acc" :
            $('category_tab').style.backgroundPosition = "0px -96px";
            break;
        
        case "bigsize" :
            $('category_tab').style.backgroundPosition = "0px -128px";
            break;

        default :
            $('category_tab').style.backgroundPosition = "0px 0px";
            break;
    }

    // 카테고리 more 주소 값을 변경 시키기 위해 값을 변경해 준다.
    $('category_tab_more').value = type;

    var params  = {'category_tab' : type};
    var request = WEBROOT + '/index/category_tab/';

    new Ajax.Request(request, {method: 'POST', parameters: params, onComplete: tab_category_view});
}
// 카테고리별 more 버튼 url
function tab_category_more() {
    
    var type = $('category_tab_more').value;
    switch (type) {
        case "men" :
            location.href = WEBROOT + "/product/list/category_id/3/";
            break;

        case "merchandise" :
            location.href = WEBROOT + "/product/list/category_id/1/subcategory_id/29/subcategory_2nd_id/124/";
            break;

        case "acc" :
            location.href = WEBROOT + "/product/list/category_id/1/subcategory_id/27/";
            break;

        case "bigsize" :
            location.href = WEBROOT + "/product/list/category_id/1/category_option_id/17/";
            break;

        default :
            location.href = WEBROOT + "/product/list/category_id/1/";
            break;

    }
}
// 우측 Best, New, Md 추천 섹션 - ajax Response
function tab_goods_view(originalRequest) {
	var response = eval("("+originalRequest.responseText+")");

	for (var i=0; i<3; i++) {
		var none_ins = i.toString();
		$('section_goods'+none_ins).style.display = 'none';
	}

//	for (var j=0; j<response.length; j++) {
//		var ins = j.toString();
	for (var ins in response) {
		$('section_goods'+ins).style.display = 'block';
		$('section_img'+ins).src    = response[ins].goods_image;
		$('section_img'+ins).alt    = response[ins].goods_name + '의 상세보기';
		$('section_url'+ins).href   = WEBROOT + "/product/detail/id/" + response[ins].goods_id + "/";
        var section_code            = response[ins].goods_uniq_code;
        if (section_code.length > 12) {
            section_code = section_code.substring(0, 12) + "..";
        }
		$('section_code'+ins).innerHTML = section_code;
	}
}
// 메인 신상품 카테고리별 - ajax Response
function tab_category_view(originalRequest) {
    var response = eval("("+originalRequest.responseText+")");

	for (var i=0; i<24; i++) {
		var none_ins = i.toString();
		$('goods'+none_ins).style.display = 'none';
	}

	for (var ins in response) {
		$('goods'+ins).style.display        = 'block';
		$('goods_url'+ins).href             = WEBROOT + "/product/detail/id/" + response[ins].goods_id + "/";
		$('goods_img'+ins).src              = response[ins].goods_image; 
		$('goods_img'+ins).alt              = response[ins].goods_uniq_code + '의 상세보기';
		$('goods_uniq_code'+ins).innerHTML  = response[ins].goods_uniq_code;
		$('goods_img_price'+ins).innerHTML  = moneySwap(response[ins].goods_buying_point);
		$('goods_price'+ins).innerHTML      = moneySwap(response[ins].goods_supply_point);
	}
}

// 숫자 3자리 마다 콤마 처리.
// 추후 다른 곳에서도 사용 된다면 global로 옮겨 주세요 -cheong
function moneySwap(value){
    var value       = String(value);
    var value_len   = value.length;
    var return_str  = String();

    for(var i = 0; i < value_len; i++){

        if ((i%3) == 0 && i != 0) {
            return_str = value.charAt((value_len - i) -1) + "," + return_str;
        } else {
            return_str = value.charAt((value_len - i) -1) + return_str;
        }
    }

    return return_str + '원';
}

//mosaic Ajax 함수
function mosaic_tab(id) {
	var brand_select = document.getElementsByClassName('brand_select');

	for (var i=0; i<brand_select.length;i++) {
		brand_select[i].className = 'brand_no';
	}

	var url = WEBROOT + "/index/brand_mosaic/id/" + id + '/';
    new Ajax.Updater($('brand_mosaic_img'), url);

}

function change_pvd_event(position) {
    
    pvdevent_num = pvdevent_num + position;
    
    // 배열키가 마이너스가 되지 않도록 처리.
    if (pvdevent_num < 0) {
        pvdevent_num = 0;
    }
    // 배열사이즈를 넘지 않도록 처리..
    if (pvdevent_num > (pvdevent_size -3)) {
        pvdevent_num = pvdevent_size -3;
    }

    // 이벤트 갯수가 2개 이하일 경우
    var pvdevent_cnt = 3;
    if (pvdevent_size < 3) {
        pvdevent_cnt = pvdevent_size;
    }

    for (var i = 0; i < pvdevent_cnt; i++) {
        if (PVD_EVENT[pvdevent_num + i]) {
            var href    = 'pvdevent_href_' +i;
            var img     = 'pvdevent_img_' +i;

            $(href).href    = WEBROOT + "/styleshop/listbypvd/pvd_id/" + PVD_EVENT[pvdevent_num +i]['pvd_id'];
            $(img).src      = LOCAL_IMAGE_URL + "/shopimages/" + PVD_EVENT[pvdevent_num +i]['admin_id'] + "/" + PVD_EVENT[pvdevent_num +i]['event_banner_image'];
            $(img).alt      = PVD_EVENT[pvdevent_num +i]['event_title'] + "[" + PVD_EVENT[pvdevent_num +i]['event_start_date'] + "] ~ [" + PVD_EVENT[pvdevent_num +i]['event_end_date'] + "]";
        }
    }
}

