/********************************************************************************************
* PageEar advertising CornerAd by Webpicasso Media
* Leave copyright notice.  
*
*  License agreement
* http://www.webpicasso.de/blog/lizenzvereinbarungen-license-agreements/
*
*	Ported to JQuery by Daniel Rolls
*	Requires:
*		flash/pageear_b.swf
*		flash/pageear_s.swf
*		scripts/swfobject.js
*	To use simply call pageEar() on some element - usually a DIV or the BODY 
*  	To use:
*
*		$('body').pageEar({
*				pagearSmallImg: '/images/pagepeel/small_image.jpg', 
*				pagearBigImg: '/images/pagepeel/large_image.jpg', 
*				mirror: 'true', 
*				jumpTo:'http://www.domain.com/linked-url.htm'
*			});
*
*	See the variable 'defaults' below for a full list of options.
*
* @copyright www.webpicasso.de
* @author    christian harz <pagepeel-at-webpicasso.de>
*********************************************************************************************/
  

/*
 *   Configuration
 */ 
(function($){
	$.fn.pageEar = function(options){
		
		window.openPeel = function() {
				$('div#bigDiv').css('top','0px'); 
				$('div#bigDiv').css('right', '0px');
				$('div#thumbDiv').css('top','-1000px');
		}
		window.closePeel = function() {
				$('div#thumbDiv').css('top','0px'); 
				$('div#bigDiv').css('top','-1000px'); 
		}
	
		var defaults = {
			
			//  URL to small image 
			pagearSmallImg: '/images/pagepeel/pageear_s.jpg', 
			//  URL to big image
			pagearBigImg: '/images/pagepeel/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
			pageearColor: '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: 4, 
			// 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, 
			// Don't change
			copyright: 'Webpicasso Media, www.webpicasso.de',
			// 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',
            afterClicked: function(){ },
            afterPeel: function() {},
			lcKey: escape(Math.random()),
			thumbWidth: 160,
			bigWidth: 450
			
		};
		
		var SWFfiles  = {
            pagearSmallSwf: '/cms_images/flash/pageear_small.swf',
            pagearBigSwf:'/cms_images/flash/pageear_big.swf'
		};
		
		var options = $.extend(defaults, options);
		
		// Do not change these:
		var settings = {
			
			// Css style default x-position
			xPos: 'right'
		};
		
		var element = this;
		
		var instantiated = false;	
		
		return this.each(function(){
               
				if(!this.instantiated){
					this.instantiated=true;
			
					// Check direction 
					if(options.setDirection == 'lt') {
						xPosBig = 'left:-1000px';  
						xPos = 'left';   
					} else {
						xPosBig = 'right: 1000px';
						xPos = 'right';              
					}
					
					// Write div layer for small swf
					$(element).prepend('<div id="thumbDiv" style="position:absolute;width:'+ options.thumbWidth +'px;height:'+ options.thumbWidth +'px;z-index:9999;'+xPos+':0px;top:0px;"><div id="innerThumbDiv"></div></div>');

					swfobject.embedSWF( SWFfiles.pagearSmallSwf, 'innerThumbDiv', options.thumbWidth, options.thumbWidth, '6.0.65','expressInstall.swf', options, {  scale: 'noscale', wmode: 'transparent', quality: 'high', allowScriptAccess: 'always' });

					// Write div layer for big swf
					$(element).prepend('<div id="bigDiv" style="position:absolute;width:'+ options.bigWidth +'px;height:'+ options.bigWidth +'px;z-index:9999;'+xPosBig+';top:-100px;"><div id="innerBigDiv"></div></div>' );    	
				
					// Check if flash exists/ version matched
					swfobject.embedSWF(SWFfiles.pagearBigSwf, 'innerBigDiv', options.bigWidth, options.bigWidth, '6.0.65','expressInstall.swf', options, { scale: 'noscale', wmode: 'transparent', quality: 'high', allowScriptAccess: 'always' });
                    
                    $('#thumbDiv').mouseover(function(){
                        if( options.afterPeel)
                            options.afterPeel.call(this);
                    });
                    
					$('#bigDiv').click(function(){
                        if( options.afterClicked)
                            options.afterClicked.call(this);
                    });
                    
                    
					// Check if flash exists/ version matched\

					setTimeout("window.closePeel()",300);
					
				}
        });
				

	};
})(jQuery);

