jQuery(function(){
    if ( jQuery(window).height() > 600 ){
        jQuery(document).scroll( function() {
            if ( jQuery(document).scrollTop() > 124 ){
                jQuery('.Main-Menu').addClass('slide-menu');
                
                if ( 0 !== jQuery('.share-block').length ){
                    if ( jQuery.browser.opera ){
                        jQuery('.sc').css('height', jQuery('.share-block').height() ); 
                    }
                    jQuery('.share-block').addClass('slide');
                    var footerPosition = jQuery(document).height() - jQuery('.footer .wrap').height() -60 - jQuery('.share-block').height() - jQuery('.Main-Menu').height() - 71 ;

                    if ( jQuery(document).scrollTop() > footerPosition ){
                        jQuery('.share-block').css('top', 71 - ( jQuery(document).scrollTop() - footerPosition ) )
                        
                    }else{
                        jQuery('.share-block').css('top', '' );
                    }
                }
            }else{
                jQuery('.Main-Menu').removeClass('slide-menu');
                jQuery('.share-block').removeClass('slide');
            }
        } )
    }
})

/* Pop Scroll Block */
/* Work with Cookies */
var popScrollTimes = jQuery.cookie("pop-scroll-times");
jQuery.cookie("pop-scroll-times", popScrollTimes*1 + 1, {path: "/", domain: "miss-vip.ru"});

var popScrollMaxTimes = 3;

var contentY;
var popScroll;
var isPopScroll = false;

jQuery(document).ready(function(){
	contentY = jQuery(".articleContent").height() - 100;
	popScroll = jQuery("#pop-scroll");
});

if (!navigator.userAgent.match(/iPad/) && (popScrollTimes <= popScrollMaxTimes)) {

	jQuery(window).scroll(function(){
		if ( (jQuery(document).scrollTop() - jQuery(".header").height() + 100) >= contentY && (jQuery(document).width() > 1140)) {
showPopScroll();
		}
		else {
hidePopScroll();
		}
	});
	
}

function showPopScroll() {
	if(!isPopScroll) {
		jQuery(popScroll).animate({right: "0px"}, 800);
		isPopScroll = true;
	}
}

function hidePopScroll() {
	if(isPopScroll) {
		jQuery(popScroll).animate({right: "-386px"}, 800);
		isPopScroll = false;
	}
}

function closePopScroll() {
	popScrollTimes = popScrollMaxTimes + 1;
	jQuery.cookie("pop-scroll-times", popScrollMaxTimes + 1, {path: "/", domain: "miss-vip.ru"});
	jQuery(popScroll).animate({right: "-386px"}, 800);	
}

function upPopScroll() {
	jQuery("html, body").animate({scrollTop:0},1000);
}
