
"use strict";

;(function( release ) {

    var json, current;

    release.prev = function() {

        if( $('*').is(':animated') )

            return false;

        var hash = ( current == undefined ) ? 0 : current;//( window.location.hash == '' ) ? 0 : window.location.hash.replace( '#', '' );

        if( hash < 1 ) {

            hash = json.object.item.length-1; 
        }

        else {

            hash -= 1;
        
        }

        var i = 0;

        $( 'h3, h4, p', '.content' ).each(function() {

            $( this ).delay( i*200 ).animate({'left':-8, 'opacity':0}, 380);

            ++i;
        
        });

        var timer = setInterval( function() {

            if( !$('*').is(':animated') ) {

                clearInterval( timer );

                $( 'h3', '.content' ).html( json.object.item[hash]['02'] ).next().html( json.object.item[hash]['03'] ).next().html( json.object.item[hash]['04'] ).next( '.link' ).html( json.object.item[hash]['05'] );

                var i = 0;

                $( 'h3, h4, p', '.content' ).each(function() {

                $( this ).delay( i*200 ).animate({'left':0, 'opacity':1}, 380);

                    ++i;
                
                });
            
            }
        
        },33);
        
        cache( json.object.item[hash]['01'] );

        current = hash;//window.location.hash = hash;

    };

    release.next = function() {
    
        if( $('*').is(':animated') )

            return false;        

        var hash = ( current == undefined ) ? 0 : current;//parseInt( (window.location.hash == '') ? 0 : window.location.hash.replace('#', '') );

        if( hash == (json.object.item.length-1)  ) {

            hash = 0; 
        }

        else {

            hash += 1;
        
        }

        var i = 0;

        $( 'h3, h4, p, .link', '.content' ).each(function() {

            $( this ).delay( i*200 ).animate({'left':-8, 'opacity':0}, 380);

            ++i;
        
        });

        var timer = setInterval( function() {            

            if( !$('*').is(':animated') ) {

                clearInterval( timer );

                $( 'h3', '.content' ).html( json.object.item[hash]['02'] ).next().html( json.object.item[hash]['03'] ).next().html( json.object.item[hash]['04'] ).next( '.link' ).html( json.object.item[hash]['05'] );

                var i = 0;

                $( 'h3, h4, p, .link', '.content' ).each(function() {

                $( this ).delay( i*200 ).animate({'left':0, 'opacity':1}, 380);

                    ++i;
                
                });
            
            }
        
        },33);

        cache( json.object.item[hash]['01'] );

        current = hash;//window.location.hash = hash;
    
    };

    release.start = function() {

        if( $('*').is(':animated') )

            return false;

        var hash = ( current == undefined ) ? 0 : current;//parseInt( (window.location.hash == '') ? 0 : window.location.hash.replace('#', '') );

        cache( json.object.item[hash]['01'] );

        var i = 0;

        $( 'h3, h4, p, .link', '.content' ).css( {'display':'block', 'left':-8, 'opacity':0, 'position':'relative'} );

        $( 'h3', '.content' ).html( json.object.item[hash]['02'] ).next().html( json.object.item[hash]['03'] ).next().html( json.object.item[hash]['04'] ).next( '.link' ).html( json.object.item[hash]['05'] );

        $( 'h3, h4, p, .link', '.content' ).each(function() {

            $( this ).delay( i*200 ).animate( {'left':0, 'opacity':1}, 380 );

            ++i;
        
        });

    };

    function cache( arg ) {
    
        $( 'body' ).append(

            $('<img />',{
            
                css:{

                    'display':'none',
                    'height':$(document).height(),
                    'left':0,
                    'margin':0,
                    'opacity':0,
                    'padding':0,
                    'position':'absolute',
                    'top':0,
                    'width':$(window).width()
                
                }
            
            })

            .attr('class','cache')

        );

        $( '.cache' ).attr( 'src', 'assets/index/'+arg+'.jpg' ).load(function() {

            change( arg );$( this ).remove();
        
        });

    };

    function change( arg ) {

        $( 'body' ).children( ':first-child' ).animate({'opacity':0},300, function() {

            $( this ).css( {'background':'url(assets/index/'+arg+'.jpg) no-repeat 50% 0'} ).animate( {'opacity':1},600 );
        
        });

    };

    (function() {

        $.getJSON('data/lastest.js', function(data) {

            json = data;release.start();
        
        });

        $( 'body' ).prepend(

            $('<div/>',{
            
                css:{

                    'height':$(document).height(),
                    'left':0,
                    'margin':0,
                    'opacity':0,
                    'padding':0,
                    'position':'absolute',
                    'top':0,
                    'width':$(window).width()
                
                }
            
            })

        );

        $( 'section' ).delegate('.prev', 'mousedown', function() {

            release.prev();
        
        });

        $( 'section' ).delegate('.next', 'mousedown', function() {

            release.next();
        
        });       
    
    })();

})( window.release = {} );

;(function( achieve ) {

    var json, hash, heap = [];

    function prev() {

        if( $('*').is(':animated') )

            return false;

        hash = ( window.location.hash == '' ) ? 0 : window.location.hash.replace( '#', '' );

        if( hash < 1 ) {

            hash = json.object.item.length-1; 
        }

        else {

            hash -= 1;
        
        }

        window.location.hash = hash;

        cache();
    
    };

    achieve.next = function() {

        /*if( $('*').is(':animated') )

            return false;*/

        hash = parseInt( (window.location.hash == '') ? 0 : window.location.hash.replace('#', '') );

        if( hash == (json.object.item.length-1)  ) {

            hash = 0; 
        }

        else {

            hash += 1;
        
        }

        window.location.hash = hash;

        cache();
    
    }

    function cache() {

        $( 'body' ).append(

            $('<img />',{
            
                css:{

                    'display':'none',
                    'height':$(document).height(),
                    'left':0,
                    'margin':0,
                    'opacity':0,
                    'padding':0,
                    'position':'absolute',
                    'top':0,
                    'width':$(window).width()
                
                }
            
            })

            .attr('class','cache')

        );

        if( $.inArray( json.object.item[hash]['04'], heap) == -1 ) {

            $( '.achieve' ).children( 'article' ).stop().animate( { 'opacity':.1},300,function() {
            
                $( this ).next( '.object' ).stop().animate( {'opacity':1},300,function() {
               
                    $( '.cache' ).attr( 'src', 'assets/index/'+json.object.item[hash]['01']+'.png').load(function() {

                        $( '.object' ).stop().animate( {'opacity':0},300,function() {
                        
                            $( this ).prev( 'article' ).stop().animate( {'opacity':1},600 );

                        } );
                        
                        change();$( this ).remove();
                    
                    });

                });

            });

            heap.push( json.object.item[hash]['04'] );

        }

        else {
        
            change();$( this ).remove();

        }

    };

    function open() {

        /*if( $('*').is(':animated') )

            return false;*/

        $.getJSON('data/achieve.js', function(data) {

            json = data;cache();
        
        });

        $( '.container' ).after(

            $('<div />',{
            
                css:{
                    'background':'#000',
                    'display':'block',
                    'height':$(document).height(),
                    'left':0,
                    'margin':0,
                    'opacity':.93,
                    'padding':0,
                    'position':'absolute',
                    'top':0,
                    'width':$(window).width()
                }
            
            })

            .attr('class','screen')

        );
    
        hash = parseInt( (window.location.hash == '') ? 0 : window.location.hash.replace('#', '') );

        $( '.achieve' ).css( {'left':($(window).width()-1000)*.5, 'top':($(window).height()-500)*.5} ).show()//.find( 'article:eq('+window.location.hash.replace('#','')+')' ).show().siblings( 'article' ).hide();

    };

    function close() {

        /*if( $('*').is(':animated') )

            return false;*/

        $( '.achieve' ).hide().find( 'img' ).attr( 'src', '' );$( '.screen' ).remove();//release.start();

    };

    function change() {

        var achieve = $( '.achieve' );

        $( achieve ).find( 'img:not(.indicator)' ).attr( 'src', 'assets/index/'+json.object.item[hash]['01']+'.png' ).css( {'opacity':0} ).animate( {'opacity':1},600 ).end().find( 'small:lt(1)').html( json.object.item[hash]['03'] ).end().find( 'h3' ).html( json.object.item[hash]['02'] ).end().find( 'a:not(.prev, .next, .close)' ).html( json.object.item[hash]['04'] ).end().find( 'span' ).html( json.object.item[hash]['05'] );

    };

    (function() {

        $( '.achieve' ).delegate('.close', 'mouseenter', function() {

            $( '.close' ).css( {'-webkit-transform':'rotate(45deg)'} );

        });

        $( '.achieve' ).delegate('.close', 'mouseleave', function() {

            $( '.close' ).css( {'-webkit-transform':'rotate(0deg)'} )

        });
    
        $( 'section' ).delegate('.more', 'mousedown',  function() {            

            open();
            
        });

        $( '.achieve' ).delegate('.close', 'mousedown', function() {

            close();

        });

        $( document ).delegate('.screen', 'mousedown', function() {
        
            close();

        });

        $( '.achieve' ).delegate('.prev', 'mousedown', function() {

            prev();
        
        });

        $( '.achieve' ).delegate('.next', 'mousedown', function() {

            achieve.next();
        
        });

        var timer = setInterval( function() {
        

            $( '.achieve section' ).find( 'a' ).each(function() {
        
                $( this ).attr({ 'target':'_blank','href':'http://'+$.trim($(this).text())} );
        
            });
        
        },500);

        /*$( '.achieve' ).delegate('.data', 'mouseenter', function() {
        
            $( '.close' ).animate( {'opacity':0},600 );

            $( '.prev', this ).css( {'left':0} );

            $( '.next', this ).css( {'right':0} );

        });

        $( '.achieve' ).delegate('.data', 'mouseleave', function() {
        
            $( '.close' ).animate( {'opacity':1},600 );

            $( '.prev', this ).css( {'left':-50} );

            $( '.next', this ).css( {'right':-50} );

        });*/

        hash = window.location.hash;

        if( hash != '' ) {
        
            open();

        }
    
    })();

})( window.achieve = {} );

;(function( automation ) {

    var timer; 

    ;(function() {

        $( document ).mousemove(function() {
        
            if( timer ) {
            
                clearInterval( timer );

            }

            timer = setInterval(function() {

                if( $('.achieve').is(':visible') ) {
                
                    achieve.next();
                
                }

                else {
                
                    release.next();

                }
            
            },6000);

        });

    })();

})( window.automation = {} );

;(function( comment ) {

    $( 'nav' ).delegate( 'a', 'mouseenter', function() {
   
        var position = (($(this).next().width())*-.5) + ($(this).parent().width()*.5);

        if( $.browser.msie )
            
            return false;
        
        $( this ).next().css({'left':position, 'opacity':0, 'width':$(this).next().width(), 'visibility':'visible'} ).animate( {'bottom':-45, 'opacity':1},300 ).parent().css( {'position':'relative'} );
    
    });
  
    $( 'nav' ).delegate( 'a', 'mouseleave', function() {
                            
        $( this ).next().animate({'bottom':-55, 'opacity':0},300,function(){
                                    
            $(this).css({'visibility':'hidden'});

        });

    });

})( window.comment = {} );

;(function( rss ) {

    (function() {

        $.get('rss.php',function(arg) {

            //console.log( $( arg ).find( 'channel' ).find( 'title:eq(1)' ).text() );

            var rss = $( arg ).find( 'channel' ).find( 'title:eq(1)' ).text();

            $( '.blog' ).find( 'p' ).html( rss );
        
        });
    
    })();

})( window.rss = {} );

$( '.email' ).click(function() {

    $( '.container' ).after(

            $('<div />',{
            
                css:{
                    'background':'url(images/index/email-overlay.png) repeat 0 0',
                    'display':'block',
                    'height':$(document).height(),
                    'left':0,
                    'margin':0,
                    'opacity':1,
                    'padding':0,
                    'position':'absolute',
                    'top':0,
                    'width':$(window).width()
            }
            
        })

        .attr('class','email-screen')

    );

    $( '.email-subscribe' ).css( {'left':($(window).width()-$('.email-subscribe').outerWidth())*.5, 'top':($(window).height()-$('.email-subscribe').outerHeight())*.5}).show();

});

$( '.email-subscribe input[type="image"]' ).click(function() {



    $( '.email-screen, .email-subscribe' ).hide();

});

$( 'body').delegate('.email-screen', 'click', function() {

    $( '.email-screen, .email-subscribe' ).hide();

});

$( 'body').delegate('.email-subscribe .close', 'click', function() {

    $( '.email-screen, .email-subscribe' ).hide();

})

$( '.email-subscribe input[type="text"]' ).focus(function() {

    $( this ).val('');

});

//;(function() {setInterval(function(){console.log( $('*:animated').length);},1000);})();

$( '.content' ).delegate( '.link', 'click', function() {

    $( this ).attr( 'href', $.trim($(this).html()) );

});

