/*
 
  Things to do.
  
  Make the content holder resize to the size of the content..
  
  Nest a div that will resize automatically with the content then take it parameteres to resize the main content.
  Use the infintry height resize as an example of how this is done. Take out the slide down and add a overflow: hidden to the .introStuff div.
  
  make it resize width and height
*/

jQuery.fn.introOverlay = function(options){
 
// setting varibles
   
    var defaults =  {
        introLength: 10000,
        transitionSpeed: 700,
        introAutoFade: true,
        introCloseBtn: true,
        introTransition: 'fade',
        openAnimation: true,
        cookieActive: true,
        introContent: '#intro',
        introTemplate: 'full',
        introTurnOffLights: false,
        $this: $(this)
    };
    
    
    var options = $.extend(defaults, options),
        timer = window.setTimeout,
        introMain = "#introContainer",
        introEverything = "#introOverlay, #introContainer, #introContent, #introClose",
        introContent = $(options.introContent).html();
        

    
    // cookies enabled/disabled
       
    if (options.cookieActive){
        
        var introCookie = $.cookie('introCookie'),
        $cookieCreate = $.cookie('introCookie','viewed',{expires : 0});
        
    } 


   
    
        
    if(introCookie != 'viewed'){
        
        //create the intro elements
        
        if(options.introTemplate == 'full'){
	$('#flashMov').hide();
        $('body').append('<div id="introOverlay"><div id="introContainer"><div id="introContent">' + introContent + '</div></div></div>');
        $(introMain).addClass('introContainerColor');
        }
            
        
     
        
        // intro auto fade
        if(options.introAutoFade){
            
            // timing on transition
        
             autoTimer = timer(function(){
                    transition();
                    timer(function(){
                        $(introEverything).remove();
                    },options.transitionSpeed);
            },options.introLength);

	    timer(function(){

            $('#flashMov').show();
             

	    },options.introLength + options.transitionSpeed +100);
            
        }
        
        
        $(introMain).addClass('introDefaultPositions introDefaultDimensions');
        
        // close btn functions
        
        if (options.introCloseBtn){
            
            
            
            //transition on click
            
            $(introEverything).bind('click', function(){
                
                transition();
                
                timer(function(){
                    
                    $(introEverything).remove();
                    
                    if(options.introAutoFade == true){
    
                        clearTimeout(autoTimer);
                        
                    }

                
                },options.transitionSpeed);
                
                 
                
            
                
            });
            
            
        }
        
 
        
        
        function transition(){
            
        
        var main = $(introMain),
            speed = options.transitionSpeed,
            transition = options.introTransition,
            opTran = main.is(':hidden'),
            temp = options.introTemplate,
            con = $('#introContent');
 
            
    
        
            if(transition == 'fade'){
                
            
                    
                    $('#introContent, #introContainer').fadeOut(speed);
                    $cookieCreate
                    
                }
                
            
                  
            
            

        }
        

    
    }

    timer(function(){

        if($('#introContent').size() === 0){

        $('#flashMov').show();

	}


    },100);

    
    
}

