var $j = jQuery.noConflict();

$j(document).ready(function() {
	//disable right-click
	$j('img').bind('contextmenu', function(e){
		return false;	
	});
	
	//Height of text
		$j('.text').each(function(index) {
			(function($j) {
				$j.fn.hasScrollBar = function() {
					return this.get(index).scrollHeight > this.height();
					test = this.get(index).scrollHeight > this.height();
				}
			})(jQuery); 
		
			if ($j('.text').hasScrollBar()) {
				var height = 0;
				heightHead = ($j('.story-head').outerHeight(true)) + 31;
				height = 460 - heightHead;
				$j('.text').css('max-height', height);
				
				$j('.text').attr('id', 'text' + index); 
			}

		}); 
		
	$j(".text").jScrollPane({showArrows: true, horizontalGutter: 10});
	
	$j(function() {
		$j('html, body').mousewheel(function(event, delta) {
				this.scrollLeft -= (delta * 60);
				/*event.stopPropagation();*/
				event.preventDefault();
		});
		
    });
	
	var viewportHeight = $j(window).height() - 20;
	$j('html, body').css('height', viewportHeight);
	
	if ( $j.browser.msie && $j.browser.version < 7) {
    	alert("You are using an outdated browser.  This website will look better in a newer browser.");  
     }

});

$j(window).load(function() {
    //Homepage Width
	if ($j('.home .story-wrap').length > 0){
		var width = 0;
		var welcome = $j('.welcome-shot').outerWidth() + 20;
		var more = $j('.more').outerWidth() + 20;
		$j('.story-wrap').each(function() {
			width += $j(this).outerWidth(true);
		});
		width = width + welcome + more
		$j('body').css('width', width);
	} 
	
	//Single Story Width & Categories
	if ($j('.single .story-wrap').length > 0) {
		var width = 0;
		var respond = 0;
		var response = 0;

		var more = $j('.more').outerWidth() + 80;
		if ($j('#respond').length) {		
			var respond = $j('#respond').outerWidth() + 20;
		}
		if ($j('#response').length) {
			var response = $j('#response').outerWidth() + 20;		
		}
		$j('.story-wrap').each(function() {
			width += $j(this).outerWidth(true);
		});	
		width = width + more + respond + response;
		$j('body').css('width', width);
	}
	
	if ($j('.category .story-wrap').length > 0) {
		var width = 0;
		var respond = 0;
		var response = 0;

		var more = $j('.more').outerWidth() + 80;
		if ($j('#respond').length) {		
			var respond = $j('#respond').outerWidth() + 20;
		}
		if ($j('#response').length) {
			var response = $j('#response').outerWidth() + 20;		
		}
		$j('.story-wrap').each(function() {
			width += $j(this).outerWidth(true);
		});	
		width = width + more + respond + response;
		$j('body').css('width', width);
	}
	
	//Categories Page Width 
	if ($j('.categories-wrap').length > 0){
		var width = 0;
		$j('.categories-wrap img').each(function() {
			width += $j(this).outerWidth(true);
			console.log(width);
		});
		width = width + 180;
		$j('body').css('width', width);
	}
	
});

