(function(){

    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);

    special.resizestop = {
        latency: 300,
        setup: function() {
            var timer,
                    handler = function(evt) {

                    var _self = this,
                        _args = arguments;

                    if (timer) {
                        clearTimeout(timer);
                    }

                    timer = setTimeout( function(){
                        timer = null;
                        evt.type = 'resizestop';
                        jQuery.event.handle.apply(_self, _args);
                    }, special.resizestop.latency);
                };

            jQuery(this).bind('resize', handler).data(uid1, handler);
        },
        teardown: function() {
            jQuery(this).unbind('resize', jQuery(this).data(uid1) );
        }
    };

    special.scrollstop = {
        latency: 300,
        setup: function() {
            var timer,
                    handler = function(evt) {

                    var _self = this,
                        _args = arguments;

                    if (timer) {
                        clearTimeout(timer);
                    }

                    timer = setTimeout( function(){
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
                    }, special.scrollstop.latency);
                };

            jQuery(this).bind('scroll', handler).data(uid2, handler);
        },
        teardown: function() {
            jQuery(this).unbind('scroll', jQuery(this).data(uid2) );
        }
    };
})();

function page_bind_events(params) {
	params = $.extend({
		'imageLoading': '/images/icons/loader.gif'
	}, params);
	
	$('a[rel=lightbox]').each(function(id, img) {
	    $(img).lightBox({
    	    'imageLoading': params['imageLoading'],
			'imageBtnClose': params['imageBtnClose']
    	});
	});
	
	var resizeMainPage = function() {
		if (($(window).width() > 1150) && ($('#pj_page_sc').width() < 1150)) {
			$('#pj_page_sc').animate({'width': '1150px'}, 200, 'swing', function() {
				$('#pj_skycraper').show();
			});
		} else if (($(window).width() < 1150) && ($('#pj_page_sc').width() >= 1150)) {
			$('#pj_skycraper').hide();
			$('#pj_page_sc').animate({'width': '980px'}, 200, 'swing');
		}
	};
	resizeMainPage();
	$(window).bind('resizestop', resizeMainPage);
	
	var adjustSkyCraperHeight = function() {
        var skycraper = $('#pj_skycraper');
        if (skycraper) {
            skycraper.animate({ 'top': $(window).scrollTop() + 140 + 'px' }, 200, 'swing');
        }
    };
      adjustSkyCraperHeight();
      $(window).bind('scrollstop', function() {
          adjustSkyCraperHeight();
      });
    
}


