$(document).ready(function() {

	$('#menu-box').accordion({ 
		header: '> ul li h3', 
		event: 'click',
		fillSpace: true,
		active: '.open',
		collapsible: true
	});

	//MENU SLIDER
	//keeps the menu in view when scrolling the page
	var name = "#menu-box";  
	var menuYloc = null; 								
	menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))  
	$(name).addClass('floating');
	
	var scrollPosition = null;
	var menuPosition = null;
	
	$(window).scroll(function () {   
		
		scrollPosition = $(window).scrollTop();
		menuPosition = $('#menu-end').offset({ scroll: false }).top;
		
		if (scrollPosition >= menuPosition) {
			$(name).addClass('pinned'); //fixed
			$(name).removeClass('floating');
			$(name).css("top","0")
		}
		if (scrollPosition < menuPosition) {
			$(name).addClass('floating');
			$(name).css("top", $("#menu-end").offset);
			$(name).removeClass('pinned');
		}
		
	});
	 
	
	//Initilize the login popup - turn off autoOpen
	$('#login-popup').dialog({autoOpen: false, modal: true, show: 'blind', title: 'Focal Holdings Login'});			
	
	//prevent the normal link, popup the login popup
	$('.loginBtn').click(function(e) {
		e.preventDefault();
		$('#login-popup').dialog('open');						
	});
	
	
	

});

//SimplestSlideshow - http://snook.ca/archives/javascript/simplest-jquery-slideshow
(function($){
  $.fn.simplestSlideShow = function(settings){
    var config = {
      'timeOut': 3000,
      'speed': 'normal'
    };
    if (settings) $.extend(config, settings);
    this.each(function(){
      var $elem = $(this);
      $elem.children(':gt(0)').hide();
      setInterval(function(){
        $elem.children().eq(0).fadeOut(config['speed'])
        .next().fadeIn(config['speed'])
        .end().appendTo($elem);
      }, config['timeOut']);
    });
    return this;
  };
})(jQuery);
