/*******************************************************************************
    PageEar advertising CornerAd by Webpicasso Media
    Leave copyright notice.

    Lizenzvereinbarung / License agreement
    http://www.webpicasso.de/blog/lizenzvereinbarungen-license-agreements/

    @copyright www.webpicasso.de
    @author    christian harz <pagepeel-at-webpicasso.de>
    
    --
    Classe pageEar di Michele Manzato/Athesis Editrice
*******************************************************************************/


// PageEar singleton object
var pageEar = {
    // URL to small image
    smallImg : 'http://media.athesiseditrice.it/media/pageear/pageear_s.jpg',
    
    // URL zum großen Bild / URL to big image
    bigImg : 'http://media.athesiseditrice.it/media/pageear/pageear_b.jpg',
    
    // Movement speed of small pageear 1-4 (2:Standard)
    speedSmall : 1,
    
    // Mirror image ( true | false )
    mirror : 'true',

    // Color of pagecorner if mirror is false
    cornerColor : 'ffffff',

    // URL to open on pageear click
    jumpTo : 'http://www.webpicasso.de/blog/',
    
    // Browser target  (new) or self (self)
    openLink : 'new',
    
    // Opens pageear automaticly (false:deactivated | 0.1 - X seconds to open)
    openOnLoad : 'false',
    
    // Second until pageear close after openOnLoad
    closeOnLoad : 0,
    
    // Set direction of pageear in left or right top browser corner (lt: left | rt: right )
    setDirection : 'rt',
    
    // Fade in pageear if image completly loaded (0-5: 0:off, 1:slow, 5:fast )
    softFadeIn : 1,
    
    // Plays background music once abspielen (false:deactivated | URL:Mp3 File e.g. www.domain.de/mysound.mp3)
    playSound : 'false',
    
    // Play sound on opening peel (false:deactivated | URL:Mp3 File e.g. www.domain.de/mysound.mp3)
    playOpenSound : 'false',
    
    // Play sound on closing peel (false:deactivated | URL:Mp3 File e.g. www.domain.de/mysound.mp3)
    playCloseSound : 'false',
    
    // Peel close first if button close will be clicked
    closeOnClick : 'false',
    
    // Close text
    closeOnClickText : 'Close',
  
    // Size small peel
    thumbWidth : 100,
    thumbHeight : 100,

    // Size big peel
    bigWidth : 500,
    bigHeight : 500,

    // Css style default x-position
    xPos : 'right',
    
    // URL to small pageear swf
    smallSwf : mediaUrl + 'pageear/pageear_s.swf',

    // URL to big pageear swf
    bigSwf : mediaUrl + 'pageear/pageear_b.swf',

    // Write PageEar to $pe jQuery element
    write : function($pe) {
        // Test installed Flash version
        requiredMajorVersion = 6;
        requiredMinorVersion = 0;
        requiredRevision = 0;
        if (!DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {
//        	document.write('<!-- No flash installed -->');  //
            $pe.html('<!-- No flash installed -->');
        	return;
        }
        
        // Copyright message - leave as-is
        var copyright = 'Webpicasso Media, www.webpicasso.de';

        // GET - Params
        var queryParams = 'pagearSmallImg='+escape(this.smallImg);
        queryParams += '&pagearBigImg='+escape(this.bigImg);
        queryParams += '&pageearColor='+this.cornerColor;
        queryParams += '&jumpTo='+escape(this.jumpTo);
        queryParams += '&openLink='+escape(this.openLink);
        queryParams += '&mirror='+escape(this.mirror);
        queryParams += '&copyright='+escape(copyright);
        queryParams += '&speedSmall='+escape(this.speedSmall);
        queryParams += '&openOnLoad='+escape(this.openOnLoad);
        queryParams += '&closeOnLoad='+escape(this.closeOnLoad);
        queryParams += '&setDirection='+escape(this.setDirection);
        queryParams += '&softFadeIn='+escape(this.softFadeIn);
        queryParams += '&playSound='+escape(this.playSound);
        queryParams += '&playOpenSound='+escape(this.playOpenSound);
        queryParams += '&playCloseSound='+escape(this.playCloseSound);
        queryParams += '&closeOnClick='+escape(this.closeOnClick);
        queryParams += '&closeOnClickText='+escape(this.utf8encode(this.closeOnClickText));
        queryParams += '&lcKey='+escape(Math.random());
        queryParams += '&bigWidth='+escape(this.bigWidth);
        queryParams += '&thumbWidth='+escape(this.thumbWidth);
//        queryParams += '&bigHeight='+escape(this.bigHeight);
//        queryParams += '&thumbHeight='+escape(this.thumbHeight);

        // Check direction
        if (this.setDirection == 'lt') {
            xPosBig = 'left:-1000px';
            this.xPos = 'left';
        } else {
            xPosBig = 'right:1000px';
            this.xPos = 'right';
        }
    
        // Write div layer for big swf
        s = '<div id="pageearBigDiv" style="position:absolute;width:'+ this.bigWidth +'px;height:'+ this.bigHeight +'px;z-index:9999;'+xPosBig+';top:-100px;">';
    	s += AC_FL_RunContent(
    				"src", this.bigSwf+'?'+ queryParams,
    				"width", this.bigWidth,
    				"height", this.bigHeight,
    				"align", "middle",
    				"id", "pageearBigSwf",
    				"quality", "high",
    				"bgcolor", "#FFFFFF",
    				"name", "pageearBigSwf",
    				"wmode", "transparent",
    				"scale", "noscale",
    				"salign", "tr",
    				"allowScriptAccess","always",
    				"type", "application/x-shockwave-flash",
    				'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
    				"pluginspage", "http://www.adobe.com/go/getflashplayer");
        s += '</div>';

        // Write div layer for small swf
        s += '<div id="pageearThumbDiv" style="position:absolute;width:'+ this.thumbWidth +'px;height:'+ this.thumbHeight +'px;z-index:9999;'+this.xPos+':0px;top:0px;">';
    	s += AC_FL_RunContent(
    				"src", this.smallSwf+'?'+ queryParams,
    				"width", this.thumbWidth,
    				"height", this.thumbHeight,
    				"align", "middle",
    				"id", "pageearSmallSwf",
    				"scale", "noscale",
    				"quality", "high",
    				"bgcolor", "#FFFFFF",
    				"name", "pageearSmallSwf",
    				"wmode", "transparent",
    				"allowScriptAccess","always",
    				"type", "application/x-shockwave-flash",
    				'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
    				"pluginspage", "http://www.adobe.com/go/getflashplayer");
        s += '</div>';
        $pe.html(s);

        setTimeout('document.getElementById("pageearBigDiv").style.top = "-1000px";',100);
    },

    // Perform UTF-8 encoding
    // ??? Perché? E se fosse già UTF-8?
    utf8encode : function(txt) {
        txt = txt.replace(/\r\n/g,"\n");
        var utf8txt = "";
        for (var i = 0; i < txt.length; i++) {
            var uc = txt.charCodeAt(i);
            if (uc < 128) {
                utf8txt += String.fromCharCode(uc);
            } else if ((uc > 127) && (uc < 2048)) {
                utf8txt += String.fromCharCode((uc >> 6) | 192);
                utf8txt += String.fromCharCode((uc & 63) | 128);
            } else {
                utf8txt += String.fromCharCode((uc >> 12) | 224);
                utf8txt += String.fromCharCode(((uc >> 6) & 63) | 128);
                utf8txt += String.fromCharCode((uc & 63) | 128);
            }
        }
        return utf8txt;
    }
}

// Must be a global function
function openPeel(){
	document.getElementById('pageearBigDiv').style.top = '0px';
	document.getElementById('pageearBigDiv').style[pageEar.xPos] = '0px';
	document.getElementById('pageearThumbDiv').style.top = '-1000px';
}

// Must be a global function
function closePeel(){
	document.getElementById("pageearThumbDiv").style.top = "0px";
	document.getElementById("pageearBigDiv").style.top = "-1000px";
}

