EOW = {};
EOW.UI = {};

EOW.UI.Global = function() {
    
    var init = function() {
        
        // Image gallery
        $("#media .image a").fancybox();
        $("a.fancybox").fancybox({
            'titlePosition': 'inside',
            'transitionIn': 'elastic',
            'transitionOut': 'elastic'
        });
        
        
        // Videos
        if ($(window).width() > 680) {
            // YouTube
            $("a.youtube").click(function() {
            	//console.log("clicked...");
            	$.fancybox({
            		'padding'		: 0,
            		'autoScale'		: false,
            		'transitionIn'	: 'none',
            		'transitionOut'	: 'none',
            		'title'			: this.title,
            		'width'		    : 680,
            		'height'		: 495,
            		'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            		'type'			: 'swf',
            		'swf'			: {
            		   	'wmode'		: 'transparent',
            			'allowfullscreen'	: 'true'
            		}
            	});
            	return false;
            });
        }
        
        // Fade signup-message
        setTimeout(function() { 
            $('#signupSuccess').fadeOut(500, function() { 
                $('#signupSuccess').css("position", "relative").show();
            }); 
        }, 10000); // Fade out after 10s

        // Local menu
        hijack_links();
        
    };
    
    var hijack_links = function() {
		$('a').click(function(e){
			var self = $(this);

			if (self.attr('href').indexOf('#')==0) {
				e.preventDefault();
				navigate_to(self.attr('href'));
			}
		});
	};
		
	var navigate_to = function(selector) {
		//window.location.hash = selector.replace('#', '');
		$.scrollTo(selector, {
				duration: 500,
				offset: -135
		    });
		
	};    
    
    return {
    		init: init
    };
}();

$(document).ready(function() {
	EOW.UI.Global.init();
});
