
	/** add_page_load_event.js allows us to run one or multiple functions on page load
	The advantage of this funtion is it won't override any previously set onload functions,
	and also that it will trigger at the point of HTML being ready, rather than waiting for every image to load */
	
	var page_url = false;
	
	/** Code to run on page load, including image rollovers and anything else fancy */
	function page_setup()
	{
		setupHeadings();
		setupLavalamp();
		
		setupSexyButtons();
		setupIconLinkList();
		setupFindUsLinks();
		
		setupShareLinks();
	}

	function setupSexyButtons()
	{
		$('.sexybutton')
		
		.hover(
			function(){
				$(this).addClass('sexybutton_over');
			},
			function(){
				$(this).removeClass('sexybutton_over');
				$(this).removeClass('sexybutton_down');
			}
		)
		.bind( 'mousedown', function(){
		
			$(this).addClass('sexybutton_down');
		
		})
		.bind( 'mouseup', function(){
		
			$(this).removeClass('sexybutton_down');
		
		});
		
	}

	function setupIconLinkList()
	{
		//if( isIE6() )
		if( true )
		{
			$('.iconlinklist').each(
				function()
				{
					if( $(this).hasClass('iconlinklist-nolink') )
					{
						$('ul>li', $(this)).each( function(){
						
							$(this).data('oldclass', $(this).attr('className').split(' '));
						
						});
						$('ul>li', $(this)).hover(function(){
						
							$('span', $(this)).css({'marginRight': 0,'paddingRight': 30 });
							$(this).addClass('over');
							
							for( var i in $(this).data('oldclass') )
							{
								$(this).addClass($(this).data('oldclass')[i]+'_over');
							}
							//$(this).addClass($(this).data('oldclass')+'_over');
							
						},function(){
						
							$('span', $(this)).css({'marginRight': 10,'paddingRight': 20 });
							$(this).removeClass('over');
							
							for( var i in $(this).data('oldclass') )
							{
								$(this).removeClass($(this).data('oldclass')[i]+'_over');
							}
							//$(this).removeClass($(this).data('oldclass')+'_over');
						
						});
					}
					else
					{
						$('ul>li>span>a', $(this)).hover(function(){
						
							$(this).css({'marginRight': 0,'paddingRight': 30 });
							
						},function(){
						
							$(this).css({'marginRight': 10,'paddingRight': 20 });
						
						});
					}
				}
			);
		}
		else
		{
			$('.iconlinklist').each(
				function()
				{
					if( $(this).hasClass('iconlinklist-nolink') )
					{
						$('ul>li', $(this)).each( function(){
						
							//$(this).data('oldclass', $(this).attr('className'));
							$(this).data('oldclass', split(' ', $(this).attr('className')));
						
						});
						$('ul>li', $(this)).hover(function(){
						
							$('span', $(this)).animate({'marginRight': 0,'paddingRight': 30 });
							$(this).addClass('over');
							//$(this).addClass($(this).data('oldclass')+'_over');
							
							for( var i in $(this).data('oldclass') )
							{
								$(this).addClass($(this).data('oldclass')[i]+'_over');
							}
							
						},function(){
						
							$('span', $(this)).animate({'marginRight': 10,'paddingRight': 20 });
							$(this).removeClass('over');
							//$(this).removeClass($(this).data('oldclass')+'_over');
							
							for( var i in $(this).data('oldclass') )
							{
								$(this).removeClass($(this).data('oldclass')[i]+'_over');
							}
						
						});
					}
					else
					{
						$('ul>li>span>a', $(this)).hover(function(){
						
							$(this).animate({'marginRight': 0,'paddingRight': 30 });
							
						},function(){
						
							$(this).animate({'marginRight': 10,'paddingRight': 20 });
						
						});
					}
				}
			);
		}
	}

	var menu_timeout = false;
	
	function setupLavalamp()
	{
		/** lava lamp */
		$(".mainmenu").lavaLamp({
			fx: 'linear',
			speed: 300
		});
		
		/** dropdown menus */
		$('.mainmenu>li').each( function(){
		
			var menuItem = $(this);
			
			var submenus = $('>ul', $(menuItem) );
			
			if( submenus.length > 0 )
			{
				$( menuItem ).hover( function(){
				
					if( menu_timeout ) clearTimeout( menu_timeout );
					$('>ul:hidden', $( menuItem )).stop().fadeIn();
					$('.mainmenu>li>ul').not($( submenus )).hide();
				
				}, function(){
				
					menu_timeout = setTimeout( function(){ $( '>ul', $( menuItem ) ).stop().fadeOut(); }, 500 );
				
				});
			}
		
		});
	}

	function setupHeadings()
	{
		$('.content h1, .panel h2').each(
			function()
			{
				$(this).addClass( 'withGradient' );
				$(this).html( '<span class="trans gradient"></span>'+$(this).html() );
				$('.gradient', $(this)).css({ 
					'width' : $(this).attr('scrollWidth') 
					,'height' : $(this).attr('scrollHeight')
				});
			}
		);
	}

	function setupFindUsLinks()
	{
		if( isIE6() )
		{
			$('.footer-wrapper .footer .right .find-us-links ul li').hover(
				function(){
					
					$('.icon', $(this)).css({ top: 0 });
					$('.reflect', $(this)).css({ top: 73 });
					
				},
				function(){
					
					$('.icon', $(this)).css({ top: 10 });
					$('.reflect', $(this)).css({ top: 63 });
				}
			);
			return false;
		}
		$('.footer-wrapper .footer .right .find-us-links ul li').hover(
			function(){
				
				$('.icon', $(this)).animate({ top: 0 });
				$('.reflect', $(this)).animate({ top: 73 });
				
			},
			function(){
				
				$('.icon', $(this)).animate({ top: 10 });
				$('.reflect', $(this)).animate({ top: 63 });
			}
		);
	}

	function setupShareLinks()
	{
		$('.sharelinks li').click( function(){
		
			return social.share( $(this).attr('className') );
		
		});
	}
	
	function isIE6()
	{
		return ( $.browser.msie !== false && $.browser.version == '6.0' );
	}

	$(document).ready( page_setup );
