function homemenu(){
	
	var mobile = false;
	if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) mobile = true;								   
	
	function init(obj){ 
		var ul = $('ul',obj);
		var total = $('li',ul).length;
		var i = 1;
		//var limit = 10;
		$('li',ul).show(); 

		if(mobile){
			limit = 9;	
			if (total > limit){
				$(obj).append('<p class="controls"><span class="next">next</span><span class="prev">prev</span></p>');						
				var next = $('.controls .next',obj);
				var prev = $('.controls .prev',obj);
				$(prev).css('opacity',0);
				if(mobile){
					$('.controls',obj).addClass('mobile');
					$(prev).addClass('mobile');
					$(next).addClass('mobile');
					$('<span class="close mobile">close</span>')
						.appendTo('.controls',obj)
						.mouseup(function(){
							close(obj);
						});
				};
				$(next).click(function(){
					if((total-i) > (limit-1)) {
						$('li:nth-child('+ i +')',ul).slideUp(); 	
						i++;		
						$(prev).css('opacity',1);
						if((total-i) == (limit-1)) $(this).css('opacity',0);
					}
				});
				$(prev).click(function(){
					if(i > 1) {
						i--;
						$('li:nth-child('+ i +')',ul).slideDown(); 	
						$(next).css('opacity',1);
						if(i==1) $(this).css('opacity',0);
					} 
				});
				
			};	
		} else {
			var top = 0;
			$(obj).mousemove(function(e){
				var fixh = 249;			  
				var objh = $(obj).height();
				top = (e.pageY - $(this).offset().top) - 50;			
				$(obj).scrollTop(top);
			});									
		};
		
	};
	function close(obj){
		$('.controls',obj).remove();
		$('li',obj).hide();
		if(!mobile)$(obj).scrollTop(0);
	};
	if(mobile){
		$('#sectionNav div').click(function(){
			if(!($('li:last-child',this).is(':visible'))) init(this);
		});	
	} else {
		$('#sectionNav div').hover(
			function(){init(this);},					   
			function(){close(this);}	
		);	
	};
};	
	
	
function insidemenu(){

	var mobile = false;
	if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) mobile = true;								   
	$('#internalNav').append('<ul class="buttons"></ul>');
	$('#internalNav h1').each(function(i){
		var parent = $(this).parent();
		var buttons = $('.buttons', parent);
		var title = $(this);
		var ul = $(this).next();
		$(title).hide(); $(ul).hide();
		$('<li class="button'+ (i+1) +'"><span>'+ $(this).html() +'</span></li>').appendTo(buttons).click(function(){
			if(!($(title).is(':visible'))){
				$('h1, .nav', parent).hide();
				$(title).fadeIn();
				$(ul).fadeIn();
			} else {
				$(title).fadeOut();
				$(ul).fadeOut();
			};
		});
	});
	$('<li class="button6"><span>Home</span></li>').appendTo('#internalNav .buttons').click(function(){
		window.location.replace("/");
	});

};	

function newsreader(){
	
	var selector = '#newsReader ul';
	var initPause = 0;
	var pause = 6000;
	var numericId = 'nr_pagination';
	
	$(selector).each(function(){
				
		var obj = $(this);								
		var length = $(obj).children().length;
		var temp = 0;
		var prev = -1;
		var z = 1;
		var h = $(':nth-child(1)',obj).height();
		var timeout;
		var play = true;		
		
		if(length > 1){
			
			$(obj).css('position','relative').height(h);
			$(obj).children()
				.hide()
				.css({
					'position':'absolute',
					'top':'0',
					'left':'0'
					});	
			
			$(obj).after('<ol id="'+ numericId +'"></ol>');	
			
			for(var i=0;i<length;i++){						
				$('<li></li>')
					.attr('id',numericId + (i+1))
					.html(i+1)
					.appendTo($('#'+ numericId))
					.click(function(){	
						int = parseInt($(this).html());
						if(temp != int){
							prev = temp;
							temp = int;
							show();
						};
					}); 												
			};	
			
			$('<li class="pause"></li>')
				.attr('id',numericId + '_button')
				.html('||')
				.appendTo($('#'+ numericId))
				.click(function(){
					if(play){
						play = false;
						clearTimeout(timeout);
						$(this).html('&raquo;').addClass('play');
					} else {
						play = true;
						set();
						$(this).html('||').removeClass('play');			
					}
				});
	
			function setPrev(){
				prev = (temp == 1) ? length : temp-1;  
			};
			function set(){
				temp = (temp == length) ? 1 : temp+1; 
				setPrev(); 
				show();
			};
			
			function show(){
	
				$('li','#'+ numericId).removeClass('current');
				$('li:nth-child(' + temp + ')','#'+ numericId).addClass('current');
				$('li:nth-child(' + temp + ')',obj)
					.css('z-index',z)
					.fadeIn('slow',function(){
						$('li:nth-child(' + prev + ')',obj).fadeOut();	
				});
				z++;
				clearTimeout(timeout);
				if(play) timeout = setTimeout(set,pause);	
			};
			
			timeout = setTimeout(set,initPause);	
			
		};
	
	});			

};
