$(document).ready(function() { init(); } );

function init()
{
	//front layer
    $("#frontLayer").css("visibility","visible");
    $("#frontLayer").hide();
    $("#frontLayer").height($(document).height()+30);
    
    var n = navigator.appName;
    var nv = navigator.appVersion;
    nv = nv.match(/MSIE \d+\./gi);
    nv = (nv) ? nv[0].match(/(\d)+/)[0] : 7;
    var ie6 = (n == "Microsoft Internet Explorer" && nv < 7);
    
    //show/hide front layers
    $("a.frontLayerLink").click(function() 
    {
        showFrontLayerPage(true);
		
        if ($(this).hasClass("frontLayerLinkProject"))
        {
            loadFrontLayerPage(this.href);
        }
        else
        {
            if          (this.id == 'frontLayerLinkAbout') 
            {
				showFrontLayerPage(true);
                setFrontLayerContent('<div id="frontLayerLanding" class="frontLayerContent frontLayerBorder"><div><img src="http://dollyrogers.nl/wp-content/themes/dollyrogers/media/newtext.gif" alt="Dolly Rogers is a creative agency that produces commercial work with heart and soul.We are creative strategists, concept developers, art directors, visual and interactive designers. We are next generation storytellers, inspired by the very things that make us human; our senses, our emotions and power to imagine beyond what we know."/></div></div>');
            }
            else if     (this.id == 'frontLayerLinkContact') 
            {
				showContactLayer();
			}

        }
        return false;
    });

	//close front layer
    $("#frontLayerClose a").click(function()
    {
		document.location.hash = "";
        hideFrontLayerPage(true);
        return false;   
    });
            
    //sidebar scroll
	sidebarHeight =  $("#sidebar").height();
    //if (!ie6) moveSidebar().move(); 
   
}

function showFrontLayerPage(tween )
{
    $(".hasFlash").hide();
    
    $("#frontLayerContentLoader").empty();
    
    var scrollTime = $(window).scrollTop() / 2;
    $('html,body').animate({scrollTop:0}, scrollTime); 

    sidebarScrollSpeed = 1;
    
    
    if (tween) 
    {
        $("#frontLayer").fadeIn(300, function() { sidebarScrollSpeed = 12 } );
    }
    else
    {
        $("#frontLayer").show();
    }
}

function hideFrontLayerPage(tween)
{
    $(".hasFlash").show();
    if (tween) $("#frontLayer").fadeOut(600); else $("#frontLayer").hide();
}

function setFrontLayerContent(htmlContent)
{
    $("#frontLayerContentLoader").html(htmlContent);
    $("#frontLayerClose").css("margin-left", $("#frontLayerContentLoader div").width()/2 - 15 + "px");
    
     
    delayedFrontLayerContentTween(); 
    
    $("a.frontLayerSelfClose").click(function()
    {
        hideFrontLayerPage(true);
        return false;   
    });
}

function delayedFrontLayerContentTween(reverse)
{
    
    $("#frontLayerContentLoader > div > div").hide();

    if (reverse) 
    {
        $("#frontLayerContentLoader > div > div").reverse().delay(450).each(function(i) {
            //$(this).delay(i*550).fadeIn(250);
            $(this).delay(i*400).slideDown(250);
        });
    }
    else
    {
        $("#frontLayerContentLoader > div > div").delay(450).each(function(i) {
            $(this).delay(i*400).slideDown(250);
        });
    }
    


}

