var Site = {

	fullBaseUrl: null,
	isLegacyBrowser: false,

	onReady: function() {

		// Set base path
		this.fullBaseUrl = document.location.protocol + '//' + document.location.host;

		// Check for outdated browsers
		this.isLegacyBrowser = this.checkLegacyBrowser();

		for (var selector in this.elements) {
			var $elms = $(selector);

			if ($elms.size() > 0) {
				this.elements[selector]($elms);
			}
		}
	},

	checkLegacyBrowser: function() {
		switch (true) {
			case $.browser.msie:
				return parseFloat($.browser.version) < 7.0;
			case $.browser.safari:
				return parseFloat($.browser.version) < 3.0;
			case $.browser.mozilla:
				return parseFloat($.browser.version) < 1.5;
			default:
				return false;
		}
	},

	elements:
	{
			/*------------------------------------------------------
			  Start: Apply Cufon
			--------------------------------------------------------*/
			
			'.nav a':function($elms){
				Cufon.replace('.nav a',{fontFamily : 'MillerDisplay-Roman'});
			},
			'.mod.subscribe .hd':function($elms){
				Cufon.replace('.mod.subscribe .hd',{fontFamily : 'MillerDisplay-Roman'});
			},
			'.mod.description .hd':function($elms){
				Cufon.replace('.mod.description .hd',{fontFamily : 'MillerDisplay-Roman'});
			},
			'h1.archive-title':function($elms){
				Cufon.replace('h1.archive-title',{fontFamily : 'MillerDisplay-Roman'});
			},
			'h2.title':function($elms){
				Cufon.replace('h2.title',{fontFamily : 'MillerDisplay-Roman'});
			},
			'.column-2 h2':function($elms){
				Cufon.replace('.column-2 h2',{fontFamily : 'MillerDisplay-Roman'});
			},
			'.column-2 h3':function($elms){
				Cufon.replace('.column-2 h3',{fontFamily : 'MillerDisplay-Light'});
			},
			/*------------------------------------------------------
			  Start: End Cufon
			--------------------------------------------------------*/

			/*------------------------------------------------------
			  Start: Archive projects
			--------------------------------------------------------*/
                            '.grid-container .project':function($elms) {


                                var $durationIn = 400;
                                var $durationOut = 200;

                                $('.project a').hover(
                                /**
                                 *  MouseEnter
                                 */
                                function(){


                                    //find related description
                                    var $project_description = $(this).parent().parent().parent().find(".description");

                                    //reset others
                                    var descriptions  = $(".description");

                                    descriptions.each(function(){

                                        $(this).animate({
                                            opacity: 'hide'
                                        },
                                        $durationOut,
                                        'easeOutQuint'
                                    );
                                    }

                                );


                                $($project_description)
                                    .stop()
                                    .css('opacity','') // reset the css before show....
                                    .animate({
                                        opacity: 'show'
                                    },
                                    $durationIn,
                                    'easeInSine'
                                    ) ;

                            },
                            /**
                             *  MouseLeave
                             */
                            function(){
                            }
                        );

						//roll out of description
						$('.mod.description').hover(
                                /**
                                 *  MouseEnter
                                 */
                                function(){
									var $project =  $(this).parent().find(".project a span");
									$project.css("text-decoration", "underline");
								},
								/**
								 *  MouseLeave
								 */
								function(){
									   $(this).animate({ opacity: 'hide'}, $durationOut, 'easeOutQuint');
										var $project =  $(this).parent().find(".project a span");
										$project.css("text-decoration", "none");
								}
                        );


                        },
			/*------------------------------------------------------
			  End: Archive projects
			--------------------------------------------------------*/

			/*------------------------------------------------------
			  Start: Fancy Projects
			--------------------------------------------------------*/
				'.mod.project a':function($elms){

					if (!Site.isLegacyBrowser) {
						$(".grid .mod.description a").fancybox({
							'type':				'ajax',
							'titleShow'			: false,
							'scrolling'			: 'no',
							'margin'			: 31,
							'padding'			: 0,
							'speedIn'			: 1000,
							'speedOut'			: 1000,
							//'width'				: 1500,
							//'height'			: 2000,
							'centerOnScroll'	: false,
							'overlayOpacity'	: 0.9,
							'overlayColor'		: '#000',
							'autoScale'			: false,
							'transitionIn'		: 'none',
							'transitionOut'		: 'fade',
							'easingIn'			: 'easeOutBack',
							'easingOut'			: 'easeInBack',
							'changeFade'		: 'slow',
							'onStart'			: startFancy,
							'onCleanup'			: cleanupFancy,
							'onClosed'			: closeFancy,
							'onComplete'		: completeFancy
						});
					}
				},
			/*------------------------------------------------------
			  End: Fancy Projects
			--------------------------------------------------------*/
			/*------------------------------------------------------
			  Start: Fancy Nav
			--------------------------------------------------------*/
				'.nav .fancybox a':function($elms){
					if (!Site.isLegacyBrowser) {
						$(".nav .fancybox a").fancybox({
							'type':				'ajax',
							'titleShow'			: false,
							'scrolling'			: 'no',
							'margin'			: 31,
							'padding'			: 0,
							'speedIn'			: 1000,
							'speedOut'			: 1000,
							'centerOnScroll'	: false,
							'overlayOpacity'	: 0.9,
							'overlayColor'		: '#000',
							'autoScale'			: false,
							'transitionIn'		: 'fade',
							'transitionOut'		: 'fade',
							'easingIn'			: 'easeOutBack',
							'easingOut'			: 'easeInBack',
							'changeFade'		: 'slow',
							'onStart'			: startFancy,
							'onClosed'			: closeFancy,
							'onComplete'		: completeFancy
						});
					}

				},
			/*------------------------------------------------------
			  End: Fancy Nav
			--------------------------------------------------------*/

			/*------------------------------------------------------
			  Start: Grid Contact
			--------------------------------------------------------*/
				'.grid-contact a':function($elms){

					if (!Site.isLegacyBrowser) {
						$(".grid-contact a").fancybox({
							'type':				'ajax',
							'titleShow'			: false,
							'scrolling'			: 'no',
							'margin'			: 31,
							'padding'			: 0,
							'speedIn'			: 1000,
							'speedOut'			: 1000,
							'centerOnScroll'	: false,
							'overlayOpacity'	: 0.9,
							'overlayColor'		: '#000',
							'autoScale'			: false,
							'transitionIn'		: 'fade',
							'transitionOut'		: 'fade',
							'easingIn'			: 'easeOutBack',
							'easingOut'			: 'easeInBack',
							'changeFade'		: 'slow',
							'onStart'			: startFancy,
							'onClosed'			: closeFancy,
							'onComplete'		: completeFancy
						});
					}
				},
			/*------------------------------------------------------
			  End: Grid Contact
			--------------------------------------------------------*/

			/*------------------------------------------------------
			  Start: Fancy Video
			--------------------------------------------------------*/
				'.video a':function($elms){

					if (!Site.isLegacyBrowser) {
						$(".grid .video.description a").fancybox({
							//'href'			: $(this).attr('href'),
							'type':				'swf',
							'titleShow'			: false,
							'scrolling'			: 'no',
	//						'width'				: 990,
							'margin'			: 31,
							'padding'			: 0,
							'speedIn'			: 1000,
							'speedOut'			: 1000,
							//'width'				: 1500,
							//'height'			: 2000,
							'centerOnScroll'	: false,
							'overlayOpacity'	: 0.9,
							'overlayColor'		: '#000',
							'autoScale'			: false,
							'transitionIn'		: 'none',
							'transitionOut'		: 'fade',
							'easingIn'			: 'easeOutBack',
							'easingOut'			: 'easeInBack',
							'changeFade'		: 'slow',
							'onStart'			: startFancy,
							'onClosed'			: closeFancy,
							'onComplete'		: function() {

								$('#fancybox-inner object').before('<div class="video-container">');
								$('#fancybox-inner object').after('<div>');

								$("#fancybox-overlay").css({'opacity':'0'});
								$("#fancybox-inner").fadeTo("slow", 1.0, function(){});

								var contentHeight = $('#fancybox-wrap').height();
								var windowHeight = $('html').innerHeight();
								var chosenHeight = Math.max(contentHeight, windowHeight);

								$('#fancybox-wrap').css('height', chosenHeight + 'px');
								$(".container").css({'overflow ' : 'hidden', 'position' : 'fixed'});
								$("#fancybox-close ").css({'left' : '-213px'});

								}
						});

					}
				}
			/*------------------------------------------------------
			  End: Fancy Video
			--------------------------------------------------------*/
	
	}
}

$(document).ready(
	function() {
		Site.onReady();
	}
);

// Will be called right before attempting to load the content
 function startFancy() {
	//	Set window scrollbar to top
	$('html,body').attr('scrollTop', 0);

	//	Hide content
	 $("#fancybox-overlay").css({'display' : 'block', 'opacity' : '0'});
	 $("#fancybox-inner").css({'display' : 'block', 'opacity' : '0'});

	 $("#fancybox-overlay").fadeTo("slow", 0.9,
		function() {
		}
	);

		
		
 }

 function cleanupFancy() {
	 $('#fancybox-inner iframe.video-iframe').attr('src', '');
 }

 function closeFancy() {
	 $(".container").css({'overflow':'visible', 'position' : 'static'});
	 $("#fancybox-close ").css({'left' : '24px'});
 }

// Will be called once the content is displayed
 function completeFancy() {

	Cufon.replace('h1.archive-title',{fontFamily : 'MillerDisplay-Light'});	
	Cufon.replace('h2.title',{fontFamily : 'MillerDisplay-Roman'});
	Cufon.replace('.column-2 h2',{fontFamily : 'MillerDisplay-Roman'});
	Cufon.replace('.column-2 h3',{fontFamily : 'MillerDisplay-Light'});

	$("#fancybox-inner").fadeTo("slow", 1.0,
		function() {
		}
	);

	//reposition
	//$("#fancybox-wrap").css({'top':'88px'});
	var contentHeight = $('#fancybox-wrap').height();
	var windowHeight = $('html').innerHeight();
	var chosenHeight = Math.max(contentHeight, windowHeight);
	$('#fancybox-wrap').css('height', chosenHeight + 'px');
	$(".container").css({'overflow ' : 'hidden', 'position' : 'fixed'});
	//if video

}
