function show_div(id)
{
	var div;
	div = document.getElementById(id);
	if ( div.style.display == "none" ) div.style.display = "block";
		else div.style.display = "none";
}


function IEPngFix(pngimg, gifimg, width, height, repeat, scale)
{
	var code = '<img src="'+ gifimg +'" width="' + width + '" height="' + height + '" border="0" style="background:url('+pngimg+') '+repeat+' 0px 0px;"/>';
	if( navigator.userAgent.indexOf("Opera") > 1 ) document.write(code);
	else
		if( navigator.userAgent.indexOf("MSIE 6") > 1 ) document.write('<img src="'+gifimg+'" width="' + width + '" height="' + height + '" border="0" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src=' + pngimg + ' , sizingMethod='+scale+' );"/>');
		else
			if(navigator.userAgent.indexOf("MSIE 5") != -1) document.write(code);
			else document.write(code);
}




function clicks()
{
	$('.start_b_next_news').click(function(){
		n = $(this).attr('nownum');
		d = $(this).attr('nowdate');
		$.ajax({
			url: "/inc/refresh_news_block.php?action=next&nownum="+n+"&nowdate="+d,
			cache: false,
			success: update_news_block
		});
	});

	$('.start_b_prev_news').click(function(){
		n = $(this).attr('nownum');
		d = $(this).attr('nowdate');
		$.ajax({
			url: "/inc/refresh_news_block.php?action=prev&nownum="+n+"&nowdate="+d,
			cache: false,
			success: update_news_block
		});
	});


	$('.start_b_next_bill').click(function(){
		n = $(this).attr('nownum');
		d = $(this).attr('nowdate');
		$.ajax({
			url: "/inc/refresh_bill_block.php?action=next&nownum="+n+"&nowdate="+d,
			cache: false,
			success: update_bill_block
		});

/*		$('#start_afisha_block div').each(function(){
			$(this).removeClass("na");
			$("#").addClass("na");
		});*/
	});

	$('.start_b_prev_bill').click(function(){
		n = $(this).attr('nownum');
		d = $(this).attr('nowdate');
		$.ajax({
			url: "/inc/refresh_bill_block.php?action=prev&nownum="+n+"&nowdate="+d,
			cache: false,
			success: update_bill_block
		});

		
	});

}

function update_news_block(data) {
	$("#start_new_block").html(data);
	clicks();
}
function update_bill_block(data) {
	$("#start_bill_block").html(data);
	clicks();
}




$(document).ready(function(){
	clicks();

	
	$('body').pngFix( );
//	$("a.fancypopup").fancybox();
	$(".gallery-image a").lightbox();
    $.Lightbox.construct({
    	"speed": 500,
    	"show_linkback": true,
    	"keys": {
			close:	"q",
			prev:	"z",
			next:	"x"
		},
		"opacity": 0.3,
		text: {
			image:		"Картинка",
			of:			"из",
			close:		"Закрыть",
			closeInfo:	"Завершить просмотр можно, кликнув мышью вне картинки.",
			help: {
				close:		"",
				interact:	""
			},
			about: {
				text: 	"",
				title:	"",
				link:	""
			}
		},
		files: {
			images: {
				prev:		"/i/lightbox/prev.gif",
				next:		"/i/lightbox/next.gif",
				blank:		"/i/lightbox/blank.gif",
				loading:	"/i/lightbox/loading.gif"
			}
		}
    });


	
	$('#ico_home').hover(
		function(){ $(this).attr('src', '/i/ico_home1.gif'); },
		function(){ $(this).attr('src', '/i/ico_home.gif'); }
	);

	$('#ico_map').hover(
		function(){ $(this).attr('src', '/i/ico_map1.gif'); },
		function(){ $(this).attr('src', '/i/ico_map.gif'); }
	);


	
	var opts = {
				left: 6,
				top: 7,
				blur: 2,
				opacity: 0.8,
				color: '#c4c1b1',
				swap: false
			};

	$('.link_partner').each(function(){
		$(this).parent().hover(function(){
			hide_hint();
			$(this).append($('#partner_title'));
			var text = $(this).find('.metadata').html();
			$('#partner_title').empty(); 
			$('#partner_title').append(text);
			$('#partner_title').css({'display' : 'block'})
			//$('#partner_title').dropShadow(opts);
			$('.calendar_line').css({'display':'block'});
		}, function(){
			hide_hint();
		})
	})

	$('.delivery_shower').click(
		function(){
			$('#delivery_block').toggle(300);
			$('.delivery_shower a').blur();
			return false;
	});
	

});

function hide_hint(){
		$('#partner_title').removeShadow();
		$('#partner_title').css({'display' : 'none'})
}



/*              СКРИПТ ОТПРАВКИ НА МЫЛО             */

var email_url="/inc/feedback_popup.php";

var send_mes_flag = 0; 


function ask_send_form(){
	if (send_mes_flag ) return false;
	send_mes_flag  = 1;
	$('#send_mail').fadeIn(300);
}

$(document).ready(function(){
	$('.popup_handler').each(function(){
		$(this).css({'opacity':'0.95'});
		var popup_item=this;
		$('#name_send').attr('value','');
		$('#email_send').attr('value','');
		$('#text_send').attr('value','');
		$(this).find('.hide_popup').each(function(){
			$(this).css({'cursor':'pointer'});
			$(this).bind('click', function(){
				send_mes_flag = 0;
				$('#name_send').attr('value','');
				$('#email_send').attr('value','');
				$('#text_send').attr('value','');
				$(popup_item).fadeOut(300);
			})
		})
	})
});

function send_mes(){
	var name = $('#name_send').attr('value');
	var email = $('#email_send').attr('value');
	var text = $('#text_send').attr('value');
	email_url+='?name='+name+'&email='+email+'&text='+text;
	send_mail(email_url);
	email_url = '';
	$('.popup_handler').fadeOut(300);
	$('#mail_send_call').empty().append('письмо отправлено');
//	$('.mail').css({'text-decoration':'none'});
	$('#mail_send_call').css({'cursor':'default', 'color':'#c4c4c4', 'background': 'url(/i/emp.gif)'});
}

function send_mail(url){ 
		//alert(url)
		$.ajax({
			url: url,
			cache: false
		});

/*		var req=null;
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.open("GET", url, true);
			req.send(null);
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.open("GET", url, true);
				req.send();
			}
		}*/
		get_answer();
		function get_answer(){
			/*if(req.readyState==4){
				if (req.responseText!=''){
					var response = req.responseText;
				} 
			}else
				tmer=setTimeout('get_answer();', 200);*/
		}
}
