﻿
function loadAlbumTab(sc_album_idx) {

	// viewLoadingImage('#album-tab-box');

	$j.post('/ajax/photo.aspx?op=get-album-tab&sc_owner_id=' + owner_id + '&sc_album_idx=' + (sc_album_idx||''), function(data) {

		$j('#album-tab-box').html(data);

	});

}

function changeAlbumTab(n) {

	$j('.tab-item-s').attr('className', 'tab-item-d');
	$j('.tab-item-on').attr('className', 'tab-item-off');
	$j('.tab-item-x1').attr('className', 'tab-item-x2');

	if (n == 'all') {
		$j('#album-tab-all').attr('className', 'tab-item-s');
	} else if (n == 'mystyle') {
		$j('#album-tab-mystyle').attr('className', 'tab-item-x1');
	} else {
		$j('#album-tab-' + n).attr('className', 'tab-item-on');
	}

}

function addAlbum() {

	var album_name = $j('#album-name').val();

	if (!album_name) {

		alert('추가할 사진첩 이름을 입력하세요');
		$j('#album-name').focus();
		return false;

	}

	var p = { 'owner_id': owner_id, 'album_name': album_name };

	closeBlindPopup();

	viewLoadingImageFull();

	$j.post('/ajax/photo.aspx?op=add-album', p, function(data) {

		var o = $j.parseJSON(data);

		if (o.result == 0) {

			closeBlindPopup();
			loadAlbumTab();

		} else if (o.result == -1) {

			alert('권한이 없습니다.');
			closeBlindPopup();

		} else if (o.result == -2) {

			alert('더이상 앨범을 추가할 수 없습니다.');
			closeBlindPopup();

		} else if (o.result == -99) {

			alert('시스템오류입니다.\r\n내용 : ' + o.ex.Message);
			closeBlindPopup();

		} else {

			alert('네트워크 장애입니다.');
			closeBlindPopup();

		}

	});

}

function modAlbum(idx) {

	var album_name = $j('#album-name').val();

	if (!album_name) {

		alert('사진첩 이름을 입력하세요');
		$j('#album-name').focus();
		return false;

	}

	var p = { 'idx': idx, 'owner_id': owner_id, 'album_name': album_name };

	closeBlindPopup();

	viewLoadingImageFull();

	$j.post('/ajax/photo.aspx?op=mod-album', p, function(data) {

		var o = $j.parseJSON(data);

		if (o.result == 0) {

			closeBlindPopup();
			loadAlbumTab();

		} else if (o.result == -1) {

			alert('권한이 없습니다.');
			closeBlindPopup();

		} else if (o.result == -99) {

			alert('시스템오류입니다.\r\n내용 : ' + o.ex.Message);
			closeBlindPopup();

		} else {

			alert('네트워크 장애입니다.');
			closeBlindPopup();

		}

	});

}

function delAlbum(idx) {

	if (!confirm('삭제된 앨범은 다시 복구하실수 없습니다.\r\n\r\n정말 삭제하시겠습니까?')) { return false; }

	$j('#html-body>.popup-list-menu').remove();

	var p = { 'owner_id': owner_id, 'idx': idx };

	closeBlindPopup();

	viewLoadingImageFull();

	$j.post('/ajax/photo.aspx?op=del-album', p, function(data) {

		var o = $j.parseJSON(data);

		if (o.result == 0) {

			closeBlindPopup();
			loadAlbumTab();

		} else if (o.result == -1) {

			alert('권한이 없습니다.');
			closeBlindPopup();

		} else if (o.result == -99) {

			alert('시스템오류입니다.\r\n내용 : ' + o.ex.Message);
			closeBlindPopup();

		} else {

			alert('네트워크 장애입니다.');
			closeBlindPopup();

		}

	});

}

function openAlbumEditLayer(idx, name) {

	$j('#mybravo').unbind('click');

	var html = '<div id="popup-list-menu-' + idx + '" class="popup-list-menu">';
	html += '<div><a href="#" onclick="delAlbum(\'' + idx + '\');return false;"><img src="/img/mybravo/btnDelPhotos.png" alt="" class="png24" /></a></div>';
	html += '<div><a href="#" onclick="openModAlbumLayer(\'' + idx + '\', \'' + name + '\');return false;"><img src="/img/mybravo/btnChangeName.png" alt="" class="png24" /></a></div>';
	html += '</div>';

	$j('#html-body>.popup-list-menu').remove();

	$j('#html-body').append(html);

	$j('#popup-list-menu-' + idx).offset({ left: $j('#btn-edit-' + idx).offset().left, top: $j('#btn-edit-' + idx).offset().top });

	window.setTimeout(function() { $j('#mybravo').bind('click', function() { $j('#html-body>.popup-list-menu').remove(); }); }, 100);

	//	if ($j('#float-menu-' + idx).css('display') == 'none') $j('#float-menu-' + idx).show();
	//	else $j('#float-menu-' + idx).hide();

}

function openAddAlbumLayer() {

	var html = '<div class="mybravo-popup-layer">';
	html += '	<div class="top"></div>';
	html += '	<div class="mid">';
	html += '		<div class="title">사진첩 이름을 입력하세요</div>';
	html += '		<div class="comment">사진첩의 이름을 직접 지정하실수 있습니다. (권장 : 12Byte)</div>';
	html += '		<div class="line"></div>';
	html += '		<div class="field"><input type="text" id="album-name" name="album-name" size="16" maxlength="12" /></div>';
	html += '		<div class="button">';
	html += '			<a href="#" onclick="addAlbum();return false;"><img src="/img/mybravo/btnPopOk.jpg" alt="확인" width="57" height="27" /></a>';
	html += '			<a href="#" onclick="closeBlindPopup();return false;"><img src="/img/mybravo/btnPopCancel.jpg" alt="취소" width="57" height="27" /></a>';
	html += '		</div>';
	html += '	</div>';
	html += '	<div class="bot"></div>';
	html += '</div>';

	$j('#html-body>.popup-list-menu').remove();

	openBlindPopup(html, false, false);

}

function openModAlbumLayer(idx, name) {

	var html = '<div class="mybravo-popup-layer">';
	html += '	<div class="top"></div>';
	html += '	<div class="mid">';
	html += '		<div class="title">사진첩 이름을 수정합니다</div>';
	html += '		<div class="comment">사진첩의 이름을 직접 지정하실수 있습니다. (권장 : 12Byte)</div>';
	html += '		<div class="line"></div>';
	html += '		<div class="field"><input type="text" id="album-name" name="album-name" value="' + name + '" size="16" maxlength="12" /></div>';
	html += '		<div class="button">';
	html += '			<a href="#" onclick="modAlbum(\'' + idx + '\');return false;"><img src="/img/mybravo/btnPopOk.jpg" alt="확인" width="57" height="27" /></a>';
	html += '			<a href="#" onclick="closeBlindPopup();return false;"><img src="/img/mybravo/btnPopCancel.jpg" alt="취소" width="57" height="27" /></a>';
	html += '		</div>';
	html += '	</div>';
	html += '	<div class="bot"></div>';
	html += '</div>';

	$j('#html-body>.popup-list-menu').remove();

	openBlindPopup(html, false, false);

}

