function link(link){
	document.location.href = link;
	return false;
}

$(document).ready(function($){
	// alert('test');
	$('.minus , .plus').each(function(){
		//replace(this);
		$(this).click(function(){
			replace(this);
		});
	})
	add_target();
	map_link();
	big_map_link();
});

function replace(a_obj){
	//alert($(a_obj).html());
	
	answer = $(a_obj).parent().parent().find('div.answer');
	//alert(answer.html());
	if( answer.css('display') == 'none' ){
		answer.show('slow');
		$(a_obj).removeClass('plus');
		$(a_obj).addClass('minus');
	}else{
		answer.hide('slow');
		$(a_obj).removeClass('minus');
		$(a_obj).addClass('plus');
	}
}

function add_target(){
	$('a').each(function(){
		if($(this).attr('href') && ($(this).attr('href').indexOf('netcat_files/File/price') > 0 )) {
			$(this).attr('target','_blank');
		}
	})
}



function getCatalog(folders){
	$('#test').append('<div id="catalogue"></div>');
	$('#catalogue').css('display','none');

	$('#catalogue').load('http://' + document.location.host + '/prices/ajax/catalogue.php?folders=' + folders, '', function(){
	
	
	$('#catalogue').show('slow');
	imgInit();	
	});
	
}


var globalPriceCount = 0;
function getPriceBox(priceParams, number){
	$(document).ready(function($){
		globalPriceCount ++;
		$.ajax({
			type: "POST",
			url: "http://mkfasady.ru/prices/ajax/catalogue.php",
			data: 'params=' + priceParams,
			success: function(html){
				$('#pb_' + number).html(html);
			}
		});

	});
}

function getPriceBoxNew(priceParams, number){
	$(document).ready(function($){
		$.ajax({
			type: "POST",
			url: "http://mkfasady.ru/prices/ajax/catalogue.php",
			data: 'params=' + priceParams,
			success: function(html){
				$('#pb_' + number).html(html);
			}
		});

	});
}

/*
function getPriceBox(price, number){
	$(document).ready(function($){
		globalPriceCount ++;
		var html = '<h3>Цены:</h3>';
		var getParam = '';
		for(i=0; i < price.length; i++){
			var loadParams = price[i].split('@');
			
			html = html + '<p>' + loadParams[0] + ': <span class="price" id="pr' + globalPriceCount + '_' + i + '"> ... </span></p>';
			if(i==0){
				getParam = 'params=' + loadParams[0];  
			}else {
				getParam = getParam  + '@' + loadParams[0];  
			}
			
			//$('#pr' + globalPriceCount + '_' + i).load('http://mkfasady.ru/prices/ajax/catalogue.php' + getParam);
			//alert('#pr' + globalPriceCount + '_' + i);
		}
		//alert(html);
		$('#pb_' + number).html(html);
		$.ajax({
			type: "GET",
			url: "http://mkfasady.ru/prices/ajax/catalogue.php",
			data: getParam,
			success: function(msg){
				var arrayMsg = msg.split('@');
				for(i=0; i < price.length; i++){
					$('#pr' + globalPriceCount + '_' + i).html(arrayMsg[i]);
				}
			}
		});

	});
}
*/

function openPrintWindow(){
	
	NewDoc=window.open("/print/index.html", "NewWindow",   "width=800,height=800,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=yes");	
	
}

function openPrintWindowMap(){	
	NewDoc=window.open("/print/map.html", "NewWindowMap",   "width=800,height=800,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=yes");	
}

function map_link(){
	//#('').getAttr	
	$('a.map-link').each(function(){	
		//alert(text);
		$(this).hover(
		  function () {
			var top = '220';
			var id = $(this).attr('id');
			if( id == 'map-n-2' || id == 'map-n-5' || id == 'map-n-7') {
				top = '100';	
			}else if(id == 'map-n-1' || id == 'map-n-4' || id == 'map-n-9'){
			top = '100';		
			}
			var text = $('#' + 'text-' + $(this).attr('id')).html();
			$('#text-for-map-box').css('top', top + 'px').html( text ).css('display','block');  
			//alert();
		  },
		  function () {
			//$(this).removeClass("hover");
			$('#text-for-map-box').css('display','none');
		  }
		);
	});
}

function big_map_link(){
	if($('#map-big').html()) {
		if(!$('#text-for-big-map-more').html()){
			$('#main').append('<div id="text-for-big-map-more" style="display:none;"><div id="text-for-big-map-more-in"></div><div id="text-for-big-map-more-in-in"><a href="javascript:void(0);" id="map-big-close"> </a><div id="text-for-big-map-contener"></div> </div><div id="text-for-big-map-more-in-in-in"></div></div><div id="text-for-big-map-fon"></div>');
		
			$('#text-for-big-map-fon').click(function(){
				$('#text-for-big-map-more').css('display','none');
				$('#text-for-big-map-fon').css('display','none');
			});
			$('#map-big-close').click(function(){
				$('#text-for-big-map-more').css('display','none');
				$('#text-for-big-map-fon').css('display','none');
			})
		
		}
		//проход по ссылкам
		$('.text-for-big-map').each(function(){
			
			var id = $(this).attr('id');
			var more_text = $('#' + id + '-more').html();
			
			$(this).click(function(){
				$('#text-for-big-map-contener').html('').html(more_text);
				$('#text-for-big-map-more').css('display','block');
				$('#text-for-big-map-fon').css('display','block');
				
				$('#map-big').click(function(){
					//$('#text-for-big-map-more').css('display','none');
				})
				imgInit();
			});
			
		});
				
	}
}