function recieveFromFlash(regName) {
	$('.nav_vert li').add('.nav_vert3 li').each(function() {
		$(this).attr('id') == ("r" + regName) ? $(this).addClass("flash_over") : $(this).removeClass("flash_over");
	});	
}
function sendFromJS(regName) {
	if (window.movieName || document.movieName) {
		var movie = ($.browser.msie ? window : document)[movieName];
		movie.sendFromJS(regName);
	}
}

(function($){
	$.fn.cleanDubleSpace = function() {
		while ($(this).val().search('  ') != -1) {
			$(this).val($(this).val().replace('  ', ' '));
		}
		return this;
	}
})(jQuery);

$(function() {
//	$('a').add('img').bind('mouseup', function(event) { $(this).blur(); });
	$('#mvt_cnt img').add('#topturizm_cnt img').css('opacity','0.5').hover(function(event) { $(this).css('opacity','1'); }, function(event) { $(this).css('opacity','0.5'); });
	$('#nav li:has(ul)').hover(function(event) { $(this).children('ul').show(); }, function(event) { $(this).children('ul').hide(); });
	$('#g2 li').hover(function(event) { sendFromJS($(this).attr('id').substring(1)); }, function(event) { sendFromJS("-" + $(this).attr('id').substring(1)); });
	$('.nav_vert li').add('.nav_vert3 li').hover(
		function(event) { sendFromJS($(this).attr('id').substring(1)); },
		function(event) { sendFromJS("-" + $(this).attr('id').substring(1)); }
	);
	if ($('.div_lists').height() < ($('.div_lists').next().height())) {
		$('.div_lists').height($('.div_lists').next().height() + 5).uncorner().corner();
	} else {
		$('.div_lists').height($('.div_lists').height() + 15).uncorner().corner();
	}
	$('.cm2 div.m_fon2').next().hide();
	$('.cm_act3').parent('ul').css('display', 'block').prev().removeClass("m_fon2").addClass("m_fon1")
	$('.cm2 div').bind('click', function(event) { $(this).hasClass("m_fon1") ? $(this).removeClass("m_fon1").addClass("m_fon2").next().slideUp("fast") : $(this).removeClass("m_fon2").addClass("m_fon1").next().slideDown("fast") });
	if ($("div.scrollable").size() > 0) {
// initialize tabs
		$("ul.tabs").tabs("div.panes > div");
// initialize scrollable
		$("div.scrollable").scrollable({ size: 1 });
		var api = $("div.scrollable").data("scrollable");
		var photoSize = api.getSize();
		if (photoSize > 1) {
			$(".next").removeClass("disabled");
			$(".current span").text("[" + photoSize + " - " + (api.getIndex() + 1) + "]");
			api.onSeek(function() {
				$(".current span").text("[" + photoSize + " - " + (this.getIndex() + 1) + "]");
				var url = "/?auther=" + this.getIndex() + "&countryid=" + $(".current span").attr("id").substring(1);
				$('#introTextTd').text(" ").load(url);
			});
		}
		$(".beginPage").click( function() { api.begin(); });
		$(".endPage").click( function() { api.end(); });
	}
	$('#fb').attr('href', 'http://www.facebook.com/sharer.php?u=' + document.location.href);
	$('#contacts input[type=button]').bind('click', function(event) { sendMail(); });
});
function sendMail() {
	$('#errorMess').html("");
	var url = "index.php";
	var reg = /[0-9a-z_-]+@[0-9a-z_^.]+.[a-z]{2,3}/i;
	var errors = [];
	var gets = [];
	var a = 0;
	$('#contacts :text').add('textarea').each(function() {
		$(this).val($.trim($(this).val()));
		if ($(this).attr('name') == "email") {
			$(this).val($(this).val().toLowerCase());
			if (reg.exec($(this).val()) == null) {
				$(this).one('click', function(event) { $('#errorMess').html(""); });
				errors[a] = $(this).attr('alt');
				gets[a] = "";
			} else {
				gets[a] = $(this).val();
			}
		} else {
			if ($(this).val() == "") {
				$(this).one('click', function(event) { $('#errorMess').html(""); });
				errors[a] = $(this).attr('alt');
				gets[a] = "";
			} else {
				gets[a] = $(this).val();
			}
		}
		a++;
	});
	if (errors.length > 0) {
		if (!errors[3]) {
			var postopt = {sendmail: 1, name: gets[0], mail: gets[1], subj: gets[2], mess: gets[4], kstring: gets[3]};
			$('#errorMess').load(url, postopt, function() {
				$('#captchatxt').val("");
				$('#captchaimg').attr("src", $('#captchaimg').attr("src") + Math.floor( Math.random() * (99999 - 10000 + 1) ) + 10000);
			});
		} else {
			var errorMess = 'Ошибка при заполнении:<span style="color: red;">';
			for (i = 0; i < errors.length; i++) {
				errorMess += (!errors[i] ? "" : " " + errors[i] + ",");
			}
			errorMess = errorMess.substring(0, (errorMess.length - 1)) + ".</span>";
			$('#errorMess').html(errorMess);
		}
	} else {
		var postopt = {sendmail: 1, name: gets[0], email: gets[1], subj: gets[2], mess: gets[4], kstring: gets[3]};
		$('#errorMess').load(url, postopt, function() {
			if ($(this).text() == "Ваше сообщение доставлено.") {
				$('#contacts :text').add('textarea').each(function() {
					$(this).val("");
				});
			}
			$('#captchatxt').val("");
			$('#captchaimg').attr("src", $('#captchaimg').attr("src") + Math.floor( Math.random() * (99999 - 10000 + 1) ) + 10000);
		});
	}
}
function embedFlash(width, height, src, name, movie, imgSrc) {
	if (navigator.userAgent.match(/AppleWebKit/i) && navigator.userAgent.match(/Mobile/i)) {
		document.write('<div id="mymap"><img src="' + imgSrc + '" width="' + width +'" height="' + height + '" /></div>');
	} else {
		if (AC_FL_RunContent == 0) {
			document.write('<div id="mymap"><img src="' + imgSrc + '" width="' + width +'" height="' + height + '" /></div>');
			alert("This page requires AC_RunActiveContent.js.");
		} else {
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
				'width', width,
				'height', height,
				'src', src,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'flash',
				'bgcolor', '#ffffff',
				'name', name,
				'menu', 'true',
				'allowFullScreen', 'false',
				'allowScriptAccess','sameDomain',
				'movie', movie,
				'salign', ''
				); //end AC code
		}
	}
}

