    var session_timeout = 3600*1000;
    var $dialog;
    var $sentdialog;
    var $fdialog;
    var $fsentdialog;
    var frm_name='';
    var frm_phone='';
    var frm_email='';
    var frm_text='';
    var elems_amount=9;

    function textarea_value() 
    {
      
      if ($('textarea').val()) {
        var textValue = $('textarea').val();
      }
      else {
        var textValue = $('textarea').text();
      }
      
      return textValue;
    }


    function close_sharabanner()
    {
	$('.overbanner').remove();
    }

    function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
    {
        var cookie_string = name + "=" + escape ( value );

        if ( exp_y )
        {
            var expires = new Date ( exp_y, exp_m, exp_d );
            cookie_string += "; expires=" + expires.toGMTString();
        }

        if ( path )
            cookie_string += "; path=" + escape ( path );

        if ( domain )
            cookie_string += "; domain=" + escape ( domain );
  
        if ( secure )
            cookie_string += "; secure";
  
        document.cookie = cookie_string;
    }

    function get_cookie (cookie_name)
    {
        var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

        if ( results )
            return ( unescape ( results[2] ) );
        else
            return null;
    }
     
    function timestamp()
    {
        var date_object = new Date();
        var timestamp = date_object.getTime();
        return timestamp;
    }

    function insert_banner()
    {
        var main = new SWFObject("/files/006_4.swf", "_right_top", "520", "500", "8" ); 
        main.addParam("wmode", "transparent"); 
        main.write("right_top"); 
    }

function sharabanner()
{
        var turl = window.location.toString();
        var indx = turl.indexOf('karta.htm');
        var old_timestamp_str;

//	alert(turl+' '+indx);

        if (indx >= 0)
        {
            close_sharabanner();
	    return;
        }

        old_timestamp_str = get_cookie("sharabanner");

        if(old_timestamp_str)
        {
            var old_timestamp = parseInt(old_timestamp_str, 10);
            var mseconds_elapsed = timestamp();
            mseconds_elapsed-=old_timestamp;
            if(mseconds_elapsed > session_timeout)
            {
                set_cookie("sharabanner", timestamp().toString());
                insert_banner();
            }else
            {
                close_sharabanner();
            }
        }else
        {
            set_cookie("sharabanner", timestamp().toString());
            insert_banner();
        }
}


function set_links()
{
	var elem;
	var turl = window.location.toString();
	var indx = turl.indexOf('Come_along_with_us');

	if (indx >= 0)
	{
		turl = 'http://www.nashare.in.ua/Come_along_with_us.htm';
	}

	indx = turl.indexOf('galeries.php');

	if (indx >= 0)
	{
		turl = 'http://www.nashare.in.ua/galeries.php';
	}

	
	for(var i=1; i<=elems_amount; i++) 
	{
		elem = document.getElementById('menu_item_'+i.toString());
		if(elem)
		{
			if (elem.href == turl)
			{
				elem.style['color'] = '#B52461';
			}
		}
	}
}


function hidd(){
		$("#block_img").fadeOut("slow",ch_foto);
	}


function open_sendmail(){
	$dialog.dialog('open');
	return false;
}

function open_send_feedback(){
	$fdialog.dialog("open");
}

function view_dlg(){

	$dialog = $('<div style="border: 0px solid #000; background-image: url(\'images/mailform_bg.jpg\'); background-repeat: no-repeat;"></div>')
		.html(
'<img style="position:absolute; left: 84px; top: 200px;" src="/images/fname.png">'+
'<img style="position:absolute; left: 48px; top: 240px;" src="/images/ftelefon.png">'+
'<img style="position:absolute; left: 76px; top: 275px;" src="/images/femail.png">'+
'<img style="position:absolute; left: 35px; top: 345px;" src="/images/fkommentary.png">'+
'<img style="position:absolute; left: 87px; top: 471px;" src="/images/fpolia.png">'+
'<input style="position:absolute; left:147px; top:205px; width: 200px;" type="text" id="to_send_name" ><br>'+
'<input style="position:absolute; left:147px; top:242px; width: 200px;" type="text" id="to_send_phone"><br>'+
'<input style="position:absolute; left:147px; top:278px; width: 200px;" type="text" id="to_send_email"><br>'+
'<textarea id="to_send_text" style="position:absolute; left:147px; top:317px; width: 196px; height: 80px;" ></textarea><br>'+
'<img id="sender" src="/images/btn_send.png" style="position:absolute; left:135px; top:419px; cursor: pointer;" ><br>'+
'<span id="error_message" style="position:absolute; left:25px; top:448px; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 14px; color: red; font-weight:bold;"></span>'
		)
		.dialog({
			position: "center center",
			width: "382px",
			height: "523", 
			draggable: false, 
			resizable: false,
			autoOpen: false,
			title: ''
		});
	$sentdialog = $('<div style="border: 0px solid #000; background-image: url(\'images/mailform_bg.jpg\'); background-repeat: no-repeat;"></div>')
		.html(
	'<table width="100%">'+
		'<tr height="200px"><td></td><td></td></tr>'+
		'<tr height="20px" style="margin-bottom: 20px;"><td align="center"></td></tr>'+
		'<tr height="40px" style="margin-bottom: 40px;"><td align="center" style="font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>Спасибо, ваше сообщение отправлено</b></td></tr>'+
		'<tr height="20px" style="margin-bottom: 20px;"><td align="center"></td></tr>'+
		'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>В ближайшее время мы</b></td></tr>'+
		'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>свяжемся с вами</b></td></tr>'+
		'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>для уточнения деталей</b></td></tr>'+
		'<tr height="40px" style="margin-bottom: 40px;"><td align="center"></td></tr>'+
		'<tr height="40px" style="margin-bottom: 40px;"><td align="center"><img id="senter" src="/images/btn_close.png" style="margin-left: 10px; cursor: pointer;" alt=""></td></tr>'+
	'</table>'
		)
		.dialog({
			position: "center center",
			width: "382px",
			height: "523", 
			draggable: false, 
			resizable: false,
			autoOpen: false,
			title: ''
		});


	$('#opener').click(function() {
		$dialog.dialog('open');
		return false;
	});

	$('#sender').click(function() {
		frm_email=$("#to_send_email").attr('value');
                frm_name=$("#to_send_name").attr('value');
                frm_text=$("#to_send_text").attr('value');
		frm_phone=$("#to_send_phone").attr('value');
		send_m_new();
		return false;
	});

	$('#senter').click(function() {
		$sentdialog.dialog('close');
		return false;
	});

	$fdialog = $('<div style="border: 0px solid #000; background-image: url(\'images/mailform_bg.jpg\'); background-repeat: no-repeat;"></div>')
		.html(
'<table width="100%">'+
'<tr height="200px"><td></td><td></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td width="100px" align=right><img src="images/name.png" alt=""></td><td width="200px"><input style="width: 200px; margin-left: 10px;" type="text" id="to_send_name_feedback" ></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td width="100px" align=right><img src="images/email.png" alt=""></td><td width="200px"><input style="width: 200px; margin-left: 10px;" type="text" id="to_send_email_feedback" ></td></tr>'+
'<tr height="100px" style="margin-bottom: 40px;"><td width="100px" align=right><img src="images/text.png" alt=""></td><td width="200px"><textarea id="to_send_text_feedback" style="width: 196px; margin-left: 10px; height: 80px;" ></textarea></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td width="100px" align=right></td><td width="200px"><img id="fsender" src="/images/btn_send.png" style="margin-left: 10px; cursor: pointer;" alt=""></td></tr>'+
'</table>'+
'<table width="100%">'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; color: red;"><b><label id="feedback_error_message"></label></b></td></tr>'+
'</table>'
		)
		.dialog({
			position: "center center",
			width: "382px",
			height: "523", 
			draggable: false, 
			resizable: false,
			autoOpen: false,
			title: ''
		});

	$fsentdialog = $('<div style="border: 0px solid #000; background-image: url(\'images/mailform_bg.jpg\'); background-repeat: no-repeat;"></div>')
		.html(
'<table width="100%">'+
'<tr height="200px"><td></td><td></td></tr>'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center"></td></tr>'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td align="center" style="font-family: Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>Спасибо, в ближайшее время</b></td></tr>'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center"></td></tr>'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"><b>ваш отзыв будет добавлен</b></td></tr>'+
'<tr height="20px" style="margin-bottom: 20px;"><td align="center" style="font-family: Arial,Helvetica,sans-serif; font-size: 18px; color: rgb(0, 85, 151);"></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td align="center"></td></tr>'+
'<tr height="40px" style="margin-bottom: 40px;"><td align="center"><img id="fsenter" src="/images/btn_close.png" style="margin-left: 10px; cursor: pointer;" alt=""></td></tr>'+
'</table>'
		)
		.dialog({
			position: "center center",
			width: "382px",
			height: "523", 
			draggable: false, 
			resizable: false,
			autoOpen: false,
			title: ''
		});

	$('#fsender').click(function() {
		frm_email=$("#to_send_email_feedback").attr('value');
                frm_name=$("#to_send_name_feedback").attr('value');
                frm_text=$("#to_send_text_feedback").attr('value');
		send_f();
		return false;
	});

	$('#fsenter').click(function() {
		$fsentdialog.dialog('close');
		return false;
	});

}

function close_dialog()
{
	$("#to_send_email").attr('value', '');
        $("#to_send_name").attr('value', '');
        $("#to_send_text").attr('value', '');
	$("#to_send_phone").attr('value', '');
	$("#error_message").html('');
	$dialog.dialog('close');
}

function send_m_new()
{
	$.ajax({
       type: "POST",
       url: 'ajax_send_mail_new.php',
       data: "to_send_email="+frm_email+"&to_send_name="+frm_name+"&to_send_text="+frm_text+"&to_send_phone="+frm_phone,
       success: function(data){
       	if (data == 1)
	{
		close_dialog();
		$sentdialog.dialog('open');
	}else
	{
		$("#error_message").html("Пожалуйста, заполните форму правильно");
	}
       }
       });
}


function ch_foto(){
   	if(j>dv.length-1) j=0;
   	document.getElementById('img_1').src=dv[j].src;
   	if (shs!=0){
   		$("#block_img").fadeIn("slow");
   	}
  	else shs=1;
   	j++;
   	setTimeout(hidd, 6000);
}

function close_fdialog()
{
	$("#to_send_email_feedback").attr('value','');
        $("#to_send_name_feedback").attr('value','');
        $("#to_send_text_feedback").attr('value','');
	$("#feedback_error_message").html('');
	$fdialog.dialog("close");
}

function send_f(){

	$.ajax({
       type: "POST",
       url: 'ajax_send_mail.php',
       data: "to_send_email="+frm_email+"&to_send_name="+frm_name+"&to_send_text="+frm_text+"&to_send_feedback=yes",
       success: function(data){
       	if (data == 1)
	{
		close_fdialog();
		$fsentdialog.dialog("open");
	}else
	{
		$("#feedback_error_message").html("Пожалуйста, заполните все поля полностью");
	}
       }
       });
}


function check_summ(){
	var kol;
	var city;
	var day;
	var summ;	
	
	day = $("#ch_day").attr('value');
	kol = $("#kk_p").attr('value');	
	city = $("#city").attr('value');

//	alert(city);
	
	kol = kol - 5;

	if (city != "Киев")
	{
		if (kol == 0){
			summ = 3000;
		}

		if (kol == 1){
			summ = 3500;
		}
		if (kol == 2){
			summ = 4000;
		}
		if (kol == 3){
			summ = 4500;
		}
	}else
	{
		switch(kol)
		{
			case 0:
			case 1:
				summ = 8000;
				break;
			case 2:
				summ = 10000;
				break;
			case 3:
				summ = 12000;
				break;
		}
	}
	
	$("#sum").html(summ);	
}

function _ch_day(){
	jQuery.post('ajax.php', {
        "ch_day":$("#ch_day").attr('value')
	},function(data){
		$("#kol_pipl").html(data);
		_ch_sum();
	});
}

function _ch_sum(){
	jQuery.post('ajax.php', {
        "ch_sum":$("#kk_p").attr('value')
	},function(data){
		$("#sum").html(data);
	});
}


hs.registerOverlay(
    	{
    		thumbnailId: null,
    		overlayId: 'controlbar',
    		position: 'top right',
    		hideOnMouseOut: true
		}
	);
	
    hs.graphicsDir = 'js/highslide/graphics/';
    hs.captionEval = 'this.thumb.alt';
    //hs.captionEval = 'this.thumb.title';
