function is_i(){
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		return 1 }
	else {
		return 0
	}
}

$(document).ready(function(){

	Language='ru'; if ($("#sector_ua").length) { Language='ua' } else if ($("#sector_en").length) { Language='en' }

	AreaHover = ["207px", "0", "-207px", "-414px", "-621px", "-828px", "-1035px"];
	Selected = $("#sector_hover_map").attr('selected');
	if (Selected>0) $("#sector_"+Language).addClass('active');
	$("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[Selected]);
	
	$("#area_1").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[1]) });
	$("#area_2").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[2]) });
	$("#area_3").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[3]) });
	$("#area_4").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[4]) });
	$("#area_5").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[5]) });
	$("#area_6").hover(function(){ $("#sector_"+Language).addClass('active'); $("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[6]) });
	$("#sector_hover_map area").mouseout(function(){
		if (Selected<1) $("#sector_"+Language).removeClass('active');
		$("#sector_"+Language+"_hover").css('background-position','0 '+AreaHover[Selected]);
	});

	$("#lvov").hover(function(){			$("#map_hover").css('background-position','0px -822px') });
	$("#kirovograd").hover(function(){		$("#map_hover").css('background-position','0px -1233px') });
	$("#lutsk").hover(function(){			$("#map_hover").css('background-position','0px -1644px') });
	$("#zaporozhye").hover(function(){		$("#map_hover").css('background-position','0px -2055px') });
	
	$("#kiev").hover(function(){			$("#map_hover").css('background-position','-1186px -10px') });
	$("#ivanofrankovsk").hover(function(){	$("#map_hover").css('background-position','-1186px -411px') });
	$("#sumy").hover(function(){			$("#map_hover").css('background-position','-1186px -822px') });
	$("#dnepropetrovsk").hover(function(){	$("#map_hover").css('background-position','-1186px -1233px') });
	$("#rovno").hover(function(){			$("#map_hover").css('background-position','-1186px -1644px') });
	$("#herson").hover(function(){			$("#map_hover").css('background-position','-1186px -2055px') });

	$("#chernigov").hover(function(){		$("#map_hover").css('background-position','-2372px 0px') });
	$("#hmelnitsk").hover(function(){		$("#map_hover").css('background-position','-2372px -411px') });
	$("#harkov").hover(function(){			$("#map_hover").css('background-position','-2372px -822px') });
	$("#donetsk").hover(function(){			$("#map_hover").css('background-position','-2372px -1233px') });
	$("#zhitomir").hover(function(){		$("#map_hover").css('background-position','-2372px -1644px') });
	$("#krym").hover(function(){			$("#map_hover").css('background-position','-2372px -2055px') });

	$("#chernovtsy").hover(function(){		$("#map_hover").css('background-position','-3558px 0px') });
	$("#vinnitsa").hover(function(){		$("#map_hover").css('background-position','-3558px -411px') });
	$("#poltava").hover(function(){			$("#map_hover").css('background-position','-3558px -822px') });
	$("#odessa").hover(function(){			$("#map_hover").css('background-position','-3558px -1233px') });
	$("#uzhgorod").hover(function(){		$("#map_hover").css('background-position','-3558px -1644px') });
	$("#ternopol").hover(function(){		$("#map_hover").css('background-position','-3558px -2055px') });

	$("#cherkasy").hover(function(){		$("#map_hover").css('background-position','-4744px -411px') });
	$("#lugansk").hover(function(){			$("#map_hover").css('background-position','-4744px -822px') });
	$("#nikolaev").hover(function(){		$("#map_hover").css('background-position','-4744px -1233px') });

	$("#map_hover_map area").mouseout(function(){	$("#map_hover").css('background-position','0px 0px') });

	$("#kiev").click(function(){			$("#kiev_").show();			$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place kiev_'); } else { $("#map_details .region_place").css('background-position','-593px 0px');  }	   return false;	})
	$("#lvov").click(function(){			$("#lvov_").show();			$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place lvov_'); } else { $("#map_details .region_place").css('background-position','-5337px 0px'); }	   return false;	})
	$("#kirovograd").click(function(){	  	$("#kirovograd_").show();	  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place kirovograd_'); } else { $("#map_details .region_place").css('background-position','-5337px -411px'); }	 return false;	})
	$("#lutsk").click(function(){			$("#lutsk_").show();		   $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place lutsk_'); } else { $("#map_details .region_place").css('background-position','-5337px -822px'); }	 return false;	})
	$("#zaporozhye").click(function(){		$("#zaporozhye_").show();	  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place zaporozhye_'); } else { $("#map_details .region_place").css('background-position','-5337px -1233px'); }	return false;	})
	$("#ivanofrankovsk").click(function(){	$("#ivanofrankovsk_").show();  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place ivanofrankovsk_'); } else { $("#map_details .region_place").css('background-position','-593px -411px'); }	  return false;	})
	$("#sumy").click(function(){			$("#sumy_").show();			$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place sumy_'); } else { $("#map_details .region_place").css('background-position','-593px -822px'); }	  return false;	})
	$("#dnepropetrovsk").click(function(){	$("#dnepropetrovsk_").show();  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place dnepropetrovsk_'); } else { $("#map_details .region_place").css('background-position','-593px -1233px'); }	 return false;	})
	$("#rovno").click(function(){			$("#rovno_").show();		   $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place rovno_'); } else { $("#map_details .region_place").css('background-position','-593px -1644px'); }	 return false;	})
	$("#herson").click(function(){			$("#herson_").show();		  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place herson_'); } else { $("#map_details .region_place").css('background-position','-593px -2055px'); }	 return false;	})
	$("#chernigov").click(function(){		$("#chernigov_").show();	   $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place chernigov_'); } else { $("#map_details .region_place").css('background-position','-1779px 0px'); }		return false;	})
	$("#hmelnitsk").click(function(){		$("#hmelnitsk_").show();	   $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place hmelnitsk_'); } else { $("#map_details .region_place").css('background-position','-1779px -411px'); }	 return false;	})
	$("#harkov").click(function(){			$("#harkov_").show();		  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place harkov_'); } else { $("#map_details .region_place").css('background-position','-1779px -822px'); }	 return false;	})
	$("#donetsk").click(function(){			$("#donetsk_").show();		 $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place donetsk_'); } else { $("#map_details .region_place").css('background-position','-1779px -1233px'); }	return false;	})
	$("#zhitomir").click(function(){		$("#zhitomir_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place zhitomir_'); } else { $("#map_details .region_place").css('background-position','-1779px -1644px'); }	return false;	})
	$("#krym").click(function(){			$("#krym_").show();			$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place krym_'); } else { $("#map_details .region_place").css('background-position','-1779px -2055px'); }	return false;	})
	$("#chernovtsy").click(function(){		$("#chernovtsy_").show();	  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place chernovtsy_'); } else { $("#map_details .region_place").css('background-position','-2965px 0px'); }		return false;	})
	$("#vinnitsa").click(function(){		$("#vinnitsa_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place vinnitsa_'); } else { $("#map_details .region_place").css('background-position','-2965px -411px'); }	 return false;	})
	$("#poltava").click(function(){		  $("#poltava_").show();		 $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place poltava_'); } else { $("#map_details .region_place").css('background-position','-2965px -822px'); }	 return false;	})
	$("#odessa").click(function(){		   $("#odessa_").show();		  $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place odessa_'); } else { $("#map_details .region_place").css('background-position','-2965px -1233px'); }	return false;	})
	$("#uzhgorod").click(function(){		 $("#uzhgorod_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place uzhgorod_'); } else { $("#map_details .region_place").css('background-position','-2965px -1644px'); }	return false;	})
	$("#ternopol").click(function(){		 $("#ternopol_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place ternopol_'); } else { $("#map_details .region_place").css('background-position','-2965px -2055px'); }	return false;	})
	$("#cherkasy").click(function(){		 $("#cherkasy_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place cherkasy_'); } else { $("#map_details .region_place").css('background-position','-4151px -411px'); }	 return false;	})
	$("#lugansk").click(function(){		  $("#lugansk_").show();		 $("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place lugansk_'); } else { $("#map_details .region_place").css('background-position','-4151px -822px'); }	 return false;	})
	$("#nikolaev").click(function(){		 $("#nikolaev_").show();		$("#map_details").fadeIn('slow');  if (is_i()) { $("#map_details .region_place").removeClass().addClass('region_place nikolaev_'); } else { $("#map_details .region_place").css('background-position','-4151px -1233px'); }	return false;	})

	$("#map_details a.close").click(function(){ $("#map_details").fadeOut('slow'); $(".region_details").hide(); return false;   })
	
	$("#portfolio .next").click(function(){
		$("#portfolio").find(".item.active").fadeOut('slow',function(){
			if($(this).next().html()){
				$(this).next().fadeIn('slow').addClass("active");
			} else {
				$("#portfolio").find(".item").first().fadeIn('slow').addClass("active")
			}
		}).removeClass("active");
		return false;
	});

	$("#portfolio .previous").click(function(){
		$("#portfolio").find(".item.active").fadeOut('slow',function(){
			if($(this).prev().html()){
				$(this).prev().fadeIn('slow').addClass("active");
			} else {
				$("#portfolio").find(".item").last().fadeIn('slow').addClass("active")
			}
		}).removeClass("active");
		return false;
	});

	setInterval(function(){
		$("#our_clients").find(".item.active").fadeOut('slow',function(){
			if($(this).next().html()){
				$(this).next().fadeIn('slow').addClass("active");
			} else {
				$("#our_clients").find(".item").first().fadeIn('slow').addClass("active")
			}
		}).removeClass("active");
	},5000);

	$("#CmsQuotation").editorPlugin();
	$("#CmsSlogan").editorPlugin();
	$("#CmsContent").editorPlugin();
	$("#SiteServices").editorPlugin();
	$("#SiteClients").editorPlugin();

	$("#CmsSave").live('click', function(event) {
		$("#content").fadeOut();
		var CmsMenuId      = $("#CmsMenuId"      ).val(),
			CmsLanguageId  = $("#CmsLanguageId"  ).val(),
			CmsMenuCaption = $("#CmsMenuCaption" ).val(),
			CmsPerson      = $("#CmsPerson"      ).val(),
			CmsPosition    = $("#CmsPosition"    ).val(),
			CmsQuotation   = markupToHtml($("#CmsQuotation .content").val()),
			CmsSlogan      = markupToHtml($("#CmsSlogan .content").val()),
			CmsPhoto       = $("#CmsPhoto"       ).val(),
			CmsTitle       = $("#CmsTitle"       ).val(),
			CmsDescription = $("#CmsDescription" ).val(),
			CmsKeywords    = $("#CmsKeywords"    ).val(),
			CmsPriority    = $("#CmsPriority"    ).val(),
			CmsContent     = markupToHtml($("#CmsContent .content").val());
		$.post("/cms/save.json", {
			"CmsMenuId":      CmsMenuId,
			"CmsLanguageId":  CmsLanguageId,
			"CmsMenuCaption": CmsMenuCaption,
			"CmsPerson":      CmsPerson,
			"CmsPosition":    CmsPosition,
			"CmsQuotation":   CmsQuotation,
			"CmsSlogan":      CmsSlogan,
			"CmsPhoto":       CmsPhoto,
			"CmsTitle":       CmsTitle,
			"CmsDescription": CmsDescription,
			"CmsKeywords":    CmsKeywords,
			"CmsPriority":    CmsPriority,
			"CmsContent":     CmsContent
		}, function(data) {
			$("#content").fadeIn();
			if (data.res=='error') {
				alert('Error saving page content. Do not close window and try again later!');
			} else {
				//window.location.reload(true);
				//window.location = '/setup';
			}
		}, "json");
		return false;
	});

	$("#NewsSave").live('click', function(event) {
		$("#content").fadeOut();
		var CmsNewsId   = $("#CmsNewsId"  ).val(),
			CmsCaption  = $("#CmsCaption" ).val(),
			CmsPubDate  = $("#CmsPubDate" ).val(),
			CmsImage    = $("#CmsImage"   ).val(),
			CmsLanguage = $("#CmsLanguage").val(),
			CmsContent  = markupToHtml($("#CmsContent .content").val());
		$.post("/news/save.json", {
			"CmsNewsId":   CmsNewsId,
			"CmsCaption":  CmsCaption,
			"CmsPubDate":  CmsPubDate,
			"CmsImage":    CmsImage,
			"CmsLanguage": CmsLanguage,
			"CmsContent":  CmsContent
		}, function(data) {
			$("#content").fadeIn();
			if (data.res=='error') {
				alert('Error saving page content. Do not close window and try again later!');
			}
		}, "json");
		return false;
	});

	$("#NewsDelete").live('click', function(event) {
		$("#content").fadeOut();
		var CmsNewsId  = $("#CmsNewsId"  ).val();
		$.post("/news/delete.json", { "CmsNewsId": CmsNewsId }, function(data) {
			$("#content").append('deleted');
			if (data.res=='error') alert('Error saving page content. Do not close window and try again later!');
		}, "json");
		return false;
	});

	$("#ServicesSave").live('click', function(event) {
		$("#content").fadeOut();
		var SiteServices = markupToHtml($("#SiteServices .content").val());
		var LangServices = $("#Language").val();
		$.post("/services/save.json",
			{
				"SiteServices": SiteServices,
				"Language": LangServices
			}, function(data) {
				$("#content").fadeIn();
				if (data.res=='error') alert('Error saving page content. Do not close window and try again later!');
			}, "json"
		);
		return false;
	});

	$("#ClientsSave").live('click', function(event) {
		$("#content").fadeOut();
		var SiteClients = markupToHtml($("#SiteClients .content").val());
		$.post("/clients/save.json", { "SiteClients": SiteClients }, function(data) {
			$("#content").fadeIn();
			if (data.res=='error') alert('Error saving page content. Do not close window and try again later!');
		}, "json");
		return false;
	});

	$('#imageup').uploadify({
  		//'uploader'  : '/js/uploadify.swf',
		'uploader'  : '/js/uploadify/uploadify.swf',
		'script'    : '/uploadify',
		'cancelImg' : '/js/uploadify/cancel.png',
		//'hideButton': true,
		'height'    : 30,
		'folder'    : '',
		'auto'      : true,
		'multi'     : true,
		//'buttonImg' : " ",
		'wmode'     : "transparent",
		'fileExt'   : '*.gif;*.png;*.jpg',
		'fileDesc'  : "Images",
		'sizeLimit' : '2621440',
		'onError' : function (event, queueID, fileObj, errorObj ) {
			if(fileObj.size > 2621440) alert('Файл должен быть не более 2,6 Мб');
		},
		'onSelectOnce' : function(event, 	data) {
			$("#uploadifyButton").hide();
		},
		'onComplete' : function(event, queueID, fileObj, response, data) {
			$('#uploadify').append('<input style="width:400px;" type="text" value="http://static.grouprost.com/i/'+fileObj.name+'" /><br/>');
		},
		'onAllComplete' : function(event, queueID, fileObj, response, data) {
			$("#uploadifyButton").show();
			//$('#uploadify').html(responce); //'/i/'+imgs[0].name
		}
	});

	$("#content_place .item").hover(function() {
		var text = $("div.text",this);
		text.stop(true,true).animate({backgroundPosition: '0 0', 'padding-left': '300px' }, 1500);
	},function() {
		var text = $("div.text",this);
		text.stop(true,true).animate({backgroundPosition: '-299px 0', 'padding-left': '0' }, 1500);
	});

});
