var Alps = {
	art : false,
	country_art : false,
	vg : 'winter',
	cvg : false,
	obj : false,
	current_visited : false,
	timer_menu : false,
    last_current:8,
    getLast:function(cnt) {
        /*$('#last_list').html('<div style="width:438px; height: 155px;vertical-align: middle;text-align: center;"><h1 style="margin-top: 70px;">Загружаем...</h1></div>');
        $.ajax({url:'/ajax/last', data:{cpg:cnt}}).success(function(text){ $('#last_list').html(text); });*/
        var dv = $('#last_list').children('div');
        
        if(cnt == 'up') {
            if(Alps.last_current >= 8) {
                $('.a_prev_dis').removeClass('a_prev_dis').addClass('a_prev');
                var i = 0;
                var max_i = Alps.last_current - 8;
                var curr_i = Alps.last_current;
                dv.children('span.info').each(function(){
                    if(i < curr_i && i >= max_i)
                    {
                        $(this).show().css('display','block');
                    } else {
                        $(this).hide();
                    }
                    i++;
                });
                Alps.last_current = max_i;
                if(Alps.last_current == 0) {
                    $('.a_next').removeClass('a_next').addClass('a_next_dis');
                    Alps.last_current = 8;
                }
            }
        } else {
            if(Alps.last_current <= 72) {
                $('.a_next_dis').removeClass('a_next_dis').addClass('a_next');
                var i = 0;
                var max_i = Alps.last_current + 8;
                var curr_i = Alps.last_current;
                dv.children('span.info').each(function(){
                    if(i >= curr_i && i < max_i)
                    {
                        $(this).show().css('display','block');
                    } else {
                        $(this).hide();
                    }
                    i++;
                });
                Alps.last_current = max_i;
                if(Alps.last_current == 80) {
                    Alps.last_current = 72;
                    $('.a_prev').removeClass('a_prev').addClass('a_prev_dis');
                }
            }
        }
    },
	countries_url : {
		'winter' : [ 'countries/switzerland', 'countries/germany',
				'countries/austria', 'countries/france', 'countries/italy',
				'countries/slovenia' ],
		'summer' : [ '/summer/countries/switzerland',
				'/summer/countries/germany', '/summer/countries/austria',
				'/summer/countries/france', '/summer/countries/italy',
				'/summer/countries/slovenia' ]
	},
	countries_list : [ 'switzerland', 'germany', 'austria', 'france', 'italy',
			'slovenia' ],
	getSubMenu : function(obj, tp) {
		var of = $(obj).offset();
		if($(obj).attr('data-obj') != 'books') {
			var countriesSublist = '<div data-country="2" class="submenu-item">Австрия</div><div data-country="1" class="submenu-item">Германия</div><div data-country="4" class="submenu-item">Италия</div><div data-country="5" class="submenu-item">Словения</div><div data-country="3" class="submenu-item">Франция</div><div data-country="0" class="submenu-item">Швейцария</div>';
			if ( $('#countriesSublistContent').size() ) {
				var countriesSublist = $('#countriesSublistContent').html();
			}
			var html = '<div class="submenu" style="top:'
					+ (of.top + 18)
					+ 'px; left:'
					+ of.left
					+ 'px;">'+countriesSublist+'</div>';
		} else {
			var html = '<div class="submenu" style="height:auto;top:'
				+ (of.top + 18)
				+ 'px; left:'
				+ of.left
				+ 'px;"></div>';
            html = $(html).append($('#books_list').html());
		}
				
		$('body').append(html);
		$('.submenu-item').each(
				function() {
					$(this).click(
							function() {
                                if($(obj).attr('data-obj') != 'books') {
                                    window.location.href = '/summer/'
                                            + Alps.countries_url[Alps.vg][$(this)
                                                    .attr('data-country')].replace(
                                                    /\/summer\//, '') + '/' + tp;
                                } else {
                                    window.location.href = $(this).attr('data-country');
                                }
							});
					$(this).hover(function() {
						$('.submenu-item').removeClass('submenu-item-hover');
						$(this).addClass('submenu-item-hover');
					}, function() {
						$('.submenu-item').removeClass('submenu-item-hover');
					});
				});
		$('.submenu').mouseenter(function(e) {
			clearTimeout(Alps.timer_menu);
		});
		$('.submenu').mouseleave(function(e) {
			Alps.timer_menu = setTimeout(function() {
				$('.submenu').remove();
			}), 1200;
		});
	},
	getSitesForSelect : function(obj, country_id, flag) {
		$("#choise_country li").removeClass('active');
		$(obj).parent().addClass('active');
		$.ajax({
			'type' : 'POST',
			'url' : '/ajax/sit_for_sel',
			data : {
				country_id : country_id,
				vg : Alps.vg,
				clr: true
			},
			success : function(text) {
				$('.jquery-selectbox').replaceWith(
						'<select id="hidden_list"></select>');
				$("#hidden_list").html(text);
				$("#hidden_list").selectbox();
				$("#hidden_list").selectbox().bind('change', function() {
					Alps.getCurortPreview($("#hidden_list").val())
				});
				if (flag)
					Alps.getCurortPreview($("#hidden_list").val())
			}
		});
	},
	getSitesForSelect2 : function(obj, country_id, cid) {
		$("#choise_country li").removeClass('active');
		$(obj).parent().addClass('active');
		$.ajax({
			'type' : 'POST',
			'url' : '/ajax/sit_for_sel',
			data : {
				country_id : country_id,
                cid : cid,
				vg : Alps.vg
			},
			success : function(text) {
				$('.jquery-selectbox').replaceWith(
						'<select id="hidden_list"></select>');
				$("#hidden_list").html(text);
				$("#hidden_list").selectbox();
				$("#hidden_list").selectbox().bind(
						'change',
						function() {
							window.location.href = String($("#hidden_list").val()).replace(/!/, "'");
						});
			}
		});
	},
	getCurortPreview : function(cid) {
		$('#curort_preview').load('/ajax/cur_preview', {
			cid : cid,
			vg : Alps.vg
		}, function() {
			$('body').css({
				zoom : 1
			})
		});
	},
	getArt : function(ob, tp) {
		$.ajax({
			'type' : 'POST',
			'url' : '/ajax/get_anons',
			data : {
				cid : this.art,
				tp : tp,
                vg : Alps.vg
			},
			success : function(text) {
				var data = $.parseJSON(text);
				if (!data.error) {
					$('.article').replaceWith(data.text);
					Alps.art = data.id;
				}
			}
		});
	},
	getCountryArt : function(ob, tp, pid, elem) {
		(typeof elem == undefined) ? elem = false : '';
		$.ajax({
			'type' : 'POST',
			'url' : '/ajax/get_art',
			data : {
				cid : this.country_art,
				tp : tp,
				pid : pid,
				elem : elem
			},
			success : function(text) {
				var data = $.parseJSON(text);
				if (!data.error) {
					$('.country_article').show();
					$('.country_article').html(data.text);
					Alps.country_art = data.id;
				}
			}
		});
	},
	goTo : function(cntr, vg) {
		window.location.href = '/' + (Alps.cvg != false ? Alps.cvg : vg)
				+ '/country.html?id=' + cntr + '&vg='
				+ (Alps.cvg != false ? Alps.cvg : vg)
				+ (Alps.obj != false ? '&obj=' + Alps.obj : '');
	},
	changeVG : function(vg, to_vg) {
		var reg = new RegExp('(/' + vg + ')', 'g');
		var href = String(window.location.pathname).replace(reg, '');
		to_vg == 'summer' ? window.location.href = '/summer' + href.replace(/(\/summer)/, '')
				: window.location.href = href;
	},
	changeObject : function(obj, tp, id) {
		$('#map_obj div').removeClass('map_obj_active');
		$('a[data-otp="' + tp + '"]').parent().addClass('map_obj_active');
		$.ajax({
			'type' : 'POST',
			'url' : '/ajax/get_obj',
			data : {
				tp : tp,
				id : id,
				vg : Alps.vg,
				ctr : obj
			},
			success : function(text) {
				var data = $.parseJSON(text);

				if ($('[data-objects]').length) {
					$('[data-objects]').effect('fade', {}, 200, function() {
						$('[data-objects]').remove();
						$('#map_cont').append(data.text);
						$('[data-objects]').effect('bounce', {}, 100);
						$('[data-objects]').each(function() {
							var el = $(this);
							el.hover(function() {
								el.addClass('active');
								el.find('.map_obj_text').css({
									opacity : 0.9
								}).show();
							}, function() {
								el.removeClass('active');
								el.find('.map_obj_text').css({
									opacity : 1
								}).hide();
							});
							el.click(function() {
								window.location.href = $(this).attr('target');
							});
						});
					});
				} else {
					$('#map_cont').append(data.text);
					$('[data-objects]').effect('bounce', {}, 100);
					$('[data-objects]').each(function() {
						var el = $(this);
						el.hover(function() {
							el.addClass('active');
							el.find('.map_obj_text').css({
								opacity : 0.9
							}).show();
						}, function() {
							el.removeClass('active');
							el.find('.map_obj_text').css({
								opacity : 1
							}).hide();
						});
						el.click(function() {
							window.location.href = $(this).attr('target');
						});
					});
				}

			}
		});
	},
	getElementKurort : function(obj, nm) {
		var el = $('.photo_active');
		el.removeClass('photo_active');
		$(obj).addClass('photo_active');
		if ($(obj).next().length == 0)
			$('.art_next').addClass('art_next_dis');
		else
			$('.art_next').removeClass('art_next_dis');
		if ($(obj).prev().length == 0)
			$('.art_prev').addClass('art_prev_dis');
		else
			$('.art_prev').removeClass('art_prev_dis');
		var i = 0;
		if (nm >= 0) {
			$('#photos_kurort>tbody>tr').each(function() {
				if (i >= nm * 6 && i < (nm * 6 + 6)) {
					$(this).show();
				} else
					$(this).hide();
				i++;
			});
		}
	},
	getElementKurortStr : function(obj, tp) {
		if (tp == 'next') {
			var el = $('.photo_active');
			if (el.next().length == 0)
				$(obj).addClass('art_next_dis');
			else {
				el.removeClass('photo_active');
				$(obj).removeClass('art_next_dis');
				$('.art_prev').removeClass('art_prev_dis');
				el.next().addClass('photo_active');
				if (el.next().next().length == 0)
					$(obj).addClass('art_next_dis');
				el.next().click();
			}
		} else {
			var el = $('.photo_active');
			if (el.prev().length == 0)
				$(obj).addClass('art_prev_dis');
			else {
				el.removeClass('photo_active');
				$(obj).removeClass('art_prev_dis');
				$('.art_next').removeClass('art_next_dis');
				el.prev().addClass('photo_active');
				if (el.prev().prev().length == 0)
					$(obj).addClass('art_prev_dis');
				el.prev().click();
			}

		}
	}

}
