$(document).ready(function() {
	var oClueOptions = {
							cluetipClass:	'jtip',
							width:			124,
							mouseOutClose:	true,
							dropShadow:		false,
							sticky:			true,
							showTitle:		false,
							positionBy:		'mouse',
							closeText:		'x'
	};

	if ($('.catEdit').length)
		$('.catEdit').each(function() {
			$(this).attr('rel', $('base').attr('href') + 'catalogue/editMenu/' + $(this).attr('rel'));
			$(this).cluetip(oClueOptions);
		});

	if ($('.artEdit').length)
		$('.artEdit').each(function() {
			$(this).attr('rel', $('base').attr('href') + 'articles/editMenu/' + $(this).attr('rel'));
			$(this).cluetip(oClueOptions);
		});
});

function photos(sPath) {
	var iPage = $('#photosPage').length ? $('#photosPage').val() : 1;
        	
	if ($(window).width() < 1130)
		var iPerPage = 6;
	else if ($(window).width() < 1270)
		var iPerPage = 8;
	else
		var iPerPage = 10;

	var sUrl = $('base').attr('href') + 'catalogue/photos/' + $('#noteId').val() + '/' + iPage + '/' + iPerPage;
	sUrl += sPath ? '/' + sPath : '';

	$('.small-photos').load(sUrl);
}

function search_photos(sPath) {
	var iPage = $('#photosPage').length ? $('#photosPage').val() : 1;
                             
	if ($(window).width() < 1130)
		var iPerPage = 6;
	else if ($(window).width() < 1270)
		var iPerPage = 8;
	else
		var iPerPage = 10;
	
	var sUrl = '/search/getphotos.php?url=' + $('#noteUrl').val() + '&sPath=' + sPath + '&iPerPage=' + iPerPage;

	$('.small-photos').load(sUrl);
}

function changeVid(vid, clas, producer, baseurl) 
{
	var objSel = document.getElementById("class"); 
	objSel.options.length=1;
	objSel.options[0].text = "Загрузка...";
	objSel.options[0].value = "0";
	var objSel = document.getElementById("producer"); 
	objSel.options.length=1;
	objSel.options[0].text = "Загрузка...";
	objSel.options[0].value = "0";
	var sUrl = 'http://'+baseurl+'/search/changeVid.php?vid=' + vid + '&class=' + clas + '&producer=' + producer;

	$('.selects').load(sUrl);
}

function catalogueAdmin() {
	tb_show('Заявки на продажу', $('base').attr('href') + 'catalogue/admin/?width=300&height=500');
}

function catalogueForm(iId) {
	var sUrl = $('base').attr('href') + 'catalogue/form/';
	sUrl += iId ? '/' + iId : '';
	sUrl += '/?width=500&height=500';

	tb_show('Судно', sUrl);
}

function articleForm(iId, dModified) {
	var sUrl = $('base').attr('href') + 'articles/form';
	sUrl += iId ? '/' + iId : '/0';
	sUrl += dModified ? '/' + dModified : '/0';
	sUrl += '/?width=640&height=500';

	tb_show('Статья', sUrl);
}


function articleDel(iId, dModified) {
	var sUrl = $('base').attr('href') + 'articles/del';
	sUrl += iId ? '/' + iId : '/0';

	$.ajax({
		url: sUrl,
		success: function() {
			document.location.href=document.location.href;
		}
	});
	
}

function orderForm(iId) {
	tb_show('Заказать сейчас', $('base').attr('href') + 'catalogue/orderForm/' + iId + '/?width=300&height=250');
}

function search_orderForm(url) {
	tb_show('Заказать сейчас', '/search/orderForm.php?width=300&height=250&url=' + url);	
}

function mailForm() {
	tb_show('Быстрое письмо', '/search/orderForm.php?width=300&height=250');	
}

function classesForm(id, baseurl) {
	tb_show('Классы', 'http://'+baseurl+'/search/classes.php?id='+id);
}

function brandsForm(id, baseurl) {
	tb_show('Производители', 'http://'+baseurl+'/search/brands.php?id='+id);
}

function modelsForm(id, url, baseurl) {
	tb_show('Модели', 'http://'+baseurl+'/search/models.php?id='+id+'&url='+url);
}

function catalogueArch(iId, iArch) {
	$.ajax({
		url: $('base').attr('href') + 'catalogue/arch/' + iId + '/' + iArch,
		success: function() {
			alert('В архиве');
			tb_remove();
		}
	});
}

function catalogueDel(iId) {
	if (window.confirm('Точно удаляем?'))
		$.ajax({
			url: $('base').attr('href') + 'catalogue/del/' + iId,
			success: function() {
				alert('Удалено');
				tb_remove();
			}
		});
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}