var InsJs = {
	requestBlock: false,
    toggleTop: function(prefix, num)
	{
		$('.item'+prefix+'Show:visible').each(function() {
			$('#'+this.id+'_').css('display', 'block');
			$('#'+prefix+'_'+num+'_').css('display', 'none');
			$(this).slideUp();
			$('#'+prefix+'_'+num).slideDown();
		});
		return false;
	},
	moveGallery: function(direction)
	{
		if ($('.onlyInCracowNaviLink').length > 3) {
			if (direction > 0) {
				$('.onlyInCracowNaviLink:last').css({width:0}).insertBefore('.onlyInCracowNaviLink:first').animate({width:'66px'}, 350);
			}
			else {
				if (parseInt($('.onlyInCracowNaviLink:first').css('width')) < 66) {
                    $('.onlyInCracowNaviLink:first').insertAfter('.onlyInCracowNaviLink:last');
                }
                $('.onlyInCracowNaviLink').each(function(num) {
                    if (num==0) {
                        $(this).animate({width:'0px'}, 350, null, function() {
                            $(this).insertAfter('.onlyInCracowNaviLink:last').css({width:'66px'});
                        });
                    }
                    else if(num==3) {
                        $(this).css({width:0}).animate({width:'66px'}, 350)
                    }
                });
			}
		}
		return false;
	},
	showOnlyInCracow: function(num)
	{
		$('#onlyInCracowBox > .boxItem:visible').each(function() {
			$(this).fadeOut('fast', function() {
				$('#onlyInCracowBox_'+num).fadeIn('slow');
			});
		});
		return false;
	},
	showWeather: function(num, title)
	{
		$('#weatherMainBox > .boxItem:visible').each(function() {
			$(this).fadeOut('fast', function() {
				$('#weatherBox_'+num).fadeIn('slow');
				$('#weatherTitle').text(title);
			});
		});
		return false;
	},
	showHideOptions: function(show)
	{
		if (show > 0) {
			$('#extra_options_button').hide('fast', function() {
				$('#extra_options').slideDown('normal');
			});
		}
		else {
			$('#extra_options').slideUp('normal', function() {
				$('#extra_options_button').show();
			});
		}
	},
	showHide: function(element)
	{
		if($(element).css('display')=='none'){
			$(element).css('display','block');
		}else{
			$(element).css('display','none');
		}
	},
    requestForm: function(form, resultDiv, loadingDiv, callback)
    {
        if (InsJs.requestBlock) {
            return false;
        }

        if (!loadingDiv) {
            loadingDiv = resultDiv;
        }
        if (!callback) {
            callback = function(){};
        }

        jQuery.ajax({
            url: $(form).attr('action'),
            method: $(form).attr('method'),
            data: $(form).serialize(),
            beforeSend  : function() {
                InsJs.requestBlock = true;
                $(loadingDiv).show().html('<div class="loading"></div>');
            },
            success: function(text) {
                InsJs.requestBlock = false;
                $(resultDiv).hide().html(text);
                $(resultDiv).fadeIn('fast');
                callback(text);
            }
        });
        return false;
    },

	addToPlanner : function(element,objectId,uri,plannerContentId)
	{
		$(element).fadeTo("slow", 0.80);
		$(element).html(i18n.planner_object_added);
		$.ajax({
		   type: "POST",
		   url:uri,
		   data: "object_id="+objectId,
		   success: function(msg){
				$(plannerContentId).html(msg);
				InsJs.plannerPreparePaginator();
				changePlannerBox('plannerBox','planYourStayBox');
				if ($.cookie('boxtodispaly') == null || $.cookie('boxtodispaly') == undefined) {
					$.cookie('boxtodispaly', 'plannerBox');
				}
				return false;
			}
		});

		return false;
	},

	plannerPreparePaginator: function(){
		this.plannerItemsCount = -1;
		this.plannerCurrentItem = 0;
		this.plannerIdItemPrefix = 'plannerObjectListGroup_';
		$(".plannerObjectListGroup").each(function(num){
			InsJs.plannerItemsCount++;
			$(this).attr('id', InsJs.plannerIdItemPrefix+InsJs.plannerItemsCount);
		});
	},

	plannerNextItems:function(){
		$('#'+this.plannerIdItemPrefix+this.plannerCurrentItem).hide();
		this.plannerCurrentItem++;
		if(this.plannerCurrentItem>this.plannerItemsCount){
			this.plannerCurrentItem = 0;
		}
		$('#'+this.plannerIdItemPrefix+this.plannerCurrentItem).show();
	},

	plannerPrevItems:function(){

		$('#'+this.plannerIdItemPrefix+this.plannerCurrentItem).hide();
		this.plannerCurrentItem--;
		if(this.plannerCurrentItem<0){
			this.plannerCurrentItem = this.plannerItemsCount;
		}
		$('#'+this.plannerIdItemPrefix+this.plannerCurrentItem).show();
	},
	toggleExpand:function(obj){
	  $(obj).toggleClass('expanded')
	}
};