 (function($){
	$.fn.pagePeel = function(options){

		var defaults = {

			// SET WIDTH / HEIGHT OF CORNER AD (SAME AS .SWF)
			smallWidth: 100,
			smallHeight: 100,
			smallBG: '/app/images/pp-src/smallBG.png',
			smallAd: '/app/images/pp-src/smallAd.jpg',
			smallSWF: '/app/images/pp-src/page-peel-small.swf',

			// SET WIDTH / HEIGHT OF INTRO AD (SAME AS .SWF)
			introWidth: 300,
			introHeight:300,
			introAd: '/app/images/pp-src/introAd.jpg',
			introSWF: '/app/images/pp-src/page-peel-intro.swf',

			// SET WIDTH / HEIGHT OF BIG AD (SAME AS .SWF)
			bigWidth: 500,
			bigHeight: 500,
			bigBG: '/app/images/pp-src/bigBG.png',
			bigAd: '/app/images/pp-src/bigAd.jpg',
			bigSWF: '/app/images/pp-src/page-peel-big.swf',

			// POSITION WILL REMAIN THE SAME FOR BOTH
			hPosition: 'right', // can use 'left' or 'right'
			vPosition: 'top', // can use 'top' or 'bottom'

			// CHOOSE WHETHER TO USE FLASH OR NOT
			flash: true,

			// WHETHER TO USE INTRO ANIMATION OR NOT
			introAnim: false,

			// ADD LINK IF LEFT 'BLANK', NO ADD LINK WILL BE APPLIED
			adLink: 'blank'
		};

		var options = $.extend(defaults, options);

		var element = this;

	return this.each(function(){

		if (options.flash === true){
			if (options.introAnim === true){
				$(element).before("<div id='page-peel-intro' style='width:" + options.introWidth + "px; height: " + options.introHeight + "px; display:block; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; z-index:9980;'><embed style='display: block;' src='" + options.introSWF + " 'flashvars='introURL=" + options.introAd + "' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' wmode='transparent' autoplay='false' width='" + options.introWidth + "' height='" + options.introHeight + "'></div> <div id='page-peel-big' style='width:" + options.bigWidth + "px; height: " + options.bigHeight + "px; display:none; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; z-index:9999;'><embed style='display: block;' src='" + options.bigSWF + "' flashvars='bigURL=" + options.bigAd + "&amp;linkURL=" + options.adLink + "' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' wmode='transparent' autoplay='false' width='" + options.bigWidth + "' height='" + options.bigHeight + "'></div><div id='page-peel-small' style='width:" + options.smallWidth + "px; height: " + options.smallHeight + "px; display:block; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; z-index:9990;'><embed style='display: block;' src='" + options.smallSWF + " 'flashvars='smallURL=" + options.smallAd + "' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' wmode='transparent' autoplay='false' width='" + options.smallWidth + "' height='" + options.smallHeight + "'></div>");
			} else {
				$(element).before("<div id='page-peel-small' style='width:" + options.smallWidth + "px; height: " + options.smallHeight + "px; display:block; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; z-index:9990;'><embed style='display: block;' src='" + options.smallSWF + " 'flashvars='smallURL=" + options.smallAd + "' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' wmode='transparent' autoplay='false' width='" + options.smallWidth + "' height='" + options.smallHeight + "'></div> <div id='page-peel-big' style='width:" + options.bigWidth + "px; height: " + options.bigHeight + "px; display:none; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; z-index:9999;'><embed style='display: block;' src='" + options.bigSWF + " 'flashvars='bigURL=" + options.bigAd + "' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' wmode='transparent' autoplay='false' width='" + options.bigWidth + "' height='" + options.bigHeight + "'></div>");
			}
		}

		if (options.flash === false){
			$(element).before("<div id='page-peel-small' style='width:" + options.smallWidth + "px; height: " + options.smallHeight + "px; display:block; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; background:url(" + options.smallBG + ") top left no-repeat; z-index:9999;'></div> <div id='page-peel-big' style='width:" + options.bigWidth + "px; height: " + options.bigHeight + "px; display:none; position:absolute; " + options.vPosition + ":0px; " + options.hPosition + ":0px; background:url(" + options.bigBG + ") top left no-repeat; z-index:9999;'></div>");
		}

		//$('#page-peel-small').css({border: "red 1px solid"});
		//$('#page-peel-big').css({border: "red 1px solid"});

		if (options.introAnim === true){

			$('#page-peel-small').hide();

			$('#page-peel-intro').mouseover(
				function(){
					$(this).hide();
					$('#page-peel-small').show();
				}
			);
		}

		$('#page-peel-small').mouseover(
			function(){
				// $(this).hide();
				$('#page-peel-big').stop().show();
			}
		);

		$('#page-peel-big').mouseout(
			function(){
				$(this).animate({right:'0px'},600).fadeOut('fast', function() {$(this).hide();});
				// $('#page-peel-small').show();
			}
		);
	});
		// alert ('page peel');

	};
})(jQuery);