$(document).ready( function() {
    var tip_url ='';
	var info_url ='';
    var tip_src = 'http://www.gamexp.ru/img/0.gif';
    var tip_click = true;
    $('body').append('<div id="itemtip"><a id="itemtip_close" title="Закрыть" href="#"></a><a id="itemtip_info" title="Подробнее" href="#"></a><div id="item_desc_back"><div id="item_desc_back2"><div id="itemtip_p1"></div></div></div></div>');
	
    if ($.browser.msie && $.browser.version == 6) {
		$('#itemtip').css('position','absolute');
		$('#itemtip').css('top','700px');
    }
    $('*').click ( function(event) {
		event = event || window.event
		if (!tip_click) {
			if ($(this).is('#itemtip, #itemtip *')) {
				event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true);
				return true;
			} else {
				$('#itemtip').css('display','none');
				$('#itemtip_p1').html('');
				$('#itemtip_info').attr('href','#');
				tip_click = true;
				event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true);
				return false;
			}
		}
    });
    $('.show_shortprofile').click( function() {
		tip_url = $(this).attr('href');
//		info_url = $(this).prev('a').attr('href');
		info_url = $(this).parent().find('a.gamexp_name').attr('href');
		$('#itemtip_info').attr('href',info_url);
		$('#item_desc_back').css('background','url('+ajaxlink+'img/skin/loading.gif) no-repeat center 30px');
		$('#itemtip').css('display','block');
		$('#itemtip_p1').load(tip_url+'&rand='+Math.random()+' div.item_content', function() {
			$('#item_desc_back').css('background','none');
			if ($('#itemtip_p1 div.item_content').length == 0) {
				$('#itemtip_p1').html('<span class="error">Для того, что бы посмотреть информацию о другом пользователе, Вам требуется заполнить информацию о себе</span>');
			}
		});
		tip_click = false;
	return false;
    });
    $('#itemtip_close').click( function() {
		$('#itemtip').css('display','none');
		$('#itemtip_p1').html('');
		$('#itemtip_info').attr('href','#');
		tip_click = true;
		return false;
    });
});

$('.move_img').live('click', function(){	
	var img_id = $(this).attr('rel')
	data = {
		img_id: img_id,
		action: "get_album_list"
	}
	//$('#item_desc_back').css('background','url('+ajaxlink+'img/skin/loading.gif) no-repeat center 30px')
	$.ajax({
		url: "/ajax/helper.php",
		dataType: "json",
		data: data,
		success: function (res) { 
			//$('#item_desc_back').css('background','none') 
			if (typeof res == "object") { 
				html = ''
				if (res.result == "ok") { 
					option_list = new Array
					for (gallery_id in res.gallery_list) { 
						option_list.push("<option value='" + gallery_id + "'>" + res.gallery_list[gallery_id]['name'] + "</option>")
					} 
					if (option_list.length)	{ 
						html+= "Альбом:"
						html+= "<select name='new_album'>" + option_list.join("\n") + "</select>"
						html+= "<span class='move_save_button button' onClick='gc_movePhoto(" + img_id + ")'>Перенести</span>"
					} 
				} else if (res.result == 'error'){ 
					switch (res.mess) { 
						case 'album_na':
							html+= '<span class="error">Не удалось получить список альбомов, возможно у вас имеется только один альбом</span>'
							break
						default:
							html+= '<span class="error">Ошибка во время запроса списка альбомов</span>'
							break;
					}
				}
				$('span#move_img').html("<a class='delete_icon' title='Закрыть'></a><span>"+html+"</span>").show();
				
				$('.delete_icon').click(function(){
					$(this).parent().hide();
					return false
				});
						
			}
		}
	})
	tip_click = false
	
	return false
});

 

function gc_movePhoto(img_id)
{
	data = [
		  'img_id=' + img_id
		, 'action=move'
		, 'new_album=' + $('select[name=new_album] option:selected').attr('value')
	]
	if (typeof window.gc_galleryPage != 'undefined' && (window.gc_galleryPage == 'list' || window.gc_galleryPage == 'page'))
	{
		data.push('redirect=' + window.gc_galleryPage)
	}
	window.location = '/ajax/helper.php?' + data.join('&')
}
