jQuery(document).ready(function($) {
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	
	$('#featured-news').cycle();
	$('#item-slideshow').cycle({cleartype: 1});
	$('#news-media-interface').css('background', 'none');
	
	
	
//	$('.feature img.banner').click(function() {
//		$('#item-slideshow').hide();
//		$('#item-content-wrapper').show();
//		$('#item-content-wrapper').css('background', 'url(http://momsbestnaturals.com/blogs/wp-content/themes/mbn/images/news-media/loader.gif) no-repeat center center');
//		
//		var id = $(this).attr('id').substr(5);
//		
//		$('#item-content').hide().load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-single-post-content.php?postid=" + id, function() {
//			$('#item-content-wrapper').css('background', 'none');
//			$(this).css('height', 'auto');
//			$(this).fadeIn();
//		});
//	});
	
	$('#load-print-thumbs').load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-print-thumbs.php", function() {
		var ul = $(this).children('.thumbs-container').children('ul');
		var num = ul.children('li').size();
		var w = num * 102;
		ul.css('width', w + 'px');
		
		$(this).disableTextSelect();
		$(this).children('.prev').fadeTo(100, 0.5);
		if (num <= 4)
			$(this).children('.next').fadeTo(100, 0.5);
		
		$(this).fadeIn();
		
		$('.print .thumbs li').click(function() {
			$('#item-slideshow').hide();
			$('#item-content-wrapper').show();
			$('#item-content-wrapper').css('background', 'url(http://momsbestnaturals.com/blogs/wp-content/themes/mbn/images/news-media/loader.gif) no-repeat center center');
			
			if ($(this).hasClass('caption'))
				var id = $(this).parent().attr('class').substr(5);
			else
				var id = $(this).attr('class').substr(5);
			
			$('#item-content').hide().load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-single-post-content.php?postid=" + id, function() {
				$('#item-content-wrapper').css('background', 'none');
				//alert("Just ran $('#item-content-wrapper').css('background', 'none');");
				$('#item-content').height('auto');
				//alert("Just ran $(this).css('height', 'auto');");
				$('#item-content').fadeIn();
				//alert("Just ran $(this).fadeIn();");
			});
		});
		$(this).children('.prev').click(function() {
			var ul = $(this).next().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left < -408) {
					ul.animate({left: '+=408'}, 'slow');
					$(this).next().next().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '+=' + (0 - left)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).next().next().fadeTo('fast', 1);
				}
			}
		});
		$(this).children('.next').click(function() {
			var ul = $(this).prev().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left + w > 816) {
					ul.animate({left: '-=408'}, 'slow');
					$(this).prev().prev().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '-=' + (left + w - 408)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).prev().prev().fadeTo('fast', 1);
				}
			}
		});
	});
	
	$('#load-web-thumbs').load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-web-thumbs.php", function() {
		var ul = $(this).children('.thumbs-container').children('ul');
		var num = ul.children('li').size();
		var w = num * 102;
		ul.css('width', w + 'px');
		
		$(this).disableTextSelect();
		$(this).children('.prev').fadeTo(100, 0.5);
		if (num <= 4)
			$(this).children('.next').fadeTo(100, 0.5);
		
		$(this).fadeIn();
		
		$('.web .thumbs li').click(function() {
			$('#item-slideshow').hide();
			$('#item-content-wrapper').show();
			$('#item-content-wrapper').css('background', 'url(http://momsbestnaturals.com/blogs/wp-content/themes/mbn/images/news-media/loader.gif) no-repeat center center');
			
			if ($(this).hasClass('caption'))
				var id = $(this).parent().attr('class').substr(5);
			else
				var id = $(this).attr('class').substr(5);
			
			$('#item-content').hide().load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-single-post-content.php?postid=" + id, function() {
				$('#item-content-wrapper').css('background', 'none');
				$(this).css('height', 'auto');
				$(this).fadeIn();
			});
		});
		$(this).children('.prev').click(function() {
			var ul = $(this).next().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left < -408) {
					ul.animate({left: '+=408'}, 'slow');
					$(this).next().next().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '+=' + (0 - left)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).next().next().fadeTo('fast', 1);
				}
			}
		});
		$(this).children('.next').click(function() {
			var ul = $(this).prev().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left + w > 816) {
					ul.animate({left: '-=408'}, 'slow');
					$(this).prev().prev().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '-=' + (left + w - 408)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).prev().prev().fadeTo('fast', 1);
				}
			}
		});
	});
	
	$('#load-press-releases').load("http://momsbestnaturals.com/blogs/wp-content/themes/mbn/load-press-releases.php", function() {
		var ul = $(this).children('.thumbs-container').children('ul');
		var num = ul.children('li').size();
		var w = num * 102;
		ul.css('width', w + 'px');
		
		$(this).disableTextSelect();
		$(this).children('.prev').fadeTo(100, 0.5);
		if (num <= 4)
			$(this).children('.next').fadeTo(100, 0.5);
		
		$(this).fadeIn();
		
		$(this).children('.prev').click(function() {
			var ul = $(this).next().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left < -408) {
					ul.animate({left: '+=408'}, 'slow');
					$(this).next().next().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '+=' + (0 - left)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).next().next().fadeTo('fast', 1);
				}
			}
		});
		$(this).children('.next').click(function() {
			var ul = $(this).prev().children('ul');
			var num = ul.children('li').size();
			var w = num * 102;
			var left = parseInt(ul.css('left').substr(0, ul.css('left').indexOf('px')));
			//alert('left: ' + left + ' w: ' + w);
			if (num > 4) {
				if (left + w > 816) {
					ul.animate({left: '-=408'}, 'slow');
					$(this).prev().prev().fadeTo('fast', 1);
				}
				else {
					ul.animate({left: '-=' + (left + w - 408)}, 'slow');
					$(this).fadeTo('fast', 0.5);
					$(this).prev().prev().fadeTo('fast', 1);
				}
			}
		});
	});
	
});
