$(function()
{

	var Home_Content_List = $('ul#home_content_list');
	Home_Content_List.slideShow({delay:7000, transSpeed:2000}).startSlides();
	
	var Home_Logos_List = $('ul#logos');
	Home_Logos_List.slideShow({delay:7000, transSpeed:1000}).startSlides();
	
	var Marquee_Text = $('span#marquee span.outer');
	var Inner_Marquee_Text = $('span.inner', Marquee_Text);
	var News_Read_More_Link = $('a#news_read_more');
	var Marquee_Count = 0;
	var Marquee_Move_Distance = 1;
	var Marquee_Callback_Speed = 15;
	//var Marquee_Callback_Speed = 5;
	
	var Marquee_Width = 0;
	
	Inner_Marquee_Text.each(function()
	{
		Marquee_Width += Inner_Marquee_Text.width();
		
		Marquee_Count += 1;
		
		$(this).css(
		{
			'position':'absolute',
			'top':'0px',
			'left': Marquee_Width + 'px'
		});
	});
	
	var Timer_Callback = function()
	{
		var marquee_position = Marquee_Text.position();
		
		var moved_position = marquee_position.left - Marquee_Move_Distance;

		var current_index = Math.floor( (moved_position*-1) / Marquee_Text.width() );
		
		var count_inner = 0;
		
		Inner_Marquee_Text.each(function(){
			if(current_index == count_inner)
			{
				var current_url = $(this).attr('rel');
			
				News_Read_More_Link.attr('href',current_url);
			}
			count_inner += 1;
		});
		
		if((moved_position*-1) > (Marquee_Text.width() * Marquee_Count))
		{
			moved_position = 0;
		}
		
		Marquee_Text.css({'left': moved_position +'px'});
		
	}	
	
	var Timer = setInterval(Timer_Callback, Marquee_Callback_Speed);
	
	var Dot_Links = $('a.dot_links');
	
	Dot_Links.click(function()
	{
		var dot_css = $(this).attr('class');
		
		var dot_css_classes = dot_css.split(' ');
		
		if(dot_css_classes[0] != '')
		{
			var number_clicked_array = dot_css_classes[0].split('_');
			
			if(number_clicked_array[2])
			{
				var current_clicked_number = (number_clicked_array[2] - 1);

				Home_Content_List.stopSlides();
				
				Home_Content_List.stopSlides().changeSlide(current_clicked_number);
			}
		}
	});
	
	$('ul#navigation_main li.tier1').hover(function()
	{
		if($.browser.msie && $.browser.version.substr(0,1)<7)
		{	
			if($(this).attr('id') == 'nav_company')
			{
				$(this).css({'background-position':'0px 0px'});
			}
			else if($(this).attr('id') == 'nav_team')
			{			
				$(this).css({'background-position':'-71px 0px'});
			}
			else if($(this).attr('id') == 'nav_portfolio')
			{
				$(this).css({'background-position':'-122px 0px'});
			}
			else if($(this).attr('id') == 'nav_investor_relations')
			{
				$(this).css({'background-position':'-190px 0px'});
			}
			else if($(this).attr('id') == 'nav_news_events')
			{
				$(this).css({'background-position':'-308px 0px'});
			}
			else if($(this).attr('id') == 'nav_contact')
			{
				$(this).css({'background-position':'-410px 0px'});
			}
			
			$('ul.navigation_tier2', $(this)).show();
			
			$('ul.navigation_tier2 li.tier2', $(this)).hover(function()
			{
				$('a', $(this)).css({'color':'#FFFFFF', 'text-decoration':'none', 'background-color':'#9eb3a9'});

				if($('ul.navigation_tier3', $(this)).length>0)
				{
					$('a', $('ul.navigation_tier3', $(this))).css({'color':'#7d7d7d', 'text-decoration':'none', 'background-color':'#ffffff'});
					
					$('ul.navigation_tier3', $(this)).show();
					
					$('ul.navigation_tier3 li.tier3', $(this)).hover(function()
					{
						$('a', $(this)).css({'color':'#FFFFFF', 'text-decoration':'none', 'background-color':'#9eb3a9'});
						
						if($('ul.navigation_tier4', $(this)).length>0)
						{
							$('a', $('ul.navigation_tier4', $(this))).css({'color':'#7d7d7d', 'text-decoration':'none', 'background-color':'#ffffff'});
							
							$('ul.navigation_tier4', $(this)).show();
							
							$('ul.navigation_tier4 li.tier4', $(this)).hover(function()
							{
								$('a', $(this)).css({'color':'#FFFFFF', 'text-decoration':'none', 'background-color':'#9eb3a9'});
							},
							function()
							{
								$('a', $(this)).css({'color':'#7d7d7d', 'text-decoration':'none', 'background-color':'#ffffff'});
							});							
						}
					}, 
					function()
					{	
						$('a', $(this)).css({'color':'#7d7d7d', 'text-decoration':'none', 'background-color':'#ffffff'});
						
						if($('ul.navigation_tier4', $(this)).length>0)
						{
							$('ul.navigation_tier4', $(this)).hide();
						}
					});
				}
			},
			function()
			{
				$('a', $(this)).css({'color':'#7d7d7d', 'text-decoration':'none', 'background-color':'#ffffff'});
				
				if($('ul.navigation_tier3', $(this)).length>0)
				{
					$('ul.navigation_tier3', $(this)).hide();
				}				
			});
		}
	},
	function()
	{
		if($.browser.msie && $.browser.version.substr(0,1)<7)
		{	
			if($(this).attr('id') == 'nav_company')
			{
				$(this).css({'background-position':'0px -35px'});
			}
			else if($(this).attr('id') == 'nav_team')
			{		
				$(this).css({'background-position':'-71px -35px'});
			}
			else if($(this).attr('id') == 'nav_portfolio')
			{
				$(this).css({'background-position':'-122px -35px'});
			}
			else if($(this).attr('id') == 'nav_investor_relations')
			{
				$(this).css({'background-position':'-190px -35px'});
			}
			else if($(this).attr('id') == 'nav_news_events')
			{
				$(this).css({'background-position':'-308px -35px'});
			}
			else if($(this).attr('id') == 'nav_contact')
			{
				$(this).css({'background-position':'-410px -35px'});
			}
			
			$('ul.navigation_tier2', $(this)).hide();
		}	
	});
	
	
	var Investor_Relations_SideBar_More_Link = $('div#sidebar_investor_relations span#sidebar_more_link');
	
	var Investor_Relations_SideBar_Close_Link = $('div#sidebar_investor_relations span#sidebar_close_link');
	
	var Investor_Relations_SideBar_More_Content = $('div#sidebar_investor_relations span#sidebar_investor_relations_secondary_content');
	
	Investor_Relations_SideBar_More_Link.click(function()
	{
		Investor_Relations_SideBar_More_Content.show();
		
		Investor_Relations_SideBar_Close_Link.show();
		
		$(this).hide();
	});
	
	Investor_Relations_SideBar_Close_Link.click(function()
	{
		Investor_Relations_SideBar_More_Content.hide();
		
		Investor_Relations_SideBar_More_Link.show();
		
		$(this).hide();
	});
	
	var Toggle_Content = $('.toggle_content');
	
	Toggle_Content.click(function()
	{
		var parent = $(this).parent();
		
		var toggle_object = $('.toggle_content_object', parent);
		
		if(toggle_object.is(':visible'))
		{
			$(this).empty().append('&raquo; More');
			
			toggle_object.hide();
		}
		else
		{
			$(this).empty().append('&raquo; Close');
			
			toggle_object.show();
		}
		
		return false;
	});
});
