/* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);

(function ($) {
    $(document).ready(function() {
	
		// Load Pluck content from Blogs and Goals
		$('#personal_blog_wpr').load($('#blogs_list_path').val());
		$('.goal_stats_wpr').load($('#goal_stats_goal_path').val());
		
		// Pictures/Video Tab Swapping
		$('.uploaded_media_nav').click(function (evt) {
			evt.preventDefault();
			$('#tabWrapper').get(0).className = '';
			$('#tabWrapper').addClass($(this).attr('target') + '_active');
			// Swap title
			$('.pictures_active .moduleLeft .header h3').html('Business Pictures');
			$('.videos_active .moduleLeft .header h3').html('Business Videos');
		});
		
		var modules = $('.gallery .moduleContent');
		if (modules.length > 0) {
			// alert($(modules[0]).children("div:first").attr('id'));
			$('.gallery').addClass($(modules[0]).children("div:first").attr('id') + "_active");
		}
		
		// Set scrollable business pictures	
		$('#publicProfileImageGallery .scrollable').scrollable({size: 1});
		var ct = $('.bizPic').size(); 
		if (ct === 1) {
			$('span.bizPicPagination, .prevPage, .nextPage').hide();
		};
		
		// Business Videos
		$('#videoThumbs .scrollable').scrollable({size: 6});
		var vct = $('#videoThumbs .scrollable .items div').size(); 
		if (vct < 7) {
			$('#videos .prevPage, #videos .nextPage').hide();
		};
		$('#videoThumbs .scrollable .items div').click(function() {
			var video_name = 'thumb_';
			var video_id = parseInt($(this).attr('class').substring(video_name.length), 10);
			$('#current_video').text(video_id);
			$("div[class^='video_']").hide();
			$('#videoThumbs .scrollable div').removeClass('active');
			$(this).addClass('active');
			$('.video_' + video_id).show();
			return false;
		});
		
	});

	$('.scroll_nav').click(function (evt) {
	    evt.preventDefault();
	});
})(jQuery);		
 