var submitId;

jQuery(document).ready(
function()
{
	$('#mainImage').live('mouseenter', function()
	{
		$('#leftArrow').show();
		$('#rightArrow').show();
		$('#imageTitle').show();
		
		$(this).mouseleave(function()
                {
 	            $('#leftArrow').hide();
        	    $('#rightArrow').hide();
                    $('#imageTitle').hide();
                });
	});
	
	 $("#mainGallery").easySlider({
		  auto: true,
		  controlsShow: false,
		  pause: 3000,
		  continuous: true	
		 });
	
	$('#cs_button_no').live('click', function()
	{
		$("#black_wnd").remove();
		$('#window').remove();
	});

	$('#cs_button_yes').live('click', function()
	{
		$("#black_wnd").remove();
		$('#window').remove();
		ShowDialog('window', '/templates/platonov/send_message.phtml');
	});

	$('#submit').live('click',	function()
	{
		clearInterval(submitId);
	});
	
	 
	CreateDialog('button_say', 'window', '/templates/platonov/confirm_send_message.phtml');
	CreateDialog('button_write', 'window', '?service=page&id=75');
});


function OnSubmit()
{
	if (($("#name").val().length) && 
			($("#address").val().length) &&
			($("#phone").val().length) &&
			($("#capch").val().length) &&
			($("#contentBody").val().length) &&
			($("#subject").val().length))
				$("#submit").attr('disabled', false);
		else
				$("#submit").attr('disabled', true);	
	
}


function ShowDialog(div_id, action_url)
{
	jQuery(document).ready(function()
	{
		$('<div id="'+div_id+'"><img class="dialog_close" src="templates/managekit/gfx/button_close.gif"/>' +
		'<div id="'+div_id+'_content" style="margin: 20px 30px;"></div></div><div id="black_wnd"></div>').insertBefore('#background');
		
		$.ajax({
			url: action_url,
			success: function(result){
				$('#' + div_id + '_content').html(result);
			},
			error: function(err){
				alert(err);
			}
		});
	});
			
	$(".dialog_close").live("click", function()
	{
		$("#black_wnd").remove();
		$('#'+div_id).remove();
	});
}

function CreateDialog(button_id, div_id, action_url)
{
	$('#'+button_id).live("click", function()
	{	
		$('<div id="'+div_id+'"><img class="dialog_close" src="templates/managekit/gfx/button_close.gif"/>' +
			'<div id="'+div_id+'_content" style="margin: 20px 30px;"></div></div><div id="black_wnd"></div>').insertBefore('#background');
		
		$.ajax({
			url: action_url,
			success: function(result){
				$('#' + div_id + '_content').html(result);
			},
			error: function(err){
				alert(err);
			}
		});
	});
			
	$(".dialog_close").live("click", function()
	{
		$("#black_wnd").remove();
		$('#'+div_id).remove();
	});
}

