// WELCOME SCREEN
function displayPage() {
$("body").fadeIn(2000);
}

window.addEventListener("load", displayPage, false);
window.addEventListener("unload", displayPage, false);

$(document).ready(function()
{
	$('.hello').addClass('fixed');
	   
   $('.hello').toggle(
   function()
   {
      $('.hello').animate({
      	top: '+=50%',
      	left: '+=50%',
      	height: '0px',
      	width: "0px"
   }, 700);

$.cookie('welcome', 'welcomeclicked', { path: '/', expires: 60 * 100 });   
$('.hello').removeClass('fixed');   
   
   },
   function()
   {
      $('.hello').animate({
      	top: '-=161px',
      	left: '-=560px',      	
      	height: '100%',
      	width: "100%"
   }, 500);
    
$('.hello').addClass('fixed');   

   });
   
// COOKIES
    var welcome = $.cookie('welcome');

    if (welcome == 'welcomeclicked') {
      $('.hello').animate({
      	top: '+=400px',
      	left: '+=60px',
      	height: '0px',
      	width: "0px"
   }, 0);
   
$('.hello').removeClass('fixed');    
    };   
   
});


// TRANSITIONS
$(document).ready(function() {
    $("body").css("display", "none");
    
    $("body").fadeIn(500);

	$(".caseclick, #header h1 a, ul.subnav li a , .previouspost a, .nextpost a, a.homebutton, a.single").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
				
	$("body").fadeOut(500, redirectPage);
		
	});

	function redirectPage() {
		window.location = linkLocation;
	}
});

// SCROLL TO TOP
$(document).ready(function(){ // run this code on page load (AKA DOM load)

			/* set variables locally for increased performance */
			var scroll_timer;
			var displayed = false;
			var $message = $('#message');
			var $window = $(window);
			var top = $(document.body).children(0).position().top;

			/* react to scroll event on window */
			$window.scroll(function () {
				window.clearTimeout(scroll_timer);
				scroll_timer = window.setTimeout(function () { // use a timer for performance
					if($window.scrollTop() <= top) // hide if at the top of the page
					{
						displayed = false;
						$message.fadeOut(500);
					}
					else if(displayed == false) // show if scrolling down
					{
						displayed = true;
						$message.stop(true, true).fadeIn(500).click(function () { $message.fadeOut(500); });
					}
				}, 100);
			});
			
			$('#message').click(function(e) { 
				e.preventDefault();
				$.scrollTo(0,300); 
			   });
			   
			$('#contact').click(function(e) { 
				e.preventDefault();
				$.scrollTo('#footer',300); 
			});   
		});

// WELCOMEBOX
$(document).ready(function() {

	$(".closewelcome").click( function() {
					
		$(".welcome").fadeOut('slow');
		
	});
	
});


// IMG SCROLLER
$(document).ready(function() {

	$("div.cj_image_flipbox_block").cjImageFlipBox({
	   debug: false
	});
	
});

// IMG SCROLLER RESET
$(document).ready(function() {
	$("div.cj_image_flipbox_block").mouseout(function (e) {
		var self = this;
			$(self).find("div.cj_image_flipbox_pics img.cj_image_flipbox_img").attr({
				"src": self.imgs[0].src
			});
	});
});

//MENU HOVERS
$(function(){
   $(".cvbutton").hover(
        function(){
            $("#menu").css('background-position', '0 -70px');
        },
        function(){
            $("#menu").css('background-position', '0 0');
        }        
    );
   $(".cvbutton").mousedown(
        function(){
            $("#menu").css('background-position', '0 0');
        }             
    );  
   $(".cvbutton").mouseup(
        function(){
            $("#menu").css('background-position', '0 -70px');
        }             
    );        
});

$(function(){
   $(".followbutton").hover(
        function(){
            $("#menu").css('background-position', '0 -140px');
        },
        function(){
            $("#menu").css('background-position', '0 0');
        }        
    );
   $(".followbutton").mousedown(
        function(){
            $("#menu").css('background-position', '0 0');
        }             
    );  
   $(".followbutton").mouseup(
        function(){
            $("#menu").css('background-position', '0 -140px');
        }             
    );      
});

$(function(){
   $(".blogbutton").hover(
        function(){
            $("#menu").css('background-position', '0 -210px');
        },
        function(){
            $("#menu").css('background-position', '0 0');
        }        
    );
   $(".blogbutton").mousedown(
        function(){
            $("#menu").css('background-position', '0 0');
        }             
    );  
   $(".blogbutton").mouseup(
        function(){
            $("#menu").css('background-position', '0 -210px');
        }             
    );      
});

$(function(){
   $(".contactbutton").hover(
        function(){
            $("#menu").css('background-position', '0 -280px');
        },
        function(){
            $("#menu").css('background-position', '0 0');
        }        
    );
   $(".contactbutton").mousedown(
        function(){
            $("#menu").css('background-position', '0 0');
        }             
    );  
   $(".contactbutton").mouseup(
        function(){
            $("#menu").css('background-position', '0 -280px');
        }             
    );      
});


$(document).ready(function(){

	$(".casebutton").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$("ul.subnav").hover(function() {
		}, function(){
			$("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});
	});

});
