function findFlash (flash) {
    if (document.all)
    {
        if (document.all[flash]) return document.all[flash];
        if (window.opera)
        {
            var movie = eval(window.document + flash);
            if (movie.SetVariable) return movie;
        }
        return;
    }
    if(document.layers)
    {
        if(document.embeds)
        {
            var movie = document.embeds[flash];
            if (movie.SetVariable) return movie;
        }
        return;
    }
    if (!document.getElementById) return;
    
    var movie = document.embeds[flash];
    if (movie.SetVariable) return movie;
    
    var movies = movie.getElementsByTagName('embed');
    if (!movies || !movies.length) return;
    
    movie = movies[0];
    if (movie.SetVariable) return movie;
    return;
}

function sendFlashVar(flash, file)
{
        var movie = findFlash(flash);
    if (movie) movie.SetVariable("file", file);
}

var lastSong = 0;
function getSong(min, max)
{
    if(min == 0 && max == 0) { min = 1; max = 32; }
    if(max == 0 && min > 0) var song = min;
    else {
        var r = parseInt(Math.random() * (max+1));
        var song = (r + min <= max ? r + min : r);
    }
    if(song < 33) lastSong = song;
    else if(song == 33) song = '';
    sendFlashVar('wcc_player', song);
}
var musicActive = 0;
function stopMusic()
{
    if(musicActive == 1)
    {
        getSong(33, 0);
        for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'wccplayer\','+I+')', (100-I)*4);
            setTimeout('hideStartContent(\'wccplayer\')', 400);
        musicActive = 0;
        setCookie(1);
    }
}
function playMusic()
{
    if(!musicActive)
    {
        setStartOpacity('wccplayer', 0);
        document.getElementById("wccplayer").style.display = "block";
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'wccplayer\','+I+')', (I*4) + 400);
        musicActive = 1;
        setCookie(0);
        setTimeout('getSong(lastSong, 0);', 1000);
    }
}

function nextTrack() { if(lastSong < 20) getSong(Math.min(20, lastSong+1), 0); }
function previousTrack() { if(lastSong > 1) getSong(Math.max(1, lastSong-1), 0); }

var next = 0;
var end = 0;
// Javascript Preloader of the Landingpage
function showSite()
{
    setTimeout('end = 1;', 10000)
    if(document.images && end == 0)
    {
        var nochmal = 0; fertig = 0; gesamt = 0;
        for(i in document.images)
        {
            if(document.images[i].src) tmp = document.images[i].src; else tmp = '';
            if(tmp.indexOf('pimps') >= 0)
            {
                while(!document.images[i].complete && next != 500) next++;
                if(next == 500) nochmal = 1; else fertig++;
                next = 0; gesamt++;
            }
        }
        document.getElementById('loadPercent').innerHTML = Math.round(Math.min(100, Math.max(0, (100/gesamt) * fertig)))+' %';
        if(nochmal == 0) setTimeout('document.getElementById("preloading").style.display = "none";', 200);
        else setTimeout('showSite()', 300);
    }
    else setTimeout('document.getElementById("preloading").style.display = "none";', 200);
    return;
}
showSite();

var imageCount = 0; instanceOpen = 0; activeSlideShow = 0; lastLink = 0;
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
              "A", "B", "C", "D", "E", "F");

function decToHex(num, radix)
// part of the hex-ifying functionality
{
var hexString = "";
while (num >= radix)
      {
       temp = num % radix;
       num = Math.floor(num / radix);
       hexString += hexVals[temp];
      }
hexString += hexVals[num];
return reversal(hexString);
}

function reversal(s) // part of the hex-ifying functionality
{
var len = s.length;
var trans = "";
for (i=0; i<len; i++)
    { trans = trans + s.substring(len-i-1, len-i); }
s = trans;
return s;
}

function convert(charCode) // this converts a given char to url hex form
{ return  "%" + decToHex(charCode, 16); }

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);
            
            if(c == 43) {
                utftext += convert(c);
            }
            else if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function showRegister(sid) {
        hideInstance(); hideInfos(); hideScreens(); hideImprint();
        showPopupContent('register', sid);
        return false;
}
function showInstance(){
        hideInfos(); hideScreens(); hideImprint(); hideReg();
        if(!instanceOpen) setStartOpacity('instance', 0);
        setStartOpacity('loading', 100);
        $('#thepimps1_content').html('');
		$('#thepimps1_special').html('');
        $('#thepimps1').hide();
        
        var win = window;
        width_x = win.innerWidth ? win.innerWidth : win.document.body.clientWidth;
        container_x = document.getElementById("instance").style.width.substr(0,document.getElementById("instance").style.width.length-2);
        document.getElementById("instance").style.left = ((width_x/2) - (container_x/2))+"px";
        document.getElementById("instance").style.top = "180px";
        document.getElementById("loading").style.display = "block";
        document.getElementById("instance").style.display = "block";
        if(!instanceOpen) for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'instance\','+I+')', (I*4) + 400);
        instanceOpen = 1;
        return false;
}

function showFlags(){
        document.getElementById("flags").style.display = "block";
}
function hideFlags(){
        document.getElementById("flags").style.display = "none";
}

function showScreens(){
    hideInfos(); hideInstance(); hideImprint(); hideReg();
    setStartOpacity('screenshots', 0);
    setStartOpacity('screenshot', 0);
        document.getElementById("screenshots").style.display = "block";
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'screenshots\','+I+')', (I*4) + 400);
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'screenshot\','+I+')', (I*4) + 400);
        if(!activeSlideShow){ slideShow(); activeSlideShow = 1; }
}
function hideScreens(){
        for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'screenshots\','+I+')', (100-I)*4);
        setTimeout('hideStartContent(\'screenshots\')', 400);
}
function showInfos(){
    hideScreens(); hideInstance(); hideImprint(); hideReg();
    setStartOpacity('infos', 0);
    var win = window;
        width_x = win.innerWidth ? win.innerWidth : win.document.body.clientWidth;
        container_x = document.getElementById("infos").style.width.substr(0,document.getElementById("infos").style.width.length-2);
        document.getElementById("infos").style.left = ((width_x/2) - (container_x/2))+"px";
        document.getElementById("infos").style.top = "85px";
        document.getElementById("infos").style.display = "block";
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'infos\','+I+')', (I*4) + 400);
}
function hideInfos(){
        for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'infos\','+I+')', (100-I)*4);
        setTimeout('hideStartContent(\'infos\')', 400);
}
function hideReg(){
        $("#layer").fadeOut(1000);
}
function hideInstance(){
    for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'instance\','+I+')', (100-I)*4);
        setTimeout('hideStartContent(\'instance\')', 400);
        instanceOpen = 0;
}

function showImprint(){
        hideScreens(); hideInstance(); hideInfos(); hideReg();
        setStartOpacity('imprint', 0);
        document.getElementById('imprint').style.display='block';
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'imprint\','+I+')', (I*4) + 400);
}

function slideShow(){
    nextScreen();
    setTimeout('slideShow()', 4000);
}

function hideImprint(){
        for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'imprint\','+I+')', (100-I)*4);
        setTimeout('hideStartContent(\'imprint\')', 400);
}
function nextScreen(){
        imageCount++;
        if (imageCount > 9) imageCount = 1;
        for(var I=96;I>0;I=I-1) setTimeout('setStartOpacity(\'screenshot\','+I+')', (100-I)*4);
        setTimeout('setScreen('+imageCount+')', 500);
        for(var I=0;I<96;I=I+1) setTimeout('setStartOpacity(\'screenshot\','+I+')', (I*4) + 800);
}

function setScreen(c) { document.getElementById("screenshot").innerHTML = '<img src="images/de/screenshots/screen0'+c+'.jpg">'; }

function checkEnterKey(e)
{
    var key;
    if(window.event) key = window.event.keyCode;     //IE
    else key = e.which;     //firefox
    
    if(key == 13) link('login');
    else return true;
}