var u2knowCount = 7;
var countLiU2know = 0;//$("li", "#un2know").length;
var currentRotaitionElementId = 0;
var mainPageInterval = null;

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

	function standvalue(group){
		group.each(function() {
			text = $(this).attr("title");
			$(this).attr("value",text);
		});
		group.one("click", function(){
			$(this).attr("value","");
		});
		group.one("keypress", function() {
			$(this).css("color","black");
		});
	}
	
	function clickGalleryTop(nId){
		setGalleryActive(nId);
		stopGallery($(".stop"));
	}
	
	function setGalleryActive(nId){
		currentRotaitionElementId = nId;
		var obj = $("a", $("#gallery_top_"+nId));
		var container = $(obj).parent().parent().parent();
		$(".active", container).removeClass();
		$(obj).parent().parent().addClass("active");
		
		var newObj = $("#main_gallery_top_"+nId, $("#main_gallery_top"));
		var oldObj = $(".first", $("#main_gallery_top"));
		
		newObj.addClass("first");
		newObj.animate({ opacity: 1.0 }, 1000 , function(){
			//$(this).addClass("first");
		});
		if (oldObj.attr("id") != "main_gallery_top_"+nId)
			oldObj.animate({ opacity: 0.0 }, 1000 , function(){
			$(this).removeClass("first");
			//$(this).css("opacity", "100");
			//$("#main_gallery_top_"+nId, $("#main_gallery_top")).addClass("first");
		});
	}
	
	function stopGallery(obj){
		$(".gallery-list .jcarousel-next").stopTime('timer1');
		$(obj).addClass("disable");
	}
	
	function startGallery(){
		$(".jcarousel-next").unbind();
		
		setInterval(function(){
			$("li", $("#un2know")).each(function(){
				if ($(this).html()==null || $(this).html()==""){
					$(this).remove();
				}
			});
			if ($(".active", "#un2know").length==0){
				$("#gallery_top_"+currentRotaitionElementId).addClass("active");
			}
		}, 100);
		
		$(".gallery-list .jcarousel-next").everyTime(6000, 'timer1', function() {
			var id = $(".active", "#un2know").attr("id");
			//$(this).click();
			var newId = $(".active", "#un2know").attr("id");
			var nId = parseInt(newId.replace("gallery_top_", ""));
			if (id == newId && countLiU2know > nId){
				nId++;
			} else if (id == newId && countLiU2know == nId){
				nId = 1;
			}
			//if (countLiU2know < u2knowCount){
			setGalleryActive(nId);
			//}
		});
	}
		
		
	var lengthGalery = 0;
	var currentPosGalery = 0;
	var imgSizeArray = new Array();
	function resizeGalery(){
		var heightContent = $('#content_galery').height(); 
		var widthContent = $('#content_galery').width();
		var heightImage = $('#active_galery img').height();
		var widthImage = $('#active_galery img').width();
		
		var maxWidth = 0;
		var maxHeight = 0;
		
		if (typeof(imgSizeArray[$('#active_galery img').attr("src")])=="undefined"){
			maxWidth  = widthImage;
			maxHeight = heightImage;
			imgSizeArray[$('#active_galery img').attr("src")] = new Array();
			imgSizeArray[$('#active_galery img').attr("src")]["height"] = maxHeight;
			imgSizeArray[$('#active_galery img').attr("src")]["width"] = maxWidth;
		} else {
			maxHeight = imgSizeArray[$('#active_galery img').attr("src")]["height"];
			maxWidth  = imgSizeArray[$('#active_galery img').attr("src")]["width"];
		}
		
		var contentChast = widthContent/heightContent;
		var imageChast = widthImage/heightImage;
		
		$('#active_galery img').css('height', 'auto');
		$('#active_galery img').css('width', 'auto');
		
		$('#active_galery img').css('max-height', maxHeight + 'px !important');
		$('#active_galery img').css('max-width', maxWidth + 'px !important');
		
		if (contentChast > imageChast){
			$('#active_galery img').css('height', heightContent+'px');
		}else {
			$('#active_galery img').css('width', widthContent+'px');
		}
		
		var paddingTop = (heightContent - $('#active_galery img').height())/2;
		
		$('#active_galery img').css('margin-top', paddingTop + 'px');
		
		var paddingTopArrows = ($(window).height() - ($('#reklama_galery').height() + 40))/2;
		$('#left_arrow_galery').css('top', paddingTopArrows+'px');
		$('#right_arrow_galery').css('top', paddingTopArrows+'px');
		
		$('#info_block').css('bottom', heightContent-paddingTop-$('#active_galery img').height()+'px');
		$('#count_block').css('bottom', (heightContent-paddingTop-$('#active_galery img').height() - 21)+'px');
		$('#info_block').css('left', ((widthContent-$('#active_galery img').width())/2)+'px');
		$('#info_block').css('width', $('#active_galery img').width()+'px');
		$('#count_block').css('width', $('#active_galery img').width()+'px');
		$('#count_block').css('left', ((widthContent - $('#count_block').width())/2) + 'px');
	};
	function showNewGalery(delta){
		
		currentPosGalery += delta;
		var newHref = $($('.box_img').get(currentPosGalery)).attr('href');
		var text = $('.reklama', $($('.box_img').get(currentPosGalery)).parent()).text();
		text = text==null?"":text;
		if (delta != 0){
			$('#active_galery img').animate({
		        opacity: 0.0
		      }, 500 );
		}
			
		$('#content_galery').html('<div style="text-align: center; width: 100%; height: 100%; display: none;" id="active_galery"><img src="'+newHref+'" /></div>');
		$('body').append('<div id="ajax_loader" style="top: 0px; bottom: 0px; left: 0px; right: 0px; z-index: 10000; position: fixed;"><img style="margin-top: 50%" src="/extentions/images/ajax-loader.gif" /></div>')
		
		var w_img = 220;//$('#ajax_loader img').width();
		var margin_left_w_img = ($(window).width() - w_img)/2;
		
		var h_img = 19;//$('#ajax_loader img').height();
		var margin_top_h_img = ($(window).height() - h_img)/2;
		
		$('#ajax_loader img').css('margin-left', margin_left_w_img + 'px');
		$('#ajax_loader img').css('margin-top', margin_top_h_img + 'px');
		
		$('#active_galery img').imagesLoaded(function(img) {
			$('#ajax_loader').remove();
			$('#active_galery').append('<div id="info_block" style="position: absolute; display: none;" ></div>');
			$('#active_galery').append('<div id="count_block">'+(currentPosGalery+1)+'/'+lengthGalery+'</div>');
			if (text != ""){
				$('#info_block').append('<div id="info_img"></div>');
				$('#info_block').append('<div id="info_text" class="shadow_container">'+text+'</div>');
			}
			$('#info_text').css('opacity', '0.0');
			
			$('#active_galery img').css('opacity', '0.0');
			$('#active_galery').show();
		
			resizeGalery();
			
			$('#active_galery img').animate({
		        opacity: 1.0
		      }, 500 );
			
			$('#info_block').show();
			
			$('#left_arrow_galery').show();
			$('#right_arrow_galery').show();
			
			if ($('.box_img').length == 1){
				$('#right_arrow_galery').hide();
				$('#left_arrow_galery').hide();
			} else if(lengthGalery == (currentPosGalery+1)){
				// не показывать правую стрелку
				$('#right_arrow_galery').hide();
			} else if(currentPosGalery == 0){
				// не показывать левую стрелку
				$('#left_arrow_galery').hide();
			} else {
				$('#left_arrow_galery').show();
				$('#right_arrow_galery').show();
			}
			if (text != "")
			$('#info_block').hover(
				function(){
					$('#info_img').animate({
				        opacity: 0.0
				     }, 500 );
					$('#info_text').animate({
				        opacity: 1.0
				     }, 500 );
				},
				function(){
					$('#info_img').animate({
				        opacity: 1.0
				     }, 500 );
					$('#info_text').animate({
				        opacity: 0.0
				     }, 500 );
				}
			);
			
			$(window).resize(function(){
				resizeGalery();
			});
		});
	};	
	
	function closeNewGalery(){
		$('body').css('overflow', 'auto');
		
		$('#overlay_galery').hide();
		$('#content_galery').hide();
		$('#left_arrow_galery').hide();
		$('#right_arrow_galery').hide();
		$('#close_galery').hide();
		$('#reklama_galery').hide();
		
		$('#ajax_loader').remove();
	};
	
$(document).ready(function(){
	
	$('.box_img').click(function(){
		var currentHref = $(this).attr('href');
		lengthGalery = $('.box_img').length;
		$('.box_img').each(function(i){
			if (currentHref == $(this).attr('href'))
				currentPosGalery = i;
		});
		
		$('#overlay_galery').css('opacity', '0.9');
		$('body').css('overflow', 'hidden');
		
		$('#overlay_galery').show();
		$('#content_galery').show();
		$('#left_arrow_galery').show();
		$('#right_arrow_galery').show();
		$('#close_galery').show();
		$('#reklama_galery').show();
		
		showNewGalery(0);
		return false;
	});
	
	
	countLiU2know = $("li", "#un2know").length;
	visible_elem=Math.round(($(".main-block").width()-($(".main-block").width()%220))/220);
	$('.no-rotate').jcarousel({
        scroll: 1,
		visible:visible_elem
    });
	
	$('.rotate').each ( function() {
		len = $(this).find("li").length;
		wdt = $(this).find("li").width();
		visible_elem=Math.round(($(this).closest(".gallery-list").width()-($(this).closest(".gallery-list").width()%110))/110);
		if( $(this).closest("div").width()<(len *wdt))
		{
			$(this).jcarousel({
			scroll: 4,
			wrap: 'null',
			visible:visible_elem
			});
		}
		else
		{
			$(this).wrap("<div class='jcarousel-skin-ayntk'><div class='jcarousel-container jcarousel-container-horizontal'><div class='jcarousel-clip jcarousel-clip-horizontal'></div></div></div>");
		}
	});
	
	

	$('.news_block_gal').each ( function() {
		function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
			$("#fist_idx").text(idx);
			$('.news_block_gal').find(".active").removeClass("active");
			$('.news_block_gal').find("li:eq("+(idx-1)+")").addClass("active");
		};
		function mycarousel_itemLastInCallback(carousel, item, idx, state) {
			$("#last_idx").text(idx);
		};
		var visible_elem=Math.round(($(this).closest(".gallery-list").width()-($(this).closest(".gallery-list").width()%165))/165);
		if ($(this).attr("id") == "un2know")
			visible_elem = u2knowCount;
		$(this).jcarousel({
			scroll: 1,
			wrap: 'last',
			visible:visible_elem,
			itemFirstInCallback:  mycarousel_itemFirstInCallback,
			itemLastInCallback:   mycarousel_itemLastInCallback
		});
		
		startGallery();
		
		$(".gallery-list .jcarousel-next").click(function(){
			stopGallery($(".stop"));
			var id = $(".active", "#un2know").attr("id");
			var nId = parseInt(id.replace("gallery_top_", ""));
			if (countLiU2know > nId){
				nId++;
			} else if (countLiU2know == nId){
				nId = 1;
			}
			setGalleryActive(nId);
		});
		
		$(".gallery-list .jcarousel-prev").click(function(){
			stopGallery($(".stop"));
			var id = $(".active", "#un2know").attr("id");
			var nId = parseInt(id.replace("gallery_top_", ""));
			if (nId > 1){
				nId--;
			} else{
				nId = countLiU2know;
			}
			setGalleryActive(nId);
		});
		
		$(".stop").click(function(){
			if ($(this).is('.disable')){
				startGallery();
				$(this).removeClass("disable");
			} else {
				stopGallery(this);
				$(this).addClass("disable");
			}
		});
		
	});
	visible_elem=Math.round(($(".main-block").width()-($(".main-block").width()%147))/147);
	$(".my_no_rotate_b ul").jcarousel({
        scroll: 1,
		wrap: 'circular',
		visible:5
    });
	
	
	$('.mini-gallery ul').jcarousel({
        scroll: 1,
		wrap: 'circular',
		visible:3
    });

	var params = {
		changedEl: ".sub-block select",
		visRows: 10,
		scrollArrows: true
	};
	cuSel( params );
	
	var params = {
		changedEl: "select.common-cusel",
		visRows: 10,
		scrollArrows: true
	};
	cuSel( params );
	
	var params = {
		changedEl: "#language",
		visRows: 5,
		scrollArrows: true
	};
	cuSel( params );
	
	setTimeout(function(){
		 var minWidth = 0;
		 $(".cusel").each(function(){
			 if (minWidth < $(this).width())
				 minWidth = $(this).width();
		 });
		 $(".cusel").width(minWidth);
	 }, 10);

	/* Континенты на странице путешествий */
	$('.continents .map').mousemove(function(e){
		var imgH = parseInt( $(this).children('img').css('height') );
		var offset = $(this).offset();
		var relativeX = ( e.pageX - offset.left ) ;
		var relativeY = ( e.pageY - offset.top );
		$(this).children('span').css({'left':relativeX+'px','top':relativeY+'px'});
	})
	$(".photo-change .back a,.photo-change .forward a").hide();
	$(".continents li").find(".img_dfg img").hover( function(){
			$(this).closest("li").css({"z-index":"99"});
			$(this).closest("li").find(".map").find("span").show();
		},
		function(){
			$(this).closest("li").css({"z-index":"10"});
			$(this).closest("li").find(".map").find("span").hide();
		}
	)
	$(".photo-change .back,.photo-change .forward").hover( 
		function (){
			$(this).find("a").fadeIn(600).css("display:inline;");
		},
		function (){
			$(this).find("a").fadeOut(600).css("display:inline;");
		}
	);
		
	$(".cont_elem").hide();
	
	if ($('#accordion_img').length)
	{
		$('.photo_info').hide();
		containerWidth_m = $(".accordion_cont").width();
		   $('#accordion_img').liteAccordion({
			  containerWidth : containerWidth_m,
				containerHeight : 300,
				slideSpeed : 600,
				headerWidth: 72,
				firstSlide : 1 ,
				onActivate : function() {
					$('.photo_info').fadeOut();
				},
				slideCallback : function() {   
					this.find('.photo_info').fadeIn();
				}
		   }).find('.photo_info:first').show();
	}
	
	if ($('#popular-downloads').length)
	{
		$('.photo_info').hide();
		containerWidth_m = $(".accordion_cont").width();
		   $('#popular-downloads').liteAccordion({
			  containerWidth : containerWidth_m,
				containerHeight : 308,
				slideSpeed : 600,
				headerWidth: 34,
				firstSlide : 1 ,
				onActivate : function() {
				},
				slideCallback : function() {   
					
				}
		   }).find('.photo_info:first').show();
	}
	
	function clickMainMenuNextFoto(obj){
		var prevObj = $(".photo-change_div .photo").find(".current").prev();
		prevObj = prevObj.html()==null?$($(".photo .elem").get(($(".photo .elem").length)-1)):prevObj;
		
		var nextObj = $(".photo-change_div .photo").find(".current").next();
		nextObj = nextObj.html()==null?$($(".photo .elem").get(0)):nextObj;
		
		var container = $(obj).parent();
		var nextText = $(".main-header-content .photo-desc h1", nextObj).html();
		var prevText = $(".main-header-content .photo-desc h1", prevObj).html();
		$("a span", $(".back", container)).html(prevText);
		$("a span", $(".forward", container)).html(nextText);
	}
	
	function goToPhoto(delta){
		var imgLength = $(".photo-change_div .elem").length;
		var currentElement = $(".photo-change_div .photo").find(".current");
		var currentImgIndex = currentElement.index();
		var nextElementId = currentImgIndex + delta;
		if (delta > 0){
			nextElementId = nextElementId>(imgLength-1)?0:nextElementId;
		} else {
			nextElementId = nextElementId<0?(imgLength-1):nextElementId;
		}
		
		var nextElement = $($(".photo-change_div .elem").get(nextElementId));
		
		$(".photo-change_div .photo").find(".elem").css({ opacity: "0.0" });
		currentElement.css({ opacity: "1.0" });
		
		currentElement.animate({ opacity: "0.0" }, 1000);
		nextElement.animate({ opacity: "1.0" }, 1000);
		
		currentElement.removeClass("current");
		nextElement.addClass("current");
		/*
		clearInterval(mainPageInterval);
		mainPageInterval = setInterval(function(){
			$(".photo-change .forward").click();
		}, 10000);
		*/
	}
	
	if ($(".photo-change_div").length)
	{
		elem_width = $(".photo-change_div").width();
		$(".main-header-content").width(elem_width);
		$(".photo .main-header-content").hide();
		$(".photo .elem").hover(
			function(){
				$(this).find(".main-header-content").fadeIn(300);
			},
			function(){
				$(this).find(".main-header-content").fadeOut(300);
			}
		);
		$(".forward").click( function(){
			goToPhoto(1);
			clickMainMenuNextFoto(this);
		});
		$(".back").click( function(){
			goToPhoto(-1);
			clickMainMenuNextFoto(this);
		});
		$("#photo-rotate li").click( function () {
			var currentIndex = $(".photo-change_div .photo").find(".current").index()
			var newIndex = $(this).index(); 
			if (currentIndex == newIndex)
				return;
			goToPhoto(newIndex - currentIndex);
			clickMainMenuNextFoto($(".forward"));
		});
	}
	
	equalHeight($(".quick_links h1"));
	
	$(".has-childs #expand").toggle ( function() {
		new_h = $(this).parent().find("ul").height() + $(this).parent().height();
		$(this).parent().animate({height:new_h}, 500).addClass("open").removeClass("has-childs");
	}, function() {
		$(this).parent().animate({height:"34px"}, 500).removeClass("open").addClass("has-childs");
	});
	
	if ($('.menu2 .selected').length){
		var object = $('.menu2 .selected');
		var lenCurrentClassName = typeof(object.parent().attr("class"))=="undefined"?0:object.parent().attr("class").length;
		var lenFinishClassName = typeof(object.parent().attr("class"))=="undefined"?0:object.parent().attr("class").replace("menu2", "").length;
		while(lenCurrentClassName == lenFinishClassName){
			var hasChildLenClassName = typeof(object.parent().attr("class"))=="undefined"?"":object.parent().attr("class");
			if (hasChildLenClassName.length != hasChildLenClassName.replace("has-childs", "").length){
				$("#expand", object.parent()).click();
			}
			object = object.parent();
			lenCurrentClassName = typeof(object.parent().attr("class"))=="undefined"?0:object.parent().attr("class").length;
			lenFinishClassName = typeof(object.parent().attr("class"))=="undefined"?0:object.parent().attr("class").replace("menu2", "").length;
		}
	}
	
	
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}
	
	$(".play-btn , .download-btn , #fancybox-close , .color-block.title , .top_100_p.wraped_gallery .jcarousel-prev , .top_100_p.wraped_gallery .jcarousel-next ,  .sig_inn_b , .btn_view , .stop").mousedown(function(){
		$(this).addClass("clicked");
    }).mouseup(function(){
		$(this).removeClass("clicked");
    });
	
	if ($('.gallery-full .img-desc').length){
		$('.gallery-full .img-desc').scrollbar({
			arrows: false
		});
	}	
	
	$('.interesting').each( function() {
		num_of_visible_elem=(($(this).closest(".interesting_div").width()-372) - (($(this).closest(".interesting_div").width()-372)%161))/161 + '';
		var arr = num_of_visible_elem.split('.');
		table_width=$(this).closest(".interesting_div").width()-10;
		$(this).width(table_width).find("td:gt("+arr[0]+")").hide();
	});
	
	/*  
	if ($(".photo-change .forward").length) {
		mainPageInterval = setInterval(function(){
			$(".photo-change .forward").click();
		}, 10000);
	}*/
	
	equalHeight($(".pics .inline-block li"));
	
	
	if ($.browser.opera) {
		$(".arrow").css({"bottom":"-5px !important"});
	}
	
	$(".sign_in").click(function(){
		var loginModal = new myModal();
		loginModal.open({
			onClose:function(){
				
			},
			onOpen:function(){
				$('#modal-overlay').css({opacity:'0.42', background:'#000'});
				$('#login_form', $('#modal-window')).show();
				var loginForm = $('#login_form', $('#modal-window'));
				var top = ($(window).height() - loginForm.height())/2;
				var left = ($(window).width() - loginForm.width())/2;
				$('#modal-window').css({top: top+'px', left: left+'px'});
				$('#modal-window').addClass('login_form');
				
				var checkBox = $('.input_checkbox_stock', $('#modal-window'));
				checkBox.removeClass('input_checkbox_stock');
				checkBox.addClass('input_checkbox');
				
				if ($('.input_checkbox').length ) {
					$('.input_checkbox').checkboxstyle();
				}
				
				$('#input_login', $('#modal-window')).bind('focus', function(){
					if ($(this).val()=='Login'){
						$(this).css('color', '#000');
						$(this).val('');
					}
				});
				$('#input_login', $('#modal-window')).bind('blur', function(){
					if ($(this).val()=='' || $(this).val()=='Login'){
						$(this).val('Login');
						$(this).css('color', '#BEBEBE');
					}
				});
				
				$('#password_text', $('#modal-window')).bind('focus', function(){
					$('#password_psw', $('#modal-window')).css('color', '#000');
					$('#password_psw', $('#modal-window')).show();
					$('#password_psw', $('#modal-window')).val('');
					$(this).hide();
					$('#password_psw', $('#modal-window')).focus();
				});
				
				$('#password_psw', $('#modal-window')).bind('blur', function(){
					if ($(this).val()=='' || $(this).val()=='Password'){
						$(this).hide();
						$('#password_text', $('#modal-window')).val('Password');
						$('#password_text', $('#modal-window')).show();
					}
				});
				
				$(".changePass").click(function(){
					closeModal();
					$.ajax({
					      url: "/user/?&act=getChangePassForm",
					      type: "GET",
					      data: {},
					      async:false,
					      success: function(msg){
					    	  $('body').append(msg);
					      }
					   });
					
					//
					var chModal = new myModal();
					chModal.open({
						onClose:function(){
							
						},
						onOpen:function(){
							$('#modal-overlay').css({opacity:'0.42', background:'#000'});
							$('#ch_login_form', $('#modal-window')).show();
							var loginForm = $('#ch_login_form', $('#modal-window'));
							var top = ($(window).height() - loginForm.height())/2;
							var left = ($(window).width() - loginForm.width())/2;
							$('#modal-window').css({top: top+'px', left: left+'px'});
							$('#modal-window').addClass('login_form');
							
							$('#ch_input_login', $('#modal-window')).bind('focus', function(){
								if ($(this).val()=='Login'){
									$(this).css('color', '#000');
									$(this).val('');
								}
							});
							$('#ch_input_login', $('#modal-window')).bind('blur', function(){
								if ($(this).val()=='' || $(this).val()=='Login'){
									$(this).val('Login');
									$(this).css('color', '#BEBEBE');
								}
							});
							$('.login_t').bind('focus', function(){
								$(this).css('color', '#000');
							});
						},
						modalObject:$("#ch_login_form")
					});
				});
				
				
				$('#loginSubmit', $('#modal-window')).click(function(){
					var allOk = true;
					var msg = "";
					var login = $('#input_login', $('#modal-window'));
					var pass = $('#password_psw', $('#modal-window'));
					if (login.val() == '' || login.val() == 'Login'){
						allOk = false;
						msg = "Login is empty!";
					}
					if (pass.val() == '' || pass.val() == 'Password'){
						allOk = false;
						msg += " Password is empty!";
					}
					if (allOk){
						$.ajax({
						      url: "/user/?&act=checkUser",
						      type: "POST",
						      data: {login: login.val(), password: pass.val()},
						      async:false,
						      success: function(responseText){
						    	  if (responseText == "false"){
						    		  allOk = false;
						    		  msg += " Login or password is wrong!";
						    	  }
						      }
						   });
					}
					if (allOk)
						return true; // ok
					else {
						$('#errorLoginMsg', $('#modal-window')).html(msg);
						return false; // so bad
					}
				});
				
			},
			modalObject:$("#login_form").clone()
		});
	});
	
	
	standvalue($('.login_t'));
	if ($('.btn_download').length ) {
		$('.btn_download').filestyle();
	}
	
	
	var currentOpenedObject = null;
	var countOpened = 0;
	var onChildMenu = false;
	
	$(".first_level_link_parent").hover(
		function(){
			var currentId = currentOpenedObject!=null?currentOpenedObject.attr('id'):-1;
			var childContainer = $(this).next();
			if (currentId != childContainer.attr('id')){
				if (childContainer.attr('class') == "second_level_link_fly_container"){
					childContainer.show('fast');
				}
				currentOpenedObject = childContainer;
				countOpened = 0;
			} else {
				countOpened++;
			}
			if (countOpened == 1){
				childContainer.hide('fast');
				currentOpenedObject = null;
			}
		},
		function(){
			var childContainer = $(this).next()
			setTimeout(function(){
				if (!onChildMenu)
					childContainer.hide('fast');				
					currentOpenedObject = null;
			}, 200);
		}
	);
	
	$(".second_level_link_fly_container").hover(
		function(){
			onChildMenu = true;
			$(".arrow_menu_div", $(this).prev()).addClass("active_arrow_menu_div");
		},
		function(){
			onChildMenu = false;
			$(this).hide('fast');
			$(".arrow_menu_div", $(this).prev()).removeClass("active_arrow_menu_div");
		}
	);
	
	var currentScroll = 0;
	
	if ($(".active", $(".pages_inn")).length){
		$("a", $(".pages_inn")).hide();
		currentScroll =$(".active", $(".pages_inn")).attr("id");
		currentScroll = currentScroll.split("_");
		currentScroll = currentScroll[2];
		for(var i=currentScroll;i<parseInt(currentScroll)+15;i++){
			if ($("#page_link_"+i).length){
				$("#page_link_"+i).show();
			}
		}
	}
	
	$(".scrollLeft").click(function(){
		$("a", $(".pages_inn")).hide();
		currentScroll = parseInt(currentScroll)-15;
		if (currentScroll < 0)
			currentScroll = 0;
		for(var i=currentScroll;i<parseInt(currentScroll)+15;i++){
			if ($("#page_link_"+i).length){
				$("#page_link_"+i).show();
			}
		}
	});
	
	$(".scrollRight").click(function(){
		$("a", $(".pages_inn")).hide();
		currentScroll = parseInt(currentScroll)+15;
		if (currentScroll > $(".pages_inn a").length)
			currentScroll = $(".pages_inn a").length;
		for(var i=currentScroll;i<parseInt(currentScroll)+15;i++){
			if ($("#page_link_"+i).length){
				$("#page_link_"+i).show();
			}
		}
	});
	
	// Удалить стрелки в топ 101 если картинок больше 4-х
	$("ul.jcarousel-list li.jcarousel-item", $("#wrapper-top101-main")).each(function(){
		if ($(this).html()==null || $(this).html()==""){
			$(this).remove();
		}
	});
	if ($("ul.jcarousel-list li.jcarousel-item", $("#wrapper-top101-main")).length < 5 && $("ul.jcarousel-list li.jcarousel-item", $("#wrapper-top101-main")).length > 0){
		$(".jcarousel-prev").remove();
		$(".jcarousel-next").remove();
	}
	

});


function mathSize( obj ) {
	container_width = $(window).width()
	if ( container_width < 1200 ) {
		size = 3;
	} else {
		var width = $(obj).find('li').css('width');
		var margin = $(obj).find('li').css('marginRight');
		size = Math.floor( container_width / ( width + margin ) );
	}
	return size;
}
//показать\скрыть страны
function showCountries(continentId){	
	$('.continent-container').hide('fast');
	$('#continent_' + continentId).toggle('fast');
}

function initTravellingHoverCountry(){
	
	$('.list_place_link').click(function(){
		isClickOnCities = true;
		var countryId = $(this).attr('country');
		if(!$('#country_'+countryId).is(':visible')){
			$('.city-list').hide();
			$('#country_'+countryId).show('fast');
		} else {
			$('.city-list').hide();
		}
	});
	
	$('.continent-container').hover(function(){},function(){$(this).hide('fast');});
	$('.city-list').hover(function(){},function(){$(this).hide();});
}

