Cufon.replace('.container h2, .container h3');

var the_window = $(window);
$.setupJMPopups({
	
					screenLockerBackground: "#0f0f0e",

					screenLockerOpacity: "0.92"

				});



				function openStaticPopup() {

					$.openPopupLayer({

						name: "StaticPopup",

						width: 380,

						target: "contactDiv"

					});
                    
                    $('.popup').html(replacedContact);
                    Cufon.replace('.popup h2, .popup h3', {hover: true, hoverables: {a: true}});

				}
                
                function closePopup() {
                 $.closePopupLayer();
                 }                        
                                
                function openErrorPopup() {

					$.openPopupLayer({

						name: "StaticPopup",

						width: 380,

						target: "errorDiv"

					});
                    
                    //$('.popup').html(replacedError);
                    Cufon.replace('.popup h2, .popup h3', {hover: true, hoverables: {a: true}});

				}                        		
                
    var replacedContact;
   // var replacedError;
	$(document).ready(function() {
							   
							   
		replacedContact = $('#contactDiv .popup').html();
        //replacedError = $('#errorDiv .popup').html();

		   
		
		$('.noJSMenu').removeClass('noJSMenu');
		$('.top > a').removeAttr("href");//.css({cursor: 'pointer'});
		
		
		var originalSelected = $('.top').children('.selected');
		var menu = $('#menu');
		var big = false;
		var over = false;
		$('.top').children('div').hide();
		
		
		$('.top').click(function() {
			
			if ($(this).children('.openMenu').size() > 0)
				return;
			
			if (!over || !big)
				return;
			
			originalSelected.removeClass('selected');
			$('.openMenu').hide(500).removeClass('openMenu');					 
			$(this).children('div').addClass('openMenu');					 
			
			if (!big) {
				big = true;
				var boo = $(this);
				menu.animate({width: 380}, 500, function () {
															boo.children('div').show(500);
															});
			} else {
				$(this).children('div').show(500);
			}
		});
		
		menu.mouseover(function() {
			over = true;
			
			menu.stop(true, true);
			
			menu.animate({paddingLeft: 10}, 200, function() {
				if (!big && over) {
					big = true;
					menu.animate({width: 380}, 500, function() {
						$('.selected + div').show(500).addClass('openMenu');
					});
				}
			});
		});
		
		menu.mouseleave(function() {
			over = false;
			
			menu.stop(true, true);
			menu.animate({paddingLeft: 10}, 500, function() {
				if (big && !over) {
						
						$('.openMenu').stop(true, true).hide(500).removeClass('openMenu');
			
				
						$('.top').children('div').hide(500, function() {
						menu.animate({width: 140}, 500, function() {big = false;});
						originalSelected.addClass('selected');
						
					});
				}
			});
			
		});
		
	});
	
	
	the_window.scroll(function() {
		var menu = $('#menu');
		var originalOffset = 290;
		var topSpacing = 52;
		var off = 0;
		if (the_window.scrollTop() < originalOffset - topSpacing) {
			off = originalOffset;
			if ($.browser.msie && $.browser.version == "6.0") {
				menu.css('top', off);
			} else {
				menu.css({
						'position': 'absolute',
						'top' : originalOffset,
						'left' : 0
						});	
			}
		}
		else {
			off = the_window.scrollTop() + topSpacing;
			if (($.browser.safari) || ($.browser.msie && $.browser.version == "6.0")) {
				menu.css('top', off);
			} else {
				menu.css({
						'position': 'fixed',
						'top' : topSpacing,
						'left' : (the_window.width()-960)/2
						});
			}
		}
		
	});
