var currentContent = "";
function toggleBackground() {
    
    if ($('bgDim').style.display == "none") {
        if ($('twitterContent').style.display != "none") {
            toggleTwitterBox();
        }

        if ($('newsletterContent').style.display != "none") {
            toggleNewsletterBox();
        }
        
        new Effect.Parallel( [
            new Effect.Fade($('bgNormal'), {
            sync :true
        }), new Effect.Appear($('bgDim'), {
            sync :true
        }), new Effect.Appear($(currentContent), {
            sync: true
        }), new Effect.Fade($('betaSignupButtonTransparency'), {
            sync: true
        }), new Effect.Fade($('betaSignupButton'), {
            sync: true
        }), new Effect.Fade($('twitterToggleButtonTransparency'), {
            sync: true
        }), new Effect.Fade($('twitterToggleButton'), {
            sync: true
        }), new Effect.Fade($('twitterContent'), {
            sync: true
        }), new Effect.Fade($('newsletterToggleButtonTransparency'), {
            sync: true
        }), new Effect.Fade($('newsletterToggleButton'), {
            sync: true
        }), new Effect.Fade($('newsletterContent'), {
            sync: true
        })], {
            duration :0.5,
            delay :0.0,
            queue: {position: 'end', scope: 'showContent', limit: 1}
        });
        
    } else {
        new Effect.Parallel( [
            new Effect.Fade($('bgDim'), {
            sync :true
        }), new Effect.Appear($('bgNormal'), {
            sync :true
        }), new Effect.Fade($(currentContent), {
            sync: true
        }), new Effect.Appear($('betaSignupButtonTransparency'), {
            sync: true
        }), new Effect.Appear($('betaSignupButton'), {
            sync: true
        }), new Effect.Appear($('twitterToggleButton'), {
            sync: true
        }), new Effect.Appear($('twitterToggleButtonTransparency'), {
            sync: true
        }), new Effect.Appear($('newsletterToggleButton'), {
            sync: true
        }), new Effect.Appear($('newsletterToggleButtonTransparency'), {
            sync: true
        }) ], {
            duration :0.5,
            delay :0.0,
            queue: {position: 'end', scope: 'showContent', limit: 1}
        });
        //window.setTimeout("setDisplay('" + currentContent + "', 'none')", 1000);
        currentContent = "";
        $('teaserMenu').innerHTML = "<object type='application/x-shockwave-flash' width='900' height='38' data='inc/swf/pv_flashmenu_en.swf'><param name='quality' value='high'><param name='movie' value='inc/swf/pv_flashmenu_en.swf'><param name='wmode' value='transparent'><param name='menu' value='false'></object>";
    }
    
}

function fadeContent(content) {
    new Effect.Parallel( [
            new Effect.Fade($(currentContent), {
            sync: true
        }), new Effect.Appear($(content), {
            sync: true
        })], {
            duration :0.5,
            delay :0.0,
            queue: {position: 'end', scope: 'showContent', limit: 1}
        });
}

function setDisplay(object, value) {
    
    $(object).style.display = value;
}

function showContent(content) {
    content = content.substr(0, 1).toUpperCase() + content.substr(1);

    content = "teaserContent" + content;
    var latency = 500;

    if(content == "teaserContentScreens") {
        loadScreenshotGallery();
    }

    if(content == "teaserContentPress") {
        loadPressCoverage();
    }


    if(currentContent == content) {
        return;
    }

    if(currentContent == "") {
        currentContent = content;
        toggleBackground();
    } else {
        fadeContent(content);
        currentContent = content;
    }
    
    if(content == "teaserContentPress") {
        window.setTimeout("CSBfleXcroll('pressRight')", latency);
    }
    if(content == "teaserContentAbout") {
        window.setTimeout("CSBfleXcroll('aboutRight')", latency);
    }
    if(content == "teaserContentBetaSignup") {
       window.setTimeout("CSBfleXcroll('betaForm')", latency);
    }

    if(content == "teaserContentScreens") {
           window.setTimeout("CSBfleXcroll('screenshots')", latency);
    }

    
    /*
    content = content.substr(0, 1).toUpperCase() + content.substr(1);

    content = "teaserContent" + content;


    if (navigator.appName.indexOf("Explorer") != -1) {
        var latency = 600;
    } else {
        var latency = 200;
    }

    if(content == "teaserContentScreens") {
        loadScreenshotGallery();
    }

    if(content == "teaserContentPress") {
        loadPressCoverage();
    }


    if(currentContent == content) {
        return;
    }
    if(currentContent == "") {
        currentContent = content;
        $(content).style.display = "block";
        if(content == "teaserContentPress") {
            window.setTimeout("CSBfleXcroll('pressRight')", latency);
        }
        if(content == "teaserContentAbout") {
            window.setTimeout("CSBfleXcroll('aboutRight')", latency);
        }
        if(content == "teaserContentBetaSignup") {
           window.setTimeout("CSBfleXcroll('betaForm')", latency);
        }

        if(content == "teaserContentScreens") {
               window.setTimeout("CSBfleXcroll('screenshots')", latency);
        }

    } else {

        var first = true;
        var tmpContent = currentContent;

        new Effect.Parallel( [
            new Effect.Fade($(currentContent), {
            sync :true
            
        }), new Effect.Appear($(content), {
            sync :true
        }) ], {
            beforeStart: function() {
                currentContent = content;
            },
            afterUpdate: function() {
                if(first) {
                    if(content == "press") {
                        $('pressRight').style.display = "block";
                        window.setTimeout("CSBfleXcroll('pressRight')", latency);
                    }
                    if(content == "about") {
                        $('aboutRight').style.display = "block";
                        window.setTimeout("CSBfleXcroll('aboutRight')", latency);
                    }
                    if(content == "betaSignup") {
                        window.setTimeout("CSBfleXcroll('betaForm')", latency);
                    }
                    if(content == "screens") {
                        window.setTimeout("CSBfleXcroll('screenshots')", latency);
                    }
                }
                first = false;
            },
            afterFinish: function()  {
                window.setTimeout("setDisplay('" + tmpContent + "', 'none')", 1000);
            },
            duration :0.5,
            delay :0.0,
            queue: {position: 'end', scope: 'showContent', limit: 1}
        });
    }
    
    if ($('bgDim').style.display == "none") {
        toggleBackground();
    }
    */
}


function toggleTwitterBox() {
    if ($('twitterContent').style.display == "none") {
        new Effect.Morph($('twitterToggleButtonTransparency'), {
            duration: 0.5,
            style: 'height:220px',
            queue: {position: 'front', scope: 'twitter', limit: 2}
        });
        new Effect.Appear($('twitterContent'), {
                duration: 0.2,
                queue: {position: 'end', scope: 'twitter', limit: 2}
        });
    } else {
        new Effect.Fade($('twitterContent'), {
                duration: 0.2,
                queue: {position: 'front', scope: 'twitter', limit: 2}
        });
        
        new Effect.Morph($('twitterToggleButtonTransparency'), {
            duration: 0.5,
            style: 'height:50px',
            queue: {position: 'end', scope: 'twitter', limit: 2}
        });
    }
}
function toggleNewsletterBox() {
    if ($('newsletterContent').style.display == "none") {
        new Effect.Morph($('newsletterToggleButtonTransparency'), {
            duration: 0.5,
            style: 'height:90px',
            queue: {position: 'front', scope: 'newsletter', limit: 2}
        });
        new Effect.Appear($('newsletterContent'), {
                duration: 0.2,
                queue: {position: 'end', scope: 'newsletter', limit: 2}
        });
    } else {
        new Effect.Fade($('newsletterContent'), {
                duration: 0.2,
                queue: {position: 'front', scope: 'newsletter', limit: 2}
        });

        new Effect.Morph($('newsletterToggleButtonTransparency'), {
            duration: 0.5,
            style: 'height:35px',
            queue: {position: 'end', scope: 'newsletter', limit: 2}
        });
    }
}


function loadScreenshotGallery() {
    if($('screenshotContainer').innerHTML == "") {
        xajax_ActionController.doAction('ExternalBlog', 'getScreenshots');
    }
}

function loadPressCoverage() {
    if($('pressRight').innerHTML == "") {
        xajax_ActionController.doAction('ExternalBlog', 'getPressCoverage');
    }
}


function twitterNow() {
    xajax_ActionController.doAction('ExternalBlog', 'twitterNow', xajax.getFormValues('twitterNowForm'));
}

function resetTwitterBox() {
    toggleTwitterBox();
    document.twitterNowForm.reset();

}

function sendEmailRequest(email) {
    xajax_ActionController.doAction('ExternalBlog', 'registerEmail', xajax.getFormValues('emailForm'));
}

function showResult(type) {
    $('form').fade({from: 1.0, to: 0.0, duration: 0.3});
    window.setTimeout("$('" + type + "').appear({from: 0.0, to: 1.0, duration: 0.3})", 300);
}

function hideResult(type) {
    document.emailForm.reset();
    $(type).fade({from: 1.0, to: 0.0, duration: 0.3});
    window.setTimeout("$('form').appear({from: 0.0, to: 1.0, duration: 0.3})", 300);
}

function submitBetaForm() {
    xajax_ActionController.doAction('ExternalBlog', 'submitBetaForm', xajax.getFormValues('betaSignupForm'));
}

function betaResult(result) {
    if(result == "mandatoryFields") {
        $('betaResultFail').appear({from: 0.0, to: 1.0, duration: 0.5});
    } else {
        $('betaResultSuccess').appear({from: 0.0, to: 1.0, duration: 0.5});
    }
}

function hideBetaResult(box) {
    
    $(box).hide({from: 1.0, to: 0.0, duration: 3.5});
}

//, {queue: {position: 'end', scope: 'toggleBG', limit: 1}}
//
////function sendEmailRequest(email) {
//    var url="/mini.php?method=registerEmail&email=" + email;
//    new Ajax.Request(url,
//        {
//            method:'get',
//            onSuccess: function(transport) {
//                showResult(transport.responseText);
//            }
//        });
//}
//
//function showResult(type) {
//    $('form').fade({from: 1.0, to: 0.0, duration: 0.3});
//    window.setTimeout("$('" + type + "').appear({from: 0.0, to: 1.0, duration: 0.3})", 300);
//}
//
//function hideResult(type) {
//    document.emailForm.reset();
//    $(type).fade({from: 1.0, to: 0.0, duration: 0.3});
//    window.setTimeout("$('form').appear({from: 0.0, to: 1.0, duration: 0.3})", 300);
//}
//
//function doBookmark() {
//    if(checkBrowserName('MSIE')){
//        window.external.AddFavorite('http://www.poisonville.com/', 'Poisonville - By Bigpoint');
//    } else {
//
//        window.sidebar.addPanel('Poisonville - By Bigpoint', 'http://www.poisonville.com/','');
//    }
//}
//
//function checkBrowserName(name){
//    var agent = navigator.userAgent.toLowerCase();
//    if (agent.indexOf(name.toLowerCase())>-1) {
//        return true;
//    }
//    return false;
//}
//
//
//var Video= {
//    loadVideo: function(url, width, height) {
//        var s1 = new SWFObject("inc/swf/mediaplayer.swf","ply",""+width+"",""+height+"","8","#FFFFFF");
//        s1.addParam("allowfullscreen","false");
//        s1.addParam("allowscriptaccess","always");
//        s1.addParam("flashvars","file="+url+"&default=&autostart=true&icons=false");
//        s1.write("player");
//
//        this.showVideo();
//    },
//    showVideo: function() {
//        //todo page shadow
//        Event.observe(document, "keypress", Video.videokillByESC);
//        $('mediaPlayer').style.display = "block";
//        //$('previewBox').removeClassName('hidden');
//        //Video.setVideoPosition('previewBox');
//
//    },
//
//    setVideoPosition: function(posBy) {
//        var dim = $(posBy).getDimensions();
//        var scl = document.viewport.getDimensions();
//        //var sDim = $('shadowLayer').getDimensions();
//        var scl2 = document.viewport.getScrollOffsets();
//        $(posBy).style.left = (sDim.width / 2) - (dim.width / 2) + "px";
//        $(posBy).style.top = (scl.height / 2) - (dim.height / 2) + "px";
//        //this.screenVideoBtn('show');
//    },
//
//
//    videokillByESC: function(e) {
//        if(e.keyCode == 27) {
//            Video.hideVideo();
//        }
//    },
//
//    hideVideo: function() {
//        //todo no more page shadow
//        //hide video overlay
//        $('mediaPlayer').style.display = "none";
//        Event.stopObserving(document, "keypress", Video.killByESC);
//    }
//}
//
//function twitterNow() {
//
//    var radioObj = $('twitterNowForm').elements['message'];
//
//    var radioLength = radioObj.length;
//    for(var i = 0; i < radioLength; i++) {
//        if(radioObj[i].checked) {
//            var message = radioObj[i].value;
//        }
//    }
//    var username = $('twitter_username').value;
//    var password = $('twitter_password').value;
//    var follow = $('follow').checked;
//    var url="/mini.php?method=twitterNow&message=" + message + "&username=" + username + "&password=" + password + "&follow=" + follow;
//    new Ajax.Request(url,
//        {
//            method:'get',
//            onSuccess: function(transport) {
//            }
//        });
//}