/*
 Script: core.js
 smooth and rich effect for "flatfive.jp".
 this script is written based on MooTools1.2.1 (http://mootools.net/)
 Author:
 masato kimura (http://www.ctrl-plus.jp/)
 */
var scriptCore = true;

// google analytics
if (!location.host.match(/localhost|conpura\.jp|192\.168|219\.94/)) {
    try {
        var pageTracker = _gat._getTracker("UA-8053263-1");
        pageTracker._trackPageview();
    } 
    catch (err) {
    }
}

// youtube API
youtube = false;
function onYouTubePlayerReady(playerId){
    youtube = true;
    ytplayer = $("youtubePlayer");
}

(function(){

    var Site, Navigation, Schedule, Calendar, Video, Ajaxbox;
    
    // サイトのエフェクトをコントロール
    Site = {
        init: function(){
            if (Browser.Engine.trident) 
                this.title = document.title;
            
            this.baseURLset = location.protocol + '//' + location.host + '/images/';
            window.scrollTo(0, 0);
            if ($('HOME')) {
                this.cuttingText($$('#HOME #box_information dd a'));
            }
            if ($('videoBox')) {
                this.setVideo();
            }
            if ($('COMPANY')) {
                this.setTable($('company_info'));
            }
            Navigation.init();
            this.pngImgFix();
            //Video.init();
            Ajaxbox.init();
            if (location.hash.test('#/contact')) {
                this.directAccess();
            }
        },
        
        load: function(){
            if ($('SCHEDULE') || $('SCHEDULE_DETAIL')) {
                Calendar.init()
                Schedule.init();
            }
            this.setBackground();
            if (location.hash.test('#/contact')) {
                this.directAccess();
            }
        },
        
        setBackground: function(){
            this.wrapperHeight = $('wrapper').getSize().y;
            var bg = $('bg_add').setStyle('height', this.wrapperHeight);
            if (Ajaxbox.overlay) {
                Ajaxbox.overlay.style.width = Ajaxbox.container.style.width = bg.getSize().x + 'px';
                Ajaxbox.overlay.style.height = Ajaxbox.container.style.height = window.getScrollSize().y + 'px';
            }
            if (Video.overlay) 
                Video.overlay.setStyles({
                    'width': bg.getSize().x,
                    'height': this.wrapperHeight
                });
        },
        
        cuttingText: function(array){
            array.each(function(el){
                var text = el.get('text').replace(/\r|\n/g, '');
                var mac = Browser.Platform.mac ? 7 : 0;
                var limit = el.getParent().hasClass('hottopic') ? 33 - (mac * 0.3).toInt() : 45 - mac;
                if (text.length > limit) 
                    el.set('text', text.substring(0, limit) + '...');
            });
        },
        
        setVideo: function(){
            if (!$$('#videoBox a')[0]) 
                return false;
            var size = $$('body')[0].get('id') == 'HOME' ? [290, 250] : [326, 275];
            var vid = $$('#videoBox a')[0].href.replace('watch?v=', 'v/');
            new Swiff(vid + '&amp;enablejsapi=1&amp;playerapiid=ytplayer&border=0&color1=a09066&color2=e1cf9d', {
                width: size[0],
                height: size[1],
                id: 'youtubePlayer',
                container: 'videoBox',
                params: {
                    allowScriptAccess: 'always',
                    wmode: 'transparent'
                }
            });
        },
        
        setTable: function(table){
            var tr = table.getElements('tr:even');
            tr.each(function(){
                tr.addClass('odd');
            });
            return;
        },
        
        directAccess: function(){
            if (!this.directAccessFlag) {
                this.directAccessFlag = true;
                return;
            }
            if (Ajaxbox.status) {
                var obj = {
                    'href': '/contact'
                };
                Ajaxbox.open(obj);
            }
        },
        
        tracker: function(str){
            if (!pageTracker) 
                return;
            pageTracker._trackPageview('/' + str);
        },
        
        /*
         PNG bugfix for IE6:
         Example:
         <img src="XX.png" alt="" class="pngfix" />
         */
        pngImgFix: function(elements){
            if ((!$$('.pngfix')[0] && !elements) || !Browser.Engine.trident4) 
                return;
            var target = elements ? elements.getElements('.pngfix') : $$('.pngfix');
            var path = this.baseURLset + 'blank.gif';
            target.each(function(el, i){
                if (el.getStyle('filter')) 
                    return;
                if (el.get('tag') == 'img') {
                    var src = el.src;
                    el.src = path;
                    el.setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + src + ')');
                }
                else {
                    var src = el.getStyle('background-image');
                    src = src.replace('url(', '');
                    src = src.replace(')', '');
                    var size = el.hasClass('sizeScale') ? 'scale' : 'crop';
                    el.setStyles({
                        'background-image': 'url(' + path + ')',
                        'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + src + ',sizingMethod=' + size + ')'
                    });
                }
            });
        }
    };
    
    // グローバルナビゲーションエフェクト
    Navigation = {
        init: function(){
            $('gNav_overlay').set('src', Site.baseURLset + 'blank.gif');
            this.globalNav = $('globalNav');
            this.trigger = $$('#gNavImg area');
            this.trigger.each(function(el, i){
                var classname = 'hover_' + el.alt;
                if (el.hasClass('active')) {
                    this.active('active_' + el.alt);
                }
                el.addEvents({
                    'mouseenter': this.enter.bind(this, [classname, i]),
                    'mouseleave': this.leave.bind(this, [classname, i])
                });
            }, this);
        },
        
        active: function(name){
            this.globalNav.addClass(name);
        },
        
        enter: function(name, i){
            if (this.trigger[i].hasClass('active')) 
                return false;
            this.globalNav.addClass(name);
        },
        
        leave: function(name, i){
            if (this.trigger[i].hasClass('active')) 
                return false;
            this.globalNav.removeClass(name);
        }
    };
    
    // スケジュールページエフェクト
    Schedule = {
        init: function(){
            if ($('SCHEDULE_DETAIL')) {
                return this.detail();
            }
            this.previous = false;
			this.flag = false;
            this.triggers = [];
            this.contents = [];
            this.heights = [];
            this.talentHash = [];
            var hash = location.hash.replace('#', '');
            this.scrlFx = new Fx.Scroll(window, {
                duration: 630,
                transition: 'circ:out'
            });
            this.talents = $$('.schedule_box');
            this.talents.each(function(el, i){
                this.talentHash.push(el.get('class').replace('schedule_box', '').replace(' ', ''));
                var trigger = el.getChildren()[0];
                trigger.addEvents({
                    'mouseenter': this.enter.bind(this),
                    'mouseleave': this.leave.bind(this),
                    'click': this.click.pass([i, true], this)
                });
                this.triggers.push(trigger);
                var ctn = el.getChildren()[1];
                this.setImg(el);
                ctn.set({
                    'styles': {
                        'opacity': 0.001
                    },
                    'tween': {
                        duration: 430,
                        transition: 'quad:out',
						link: 'chain'
                    }
                });
                ctn.setStyle('height', 0);
                this.contents.push(ctn);
                
                if (el.hasClass(hash)) {
                    this.click(i, true);
                }
            }, this);
        },
        
        setLoading: function(el, i){
			el.getParent().getElement('.s_img').setStyle('opacity', 0.01);
			new Element('div', {
				'text': 'スケジュールを読み込み中...',
				'class': 'loading_box'
			}).inject(el).setStyle('height', 70);
			this.contents[i].setStyles({
				'height': 70,
				'opacity': 0.9
			});
			return el;
		},
		
        setEmpty: function(element, i){
            var height = element.getSize().y;
            if (height < 320) {
                new Element('div', {
                    'class': 'empty_box'
                }).inject(element).setStyle('height', 320 - height);
            }
            else 
                if (this.talents.length == i + 1) {
                    new Element('div', {
                        'class': 'empty_box'
                    }).inject(element).setStyle('height', 130);
                }
            return element;
        },
        
        setImg: function(element){
            var name = element.get('class').replace('schedule_box', '');
            name = name.replace(' ', '');
            var src = '/talents/' + name + '/schedule_image';
            var img = element.getElement('.s_img img');
            img.src = src;
        },
		
		setRequest: function(target, i, talent){
			new Request.HTML({
				method: 'get',
				url: '/schedules/' + talent + '/parts/',
				//update: target,
				onComplete: (function(tree, elements, html){
					this.resultHtml = html;
					this.appear(target, i);
				}).bind(this)
			}).send();
		},
        
        enter: function(e){
			if(!this.flag) {
	            e.target.addClass('hover');
			}
        },
        
        leave: function(e){
            e.target.removeClass('hover');
        },
        
        click: function(i, scrl, pagejump){
			if (this.flag) 
				return false;
            if (this.fx) {
                this.fx.cancel();
            }
            if (this.talents[i].hasClass('active')) {
                if (pagejump) {
                    this.scroll(i, 36);
                }
                else {
                    this.close(i);
                    this.previous = false;
                }
            } else {
                if ($chk(this.previous)) {
                    this.close(this.previous);
                }
                if (scrl) {
                    this.href(i);
                }
                this.open(i);
                if (scrl && i >= this.previous) 
                    this.scroll(i, 6);
                else 
                    if (scrl && i < this.previous) 
                        this.scroll(i, 36);
                this.talents[i].addClass('active');
                this.previous = i;
                if (scrl) {
                    Site.tracker('AJAX_schedule/' + this.talentHash[i]);
                }
            }
        },
        
        open: function(i){
			this.flag = true;
            if (Calendar.tip.hasClass('active')) {
                Calendar.close();
            }
            var talent = this.talentHash[i];
            var target = $('schedule_list_of_' + talent);
			
			if(!target.getElement('.s_category')){
				if(!target.getElement('.loading_box')) 
					this.setLoading(target, i);
				this.timer = false;
				this.setRequest(target, i, talent);
				this.appear.delay(650, this, [target, i]);
			}
			else {
				this.timer = true;
				this.appear(target, i);
			}
        },
        
        appear: function(target, i) {
			if(!this.timer ) {
				this.timer = true;
				return false;
			}
			if(this.resultHtml) {
				target.innerHTML = this.resultHtml;
				this.contents[i].setStyle('opacity', 0.1);
				this.contents[i].getElement('.s_img').setStyle('opacity', 1);
			}
			this.heights[i] = this.setEmpty(target, i).getSize().y;
			this.contents[i].setStyle('height', this.heights[i]);
			Calendar.setTrigger(target);
			this.fx = this.contents[i].get('tween');
			this.fx.start('opacity', 1).chain(this.end.bind(this));
		},
		
		end: function() {
			this.flag = false;
			this.timer = false;
			this.resultHtml = null;
			Site.setBackground();
		},
        
        close: function(i){
            if (Calendar.tip.hasClass('active')) 
                Calendar.close();
            this.contents[i].setStyles({
                'height': 0,
                'opacity': 0
            });
            this.talents[i].removeClass('active');
            Site.setBackground();
        },
        
        href: function(i){
            var hash = this.talents[i].get('class').replace('schedule_box', '').replace(' ', '');
            location.href = '#' + hash;
        },
        
        scroll: function(i, add){
            var pos = this.talents[i].getPosition().y;
            this.scrlFx.start(0, pos - add);
        },
        
        detail: function(){
            $$('.s_img')[0].setStyle('height', $$('.s_data')[0].getSize().y);
        },
        
        jump: function(url){
            var hash = this.talentHash.indexOf(url);
            if (hash != -1) 
                this.click(hash, true, true);
        }
    };
    
    // カレンダー登録
    Calendar = {
        init: function(){
            if (!$('addCalendar_tip')) {
                return;
            }
            this.addCal = [];
            this.flag = false;
            this.num = null;
            this.container = $('schedule_content');
            this.tip = $('addCalendar_tip');
            this.tip_google = this.tip.getElement('.add_google');
            this.tip_outlook = this.tip.getElement('.add_outlook');
            this.tip_ical = this.tip.getElement('.add_ical');
            this.fx = new Fx.Morph(this.tip, {
                duration: 240,
                transition: 'circ:out',
                link: 'chain'
            });
            this.text = this.tip.getElement('#tip_ttl');
            $('tip_bg').addEvent('click', this.close.bind(this)).setStyle('opacity', 0.7);
            if ($('SCHEDULE_DETAIL')) 
                this.setTrigger(this.container);
        },
        
        setTrigger: function(elm){
            this.addCal = [];
            this.triggers = elm.getElements('a.addCal');
            this.triggers.each(function(elm, i){
                elm.addEvent('click', this.click.bind(this, [elm, i]));
            }, this);
            
            elm.getElements('.addCalInvisibleData').each(function(el, i){
                this.addCal.push({
                    'google': el.getElement('.google_calendar').get('href'),
                    'outlook': el.getElement('.outlook_calendar').get('href'),
                    'ical': el.getElement('.ical_calendar').get('href')
                });
            }, this);
        },
        
        click: function(el, i){
            if (this.flag) 
                return false;
            if ($type(this.addCal[i]) != 'object') 
                return false;
            this.flag = true;
            if (this.tip.hasClass('active')) 
                this.close();
            el.blur();
            this.prepare(el, i);
            return false;
        },
        
        prepare: function(el, i){
            this.num = i;
            el.addClass('hidden');
            this.tip_google.href = this.addCal[i]['google'];
            this.tip_outlook.href = this.addCal[i]['outlook'];
            this.tip_ical.href = this.addCal[i]['ical'];
            this.background = el.getParent().className == 's_category' ? el.getParent() : el.getParent().getParent();
            var pos = el.getPosition(this.container);
            this.tip.setStyles({
                'width': 0,
                'height': 0,
                'top': pos.y - 4,
                'left': pos.x
            });
            this.text.set('text', el.get('text'));
            this.appear();
        },
        
        appear: function(){
            this.tip.addClass('active');
            if (this.background.className == 's_category') {
                this.lists = this.background.getParent().getElements('.text_box');
                this.current = this.background.getParent().getElements('.s_current_body');
                $each([this.lists, this.current], function(el){
                    el.setStyle('background-position', '-590px 0');
                });
            }
            else {
                this.background.setStyle('background-position', '-590px 0');
            }
            this.fx.start({
                'width': 300,
                'height': 160
            }).chain(this.end.bind(this));
        },
        
        close: function(){
            this.triggers[this.num].removeClass('hidden');
            this.tip.removeClass('active');
            this.tip.setStyles({
                'width': 0,
                'height': 0
            });
            if (this.lists) {
                $each([this.lists, this.current], function(el){
                    el.setStyle('background-position', '0 0');
                });
                this.lists = this.current = false;
            }
            else {
                this.background.setStyle('background-position', '0 0');
            }
        },
        
        end: function(){
            this.flag = false;
        }
    };
    
    // フッター部のタレントムービーエフェクト
    Video = {
        init: function(){
            this.overlay = new Element('div', {
                id: 'v_overlay'
            }).setStyles({
                'width': $('bg_add').getSize().x,
                'height': $('wrapper').getSize().y
            }).inject($('wrapper'));
            this.background = new Element('div', {
                id: 'v_background'
            }).inject(this.overlay).setStyle('opacity', 0.45);
            this.videoFrame = new Element('div', {
                id: 'v_container'
            }).inject(this.overlay, 'after');
            this.videoBody = new Element('div', {
                id: 'v_frame'
            }).inject(this.videoFrame);
            
            // タレントムービー本体
            new Swiff('/flash/video_frame.swf', {
                width: 1034,
                height: 480,
                id: 'videoContent',
                container: this.videoBody,
                callBacks: {
                    videoready: Video.readyobj.bind(Video, 'video'),
                    schedule: Video.jumpSchedule.bind(Video),
                    close: Video.close.bind(Video)
                }
            });
        },
        
        readyobj: function(from){
            if (from == 'video') {
                // タレントサムネール
                new Swiff('/flash/talents_index2.swf', {
                    width: '100%',
                    height: 118,
                    id: 'talentThumbs',
                    container: $('talentVideo_base'),
                    callBacks: {
                        indexready: Video.readyobj.bind(Video, 'index'),
                        mouseenter: Video.enter.bind(Video)
                    }
                });
            }
            else 
                if (from == 'index') {
                    this.setup();
                }
        },
        
        setup: function(){
            this.step = 0;
            this.talentSwf = $('talentThumbs');
            this.videoSwf = $('videoContent');
            this.overlay.addEvent('click', this.removeVideo.bind(this));
            this.background.set('tween', {
                duration: 430,
                transition: 'circ:out',
                link: 'chain'
            });
        },
        
        enter: function(who){
            if (this.step) 
                return false;
            if (!this.overlay.hasClass('active')) {
                this.resetTitle();
                this.step = 1;
                this.activeTalent = who;
                this.videoSwf.loadFlv('/flash/' + this.activeTalent + '.flv', this.activeTalent);
                this.background.setStyle('margin-top', $('wrapper').getSize().y);
                this.overlay.addClass('active');
                this.appear();
                Site.tracker('FLV/' + this.activeTalent);
            }
        },
        
        appear: function(){
            this.videoFrame.addClass('active');
            
            var fx = this.background.get('tween');
            fx.start('margin-top', 0).chain(this.startVideo.bind(this));
        },
        
        startVideo: function(){
            this.step = 2;
            // youtubeが再生してれば自動停止
            if (youtube && ytplayer.getPlayerState() == 1) {
                ytplayer.pauseVideo();
                youtube = 'stop';
            }
            this.videoSwf.loadingClip(this.activeTalent);
        },
        
        removeVideo: function(){
            if (this.step <= 1) 
                return false;
            this.videoSwf.closeStream();
            //Swiff.remote(this.videoSwf, 'closeStream');
        },
        
        close: function(){
            this.resetTitle();
            this.videoFrame.removeClass('active');
            var fx = this.background.get('tween', {
                duration: 320,
                transition: 'cubic:out',
                link: 'chain'
            });
            fx.start('margin-top', this.background.getSize().y).chain(this.end.bind(this));
        },
        
        end: function(){
            if (this.jumpFlag) {
                Schedule.jump(this.jumpFlag[1]);
                this.jumpFlag = false;
            }
            this.talentSwf.endAction(this.activeTalent);
            this.overlay.removeClass('active');
            this.step = 0;
            // 自動停止したyoutubeがあれば再生
            if (youtube == 'stop') {
                ytplayer.playVideo();
                youtube = true;
            }
        },
        
        resetTitle: function(){
            if (Browser.Engine.trident) 
                document.title = Site.title;
        },
        
        jumpSchedule: function(url){
            if ($('SCHEDULE')) {
                this.removeVideo();
                this.jumpFlag = [true, url.replace('/schedules/#', '')];
            }
            else {
                location.href = url;
            }
        }
    };
    
    // サイトマップ、お問い合わせ等
    Ajaxbox = {
        init: function(){
            // lightboxで表示したいURLを設定
            this.targets = ['/sitemap', '/contact', '/help'];
            this.iframesrc = '/contact/';
            this.status = 'init'; // 'init'|'ready'|'open'|'close'
            this.container = new Element('div', {
                id: 'a_container'
            }).inject(document.body);
            this.overlay = new Element('div', {
                id: 'a_overlay'
            }).inject(this.container).addEvent('click', this.close.bind(this));
            this.base = new Element('div', {
                id: 'a_base'
            }).inject(this.container);
            this.content = new Element('div', {
                id: 'a_content'
            }).inject(this.base);
            this.overlay.style.width = this.container.style.width = $('bg_add').getSize().x + 'px';
            this.overlay.style.height = this.container.style.height = window.getScrollSize().y + 'px';
            this.fx = {
                overlay: new Fx.Tween(this.overlay, {
                    property: 'opacity',
                    duration: 430,
                    transition: 'circ:out',
                    link: 'chain'
                }),
                base: new Fx.Morph(this.base, {
                    duration: 360,
                    transition: 'quad:out',
                    link: 'chain'
                }),
                content: new Fx.Tween(this.content, {
                    property: 'opacity',
                    duration: 350,
                    transition: 'circ:out',
                    link: 'chain'
                })
            };
            this.closebtn = new Element('a', {
                id: 'a_close',
                'class': 'hidden',
                'text': 'close'
            }).addEvent('click', this.close.bind(this));
            this.error = new Element('p', {
                'class': 'errorContent',
                'text': 'ページの取得に失敗しました'
            });
            this.setup();
            this.status = 'ready';
        },
        
        setup: function(content){
            var triggers = [];
            var anchors = content ? content.getElements('a') : $$('a');
            anchors.each(function(el){
                this.targets.each(function(url){
                    if (el.href.test(location.protocol + '//' + location.host + url)) 
                        triggers.push(el);
                });
            }, this);
            $each(triggers, function(el, i){
                el.addEvents({
                    'focus': function(){
                        this.blur();
                    },
                    'click': this.click.bind(this, el)
                })
            }, this);
        },
        
        click: function(el){
            if (this.status == 'close') 
                return false;
            if (this.status == 'open') 
                this.change(el);
            else 
                this.open(el);
            return false;
        },
        
        request: function(){
            if (this.targetURL.test('/contact')) 
                return false;
            var request = new Request.HTML({
                url: this.targetURL,
                link: 'cancel',
                onComplete: this.complete.bind(this)
            }).get();
        },
        
        complete: function(e){
            if (!e) {
                this.ajaxContent = this.error;
                return this.process('ajax');
            }
            $each(e, function(el){
                if ($type(el) == 'element' && el.get('id') == 'ajax_content') {
                    this.ajaxContent = el;
                    return this.process('ajax');
                }
            }, this);
        },
        
        setframe: function(){
            // firefox3.0 has bug - iframe can not have same name at one session
            var id = 'a_iframe' + $time();
            this.iframe = new IFrame(id, {
                'name': id,
                'frameborder': 0,
                'scrolling': 'no'
            });
            this.iframe.src = this.iframesrc;
            this.iframe.inject(this.content).addEvents({
                'domready': function(){
                    Ajaxbox.content.addClass('invisible')
                },
                'load': this.process.bind(this, 'iframe')
            });
        },
        
        open: function(el){
            this.position = this.position ? this.position : window.getScrollTop() + (window.getHeight() / 6);
            this.targetURL = el.href;
            this.overlay.setStyle('opacity', 0.5);
            this.base.setStyles({
                'top': this.position - 15,
                'opacity': 0
            });
            this.container.addClass('active');
            this.fx.base.start({
                'top': this.position,
                'opacity': 1
            }).chain(this.process.bind(this, 'fx'));
            this.ajaxContent = false;
            this.wait = true;
            this.request();
        },
        
        change: function(el){
            this.ajaxContent = false;
            this.content.innerHTML = '';
            this.targetURL = el.href;
            this.content.setStyle('opacity', 0.001).addClass('invisible');
            this.wait = false;
            if (this.targetURL.test('/contact')) 
                this.process('fx');
            else 
                this.request();
        },
        
        process: function(from){
            if (from == 'ajax') {
                this.content.setStyle('opacity', 0.001).addClass('invisible');
                this.ajaxContent.inject(this.content);
                this.closebtn.inject(this.content);
                this.setup(this.ajaxContent);
                if (!this.wait) 
                    this.appear();
                else 
                    this.wait = false;
            }
            else 
                if (from == 'fx') {
                    if (this.targetURL.test('/contact')) 
                        this.setframe();
                    else 
                        if (!this.wait) 
                            this.appear();
                        else 
                            this.wait = false;
                }
                else 
                    if (from == 'iframe') {
                        this.content.setStyle('opacity', 0.001);
                        this.closebtn.inject(this.content);
                        this.appear(true);
                    }
        },
        
        getPosition: function(size){
            return window.getHeight() - size.y < 0 ? window.getScrollTop() + 10 : window.getScrollTop() + (window.getHeight() - size.y) / 2;
        },
        
        appear: function(isframe){
            if (isframe) {
                var iframe = frames[this.iframe.name].document.getElementById('CONTACT');
                this.iframe.setStyles({
                    'width': iframe.offsetWidth,
                    'height': iframe.offsetHeight
                });
                var size = {
                    x: iframe.offsetWidth,
                    y: iframe.offsetHeight
                };
            }
            else {
                var size = this.ajaxContent == this.error ? this.error.getSize() : this.ajaxContent.getChildren()[0].getSize();
            }
            this.position = this.getPosition(size);
            this.fx.base.start({
                'top': this.position,
                'width': size.x,
                'height': size.y,
                'margin-left': -size.x / 2
            }).chain(this.show.bind(this));
            this.wait = false;
        },
        
        show: function(){
            this.status = 'open';
            this.content.removeClass('invisible');
            this.fx.content.start(1);
            this.overlay.style.height = window.getScrollSize().y + 'px';
            Site.tracker(this.targetURL.replace('http://' + location.host + '/', ''));
        },
        
        close: function(){
            if (this.status == 'close') 
                return false;
            this.status = 'close';
            this.cancel();
            if (this.iframe) {
                this.iframe.onload = $empty;
                this.iframe.destroy();
            }
            this.closebtn.addClass('disable');
            this.fx.base.start({
                'top': this.position + 30,
                'opacity': 0
            });
            this.fx.overlay.start(0).chain(this.end.bind(this));
        },
        
        cancel: function(){
            for (var f in this.fx) 
                this.fx[f].cancel();
        },
        
        end: function(){
            this.container.removeClass('active');
            this.closebtn.removeClass('disable');
            this.ajaxContent = false;
            this.content.innerHTML = '';
            this.status = 'ready';
        }
    };
    
    // Effect set for document
    window.addEvents({
        'domready': Site.init.bind(Site),
        'load': Site.load.bind(Site),
        'resize': Site.setBackground.bind(Site)
    });
})();
