var anchor = unescape(window.document.location.hash.substring(0));

if(anchor == '#' || anchor == '' || anchor =='undefined')
	showPage('#fizz10');
else
	showPage(anchor.replace('page_', ''));

$('#bubbling_under ul').rotator({
	ms : 3200, //time between rotations in miliseconds
	n: 1, //number of children elements to display
	autoHeight: false // automatically resize the element
});

$('.q_box p').hide();

$('#weekly_insight p').expander(
	{	slicePoint: 200,
		widow:2,
		expandEffect: 'fadeIn',
		expandText: 'more',
		expandSpeed: 500,
		userCollapseText: 'less',
		userCollapsePrefix: '&#0133;',
		afterExpand: function(thisEl) { 
			var x = thisEl.offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: x}, 1200); 
			}
	}
	);

// Only create tooltips when document is ready
$(document).ready(function()
	{
		
		$('.q_box').randomChild().show('fast');
		
		$('.q_box p:visible').expander(
			{	slicePoint: 56,
				widow:2,
				expandEffect: 'fadeIn',
				expandPrefix: '',
				expandText: '&nbsp;&#0133;',
				expandSpeed: 180,
				userCollapseText: '',
				userCollapsePrefix: '',
				beforeExpand: function($thisEl) {
					$thisEl.parent().siblings('.t_box').find('p:visible span.read-more').hide();
					$thisEl.parent().siblings('.t_box').find('p:visible span.details').fadeIn(180);
					$thisEl.parent().addClass('expanded'); 
					},
				onCollapse: function($thisEl, byUser) {
					$thisEl.parent().siblings('.t_box').find('p:visible span.read-more').fadeIn(180);
					$thisEl.parent().siblings('.t_box').find('p:visible span.details').hide();
					$thisEl.parent().removeClass('expanded').addClass('truncated'); 
					},
				parentClass: 'truncated'
			}
			);
		
	$('.t_box span').expander(
		{	slicePoint: 20,
			widow:2,
			expandEffect: 'fadeIn',
			expandPrefix: '',
			expandText: '&#0133;',
			expandSpeed: 180,
			userCollapseText: '',
			userCollapsePrefix: '',
			beforeExpand: function($thisEl) { 
					$thisEl.parent().siblings('.q_box').find('p:visible span.read-more').hide();
					$thisEl.parent().siblings('.q_box').find('p:visible span.details').fadeIn(180);
					},
			onCollapse: function($thisEl) { 
					$thisEl.parent().siblings('.q_box').find('p:visible span.read-more').fadeIn(180);
					$thisEl.parent().siblings('.q_box').find('p:visible span.details').hide();
					},
			parentClass: ''
		}
		);
		
		if($('#contact_form').length > 0)
			$('#contact_form').validate(
				{rules : {
					cf_name: { required:true,minlength: 3 },
					cf_company: { required:true,minlength: 3 },
					cf_email: { required:true,email:true },
					cf_message: { required:true,minlength: 3 }
				}}
		);
		
		if($('#download_form').length > 0)
			$('#download_form').validate(
				{rules : {
					dl_firstname: { required:true,minlength: 3 },
					dl_lastname: { required:true,minlength: 3 },
					dl_company: { required:true,minlength: 3 },
					dl_email: { required:true,email:true }
				}}
		);
		
		// Use the each() method to gain access to each of the elements attributes
		$('#n12 a').each(function()
		{
			$(this).qtip(
			{
			content: '<img src="/images/leaf.gif">', // Give it some content
			prerender: true,
			delay: 0,
			position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			}
		},
			hide: {
				fixed: true // Make it fixed so it can be hovered over
				},
				style: { 
				width: { min: 50 },
				width: { max: 150 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: {
					width: 5,
					radius: 5,
				color: '#A2D959'
				},
				tip: 'bottomMiddle',
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
				}
			});
		});
		//end function 1
		
		// function 2
		$('#smi1 a').each(function()
		{
			$(this).qtip(
			{
			content: 'share on facebook', // Give it some content
			prerender: true,
			delay: 0,
			position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { x: 0, y: -8 }
		},
			hide: {
				fixed: true // Make it fixed so it can be hovered over
				},
				style: { 
				width: { min: 50 },
				width: { max: 400 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: {
					width: 5,
					radius: 5,
				color: '#A2D959'
				},
				tip: 'bottomMiddle',
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
				}
			});
		});
		//end function 2
		
		// function 3
		$('#smi2 a').each(function()
		{
			$(this).qtip(
			{
			content: 'share on twitter', // Give it some content
			prerender: true,
			delay: 0,
			position: {
			corner: { target: 'topMiddle', tooltip: 'bottomMiddle' },
			adjust: { x: 0, y: -8 }
		},
			hide: {
				fixed: true // Make it fixed so it can be hovered over
				},
				style: { 
				width: { min: 50 },
				width: { max: 150 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: {
					width: 5,
					radius: 5,
				color: '#A2D959'
				},
				tip: 'bottomMiddle',
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
				}
			});
		});
		//end function 3
		
		// function 4
		$('#smi3 a').each(function()
		{
			$(this).qtip(
			{
			content: 'share on myspace', // Give it some content
			prerender: true,
			delay: 0,
			position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { x: 0, y: -8 }
		},
			hide: {
				fixed: true // Make it fixed so it can be hovered over
				},
				style: { 
				width: { min: 50 },
				width: { max: 150 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: {
					width: 5,
					radius: 5,
				color: '#A2D959'
				},
				tip: 'bottomMiddle',
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
				}
			});
		});
		//end function 4

		// function 5
		$('#smi4 a').each(function()
		{
			$(this).qtip(
			{
			content: 'share via email',
			prerender: true,
			delay: 0,
			position: {
			corner: { target: 'topMiddle', tooltip: 'bottomMiddle' },
			adjust: { x: 0, y: -8 }
		},
			hide: {
				fixed: true
				},
				style: { 
				width: { min: 50, max: 150 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: { width: 5,	radius: 5, color: '#A2D959'	},
				tip: 'bottomMiddle',
				name: 'dark'
				}
			});
		});
		//end function 5
		
		// function 5
		$('#legalpop').each(function()
		{
			$(this).qtip(
			{
			content: 'TWITTER and the "T" logo are trademarks of Twitter, Inc. FACEBOOK and the "F" logo are trademarks of Facebook, Inc. Neither Twitter nor Facebook are affiliated with, associated with, or sponsors of Fizziology, LLC or the Fizziology service.',
			prerender: true,
			delay: 0,
			position: {
			corner: { target: 'topMiddle', tooltip: 'bottomMiddle' },
			adjust: { x: 0, y: -8 }
		},
			hide: {
				fixed: true
				},
				style: { 
				width: { min: 250, max: 450 },
				padding: 5,
				background: '#A2D959',
				color: 'black',
				textAlign: 'center',
				border: { width: 5,	radius: 5, color: '#A2D959'	},
				tip: 'bottomMiddle',
				name: 'dark'
				}
			});
		});
		//end function 5
		
			$('.negative').each(function()
			{

				$(this).qtip(
				{
				content: $(this).children('img:first').attr('alt'),
				prerender: true,
				delay: 0,
				position: {
				corner: { target: 'topRight', tooltip: 'bottomLeft' },
				adjust: { x: -6, y: 6 }
			},
				hide: {
					fixed: true
					},
					style: { 
					width: { min: 190, max: 200 },
					padding: '0 0 0 38px',
					'font-size': '11px',
					'line-height': '17px',
					background: '#E4008C url(/images/tooltip_moods.png) no-repeat -200px 0',
					color: '#fff',
					textAlign: 'left',
					border: { width: 1,	radius: 9, color: '#E4008C'	},
					tip: 'bottomLeft',
					name: 'dark'
					}
				});
			});
			
			$('.positive').each(function()
			{
				$(this).qtip(
				{
				content: $(this).children('img:first').attr('alt'),
				prerender: true,
				delay: 0,
				position: {
				corner: { target: 'topRight', tooltip: 'bottomLeft' },
				adjust: { x: -6, y: 6 }
			},
				hide: {
					fixed: true
					},
					style: { 
					width: { min: 190, max: 200 },
					padding: '0 0 0 38px',
					'font-size': '11px',
					'line-height': '17px',
					background: '#5fa136 url(/images/tooltip_moods.png) no-repeat 0 0',
					color: '#fff',
					textAlign: 'left',
					border: { width: 1,	radius: 9, color: '#5fa136'	},
					tip: 'bottomLeft',
					name: 'dark'
					}				
				});
				
				
			});
		
		// Products navigation
		$('li#pro1 a, li#pro2 a, li#n1 a, li#n2 a, li#n3 a, #ft_nav2 li a[href$="#page_contact"], , #ft_nav2 li a[href$="#page_about"], #dld_fizztrack a, #fizzcheck_download a, #lc_featured a, #member_text a').bind('click', function(e)
		{	
			e.preventDefault();
			showPage($(this).attr('href').replace('page_', ''));
		})
		
	});
	
function showPage(page)
{
	// Hide all pages
	$('div.page:visible').hide();
	// Show page
	$(page).show();
	
	$('#products li a.selected').removeClass('selected');
	$('#products li a[href$="'+page.replace('#', '#page_')+'"]').addClass('selected');
	
	if(page != '#fizz10')
		window.document.location.hash = page.replace('#', '#page_');
	else if(window.document.location.hash != '')
		window.document.location.hash = '';
	
	$('#lc_main, #lc_about, #lc_sub1, #lc_sub2, #lc_sub3, #lc_sub4, #lc_about_alt, #lc_featured, #lc_login').hide();

	// Switch statement for sidebar?
	switch(page)
	{
		case '#featured':
		case '#contact':
			$('#lc_about').show();
			break;
		case '#movietracker':
			$('#lc_login').show();			
			$('#lc_about_alt').show();
		case '#talenttracker':
			$('#lc_about_alt').show();
			break;
		case '#about':
		case '#press':
		case '#fizz_pa':
			break;
		case '':
		case '#fizz10':
			$('#lc_main').show();
			$('#lc_featured').show();
			$('#lc_sub1, #lc_sub2, #lc_sub3, #lc_sub4').show();
			break;
		default:
			$('#lc_main').show();
			$('#lc_featured').show();
			break;
	}
}