(function($){

//================================================================================
	
	  function have_captions(){
	  		jQuery('.wp-caption-text').hide();
			jQuery('.wp-caption').wrap('<div class="cap-wrap" />');
			jQuery('.wp-caption').prepend("<a href=\"#\" class=\"ctrl\">+</a>");
					//alert('done');
					
				jQuery('.wp-caption-text').hide();
					jQuery('.ctrl').click(function() {
						//alert(nextcaption);
							event.preventDefault();
						if(jQuery(this).hasClass("open")){
							//alert("open");
							jQuery(this).removeClass("open");
							jQuery(this).siblings('.wp-caption-text').fadeTo('slow', 0, function() {
							 // Animation complete.
							});
						}else{
							//alert("not open");
								
							jQuery(this).addClass("open");
							jQuery(this).siblings('.wp-caption-text').fadeTo('slow', 1, function() {
							 // Animation complete.
							});
						}
							/**/
				//	jQuery(this).siblings('.wp-caption-text').css("background", "yellow");
				
				  });
	  }
	  
	jQuery(document).ready(function(){
		
		
   // var imgsrc = jQuery("img").attr('src');
    //alert(imgsrc);
jQuery("img").lazyload({ threshold : 200 });
function updateLazy() {
	jQuery('img').each( function(i,n) {
		if( jQuery(n).offset().top < ( jQuery(window).scrollTop() + jQuery(window).height() ) ) {
			var img = new Image();
			var src = jQuery(n).attr('data-real-src');
			img.onload = function() {
				jQuery(n).css('background-image', 'url(' + src + ')' );
				jQuery(n).css('opacity', 1);
			}
			img.src = src;
		}
	} );
}


    jQuery("body a").removeAttr('title');
    jQuery("body img").removeAttr('title');
		
		
		function check_window(){
			
					if(jQuery(window).width() < "1270"){
						//alert("small");
						 jQuery("#tertiary").css({"position":"absolute","left":"1115px","right":"auto","top":+(jQuery(window).scrollTop()+29)+"px"});
					
						//jQuery("#tertiary").css({"position":"absolute","left":"auto","right":"auto","margin-right":"30px"});
					}else{
					
						 jQuery("#tertiary").css({"position":"fixed","left":"auto","right":"0","top":"29px"});
				
						//alert("large");
					}
		}
	//alert(jQuery(window).width());
	
					
					if(jQuery(window).width() < "1270"){
						//alert("small");
						 jQuery("#tertiary").css({"position":"absolute","left":"1115px","right":"auto","top":+(jQuery(window).scrollTop()+29)+"px"});
					
						//jQuery("#tertiary").css({"position":"absolute","left":"auto","right":"auto","margin-right":"30px"});
					}else{
					
						 jQuery("#tertiary").css({"position":"fixed","left":"auto","right":"0","top":"29px"});
				
						//alert("large");
					}
					
			//alert(jQuery(window).scrollTop());
		jQuery(window).scroll(function() {
					
					if(jQuery(window).width() < "1270"){
						//alert("small");
						 jQuery("#tertiary").css({"position":"absolute","left":"1115px","right":"auto","top":+(jQuery(window).scrollTop()+29)+"px"});
					
						//jQuery("#tertiary").css({"position":"absolute","left":"auto","right":"auto","margin-right":"30px"});
					}else{
					
						 jQuery("#tertiary").css({"position":"fixed","left":"auto","right":"0","top":"29px"});
				
						//alert("large");
					}
					
			//alert(jQuery(window).scrollTop());
		});
		
	jQuery(window).resize(function() {
						if(jQuery(window).width() < "1270"){
							//alert("small");
						 jQuery("#tertiary").css({"position":"absolute","left":"1115px","right":"auto","top":+(jQuery(window).scrollTop()+29)+"px"});
						
							//jQuery("#tertiary").css({"position":"absolute","left":"auto","right":"auto","margin-right":"30px"});
						}else{
						
						 jQuery("#tertiary").css({"position":"fixed","left":"auto","right":"0","top":"29px"});
					
							//alert("large");
						}
	});
		
		
		
	  
	  
	  have_captions();
	  
		
	jQuery('#content').infinitescroll({

		// callback		: function () { console.log('using opts.callback'); },
		navSelector  	: "#nav-below .nav-previous a:last",
		nextSelector 	: "#nav-below .nav-previous a:last",
		itemSelector 	: "#content",
		debug		 	: false,
		dataType	 	: 'html',
		loading: {
			finished: undefined,
			finishedMsg: "<em>There are no more entries.</em>",
			img: "http://zvereff.com/zvereff_live/wp-content/themes/toolbox/i/loading.gif",
			msg: null,
			msgText: "<em>Loading...</em>",
			selector: null,
			speed: 'fast',
			start: undefined
		},
		// behavior		: 'twitter',
		// appendCallback	: false, // USE FOR PREPENDING
		// pathParse     	: function( pathStr, nextPage ){ return pathStr.replace('2', nextPage ); }
    }, function(newElements){
		have_captions();
    	//USE FOR PREPENDING
    	// $(newElements).css('background-color','#ffef00');
    	// $(this).prepend(newElements);
    	//
    	//END OF PREPENDING
    	
    	window.console && console.log('context: ',this);
    	window.console && console.log('returned: ', newElements);
    	
    });
		
		
		
		
		
		
	}); /* END DOCUMENT READY */

})(jQuery);
//================================================================================
// Document Ready

