jQuery(document)
    .ready(function(){

        //- Set trailers
        //-------------------------------------------//
        function setTrailers()
        {
            // Set adata
            $data               = {};
            $data["action"]     = "getTrailer";
            
            // Get value
            jQuery.post("http://" + document.location.hostname + "/json.php", $data, 
            function(data)
            {
                // Check status
                if( data.status == false )
                {
                    // Set status text
                    jQuery("#offer-rotating")
                        .animate({
                            opacity: 0
                        }, 1000, function(){
                            // Hide
                            jQuery(this)
                                .css("visibility", "hidden");                
                        })
                }
                else
                {
                    // Check visibility
                    if(jQuery("#offer-rotating").css("visibility") == "visible")
                    {
                        // Set status text
                        jQuery("#offer-rotating")
                            .animate({
                                opacity: 0
                            }, 1000, function(){
                                // Set text
                                jQuery(this)
                                    .html(data.text)
                                    .animate({
                                        opacity: 1
                                    }, 1000);                         
                            });                                               
                    }
                    else
                    {
                        // Set status text
                        jQuery("#offer-rotating")
                            .html(data.text)
                            .css({
                                visibility  : "visible",
                                opacity     : 0
                            })
                            .animate({
                                opacity: 1
                            }, 1000);
                    }
                }                
            },"json"); 
            
            // Set timeout
            $timeout = setTimeout(setTrailers, 6000);  
        }
        //-------------------------------------------//        
    
    
        //- Add timeout 
        //-------------------------------------------//
        function addTimeout()
        {
            // Check timeout value
            if($timeout == "")
            {
                setTrailers();    
            }
        }        
        //-------------------------------------------//        
        
        
        //- Delete timeout 
        //-------------------------------------------//
        function delTimeout()
        {
            // Clear timeout
            clearTimeout($timeout);
            
            $timeout = "";
        }
        //-------------------------------------------//    
        
        
        //- Check window focus or blur 
        //-------------------------------------------//
        if(/*@cc_on!@*/false) // check for Internet Explorer
        {   
            document.onfocusin  = addTimeout;
            document.onfocusout = delTimeout;
        }
        else 
        {
            window.onfocus  = addTimeout;
            window.onblur   = delTimeout;
        }
        //-------------------------------------------//        
        
        
        // Set trailers after load page
        setTrailers();        
    });

