var iPhone = navigator.userAgent.match (/iPhone/i);

var Popables = new Class(
	{
		initialize: function(element) {
		
			var imgsrc = element.getAttribute("src");

			var overimgsrc = imgsrc.replace(".gif", "_over.gif");
			overimgsrc = overimgsrc.replace(".jpg", "_over.jpg");
			overimgsrc = overimgsrc.replace(".png", "_over.png");

			var popimgsrc = imgsrc.replace(".gif", "_pop.gif");
			popimgsrc = popimgsrc.replace(".jpg", "_pop.jpg");
			popimgsrc = popimgsrc.replace(".png", "_pop.png");

			var popelOuter = new Element('div', { 'class': 'hoverable' } );
			popelOuter.setStyle('background-position','50% 100%');
			popelOuter.setStyle('background-repeat','no-repeat');
			popelOuter.setStyle('height','0px');
			popelOuter.setStyle('overflow','hidden');
			popelOuter.setStyle('width','100%');
			popelOuter.setOpacity('0');

			popelOuter.inject(element,'before');
			element.remove();

			// preload first image and slide it in once loaded
			var preloadImage = new Element('img', { 'class': 'preload' }  );
			preloadImage.addEvent( 'load', function() { 
				popelOuter.setStyle('background-image','url('+imgsrc+')');
				popelOuter.setStyle('display','block');
				if ( iPhone ) {
					popelOuter.setStyle('height',preloadImage.height);
					popelOuter.setOpacity(1);
				} else {
					var revealfader = new Fx.Styles(popelOuter, {duration:500, wait:false, fps:30});
					revealfader.start( { 'height': preloadImage.height, 'opacity': 1 } ); 				

					var popelInner = new Element('div', { 'class': 'showwhenhovering' } );			
					
					popelInner.setStyle('background-position','50% 100%');
					popelInner.setStyle('background-repeat','no-repeat');
					popelInner.setStyle('width','100%');
					popelInner.setOpacity('0');

					popelInner.inject(popelOuter);

					popelInner.setStyle('height',preloadImage.height); 
					
					// once that's done - preload hover image and then setup mouse events
					var preloadOverImage = new Element('img', { 'class': 'preload' }  );
					preloadOverImage.addEvent( 'load', function() { 
						popelInner.setStyle('background-image','url('+overimgsrc+')');
						popelInner.setStyle('display','block');
						var hoverfader = new Fx.Styles(popelInner, {duration:500, wait:false, fps:30});
						popelOuter.addEvent( 'mouseover', function () { hoverfader.start({ 'opacity' : '1' });  } );
						popelOuter.addEvent( 'mouseout', function () { hoverfader.start({ 'opacity' : '0' }); } );
					} );
					preloadOverImage.setAttribute ('src', overimgsrc );
				}
				/* image popper */				
				popelOuter.addEvent( 
					'click', 
					function () { 
						var popcancel = false;
						var popfader;
						var winsize = window.getSize();
						var docwidth = winsize.scrollSize.x;
						var docheight = winsize.scrollSize.y;
						var vertscrollpos = winsize.scroll.y;
						var horzscrollpos = winsize.scroll.x;
						var windowwidth = winsize.size.x;
						var windowheight = winsize.size.y;

						var popdiv = new Element('div', { id: 'screenbackoverlay' } );
						popdiv.addEvent( 'click', function () {
							popcancel = true;
							var sbo = $('screenbackoverlay');
							if ( sbo != null ) { sbo.remove(); }
							var pui = $('popimg');
							if ( pui != null ) { pui.remove(); }
							window.removeEvents('resize');
						} );
						popdiv.setStyle('display','block');
						popdiv.setStyle('position','absolute');
						popdiv.setStyle('margin','0px');
						popdiv.setStyle('top','0px');
						popdiv.setStyle('left','0px');
						popdiv.setStyle('height', docheight );
						popdiv.setStyle('width', docwidth );
						popdiv.setStyle('z-index','1000');
						popdiv.setStyle('visibility','hidden');
						popdiv.setStyle('opacity','0');
						popdiv.inject($('bd'));
						
						window.addEvent( 'resize', function() {
							popcancel = true;
							var sbo = $('screenbackoverlay');
							if ( sbo != null ) { sbo.remove(); }
							var pui = $('popimg');
							if ( pui != null ) { pui.remove(); }						
							window.removeEvents('resize');
						} );

						var popfader = new Fx.Styles(popdiv, {duration:500, wait:false});
						popfader.start({ 'opacity': '.85' });

						var preloadPopImage = new Element('img', { 'class': 'preload' }  );
						preloadPopImage.addEvent( 'load', function() { 
							var imgel = new Element('img', { id: 'popimg', src: popimgsrc } );
							imgel.addEvent( 'click', function () { 
								var sbo = $('screenbackoverlay');
								if ( sbo != null ) { sbo.remove(); }
								var pui = $('popimg');
								if ( pui != null ) { pui.remove(); }
								window.removeEvents('resize');
							} );
							imgel.setStyle('position','absolute');
							var vcalc = vertscrollpos + ( windowheight / 2 ) - ( preloadPopImage.height / 2 );
							imgel.setStyle('top',vcalc + 'px');
							var hcalc = horzscrollpos + ( windowwidth / 2 ) - ( preloadPopImage.width / 2 );
							imgel.setStyle('left', hcalc + 'px ');
							imgel.setStyle('z-index','1000');
							imgel.setStyle('visibility','hidden');
							imgel.setStyle('opacity','0');
							if ( !popcancel ) {
								imgel.inject($('bd'));
								var popfadertwo = new Fx.Styles(imgel, {duration:750, wait:false});
								popfadertwo.start({ 'opacity': '1' });
							}
						} );
						preloadPopImage.setAttribute ('src', popimgsrc );
					} 
				);
				/* end image popper */				
			} );
			preloadImage.setAttribute ('src', imgsrc );
		}
	}
);
var Hoverables = new Class(
	{
		initialize: function(element) {
		
			var imgsrc = element.getAttribute("src");

			var overimgsrc = imgsrc.replace(".gif", "_over.gif");
			overimgsrc = overimgsrc.replace(".jpg", "_over.jpg");
			overimgsrc = overimgsrc.replace(".png", "_over.png");

			var popelOuter = new Element('div', { 'class': 'hoverable' } );
			popelOuter.setStyle('background-position','50% 100%');
			popelOuter.setStyle('background-repeat','no-repeat');
			popelOuter.setStyle('height','0px');
			popelOuter.setStyle('overflow','hidden');
			popelOuter.setStyle('width','100%');
			popelOuter.setOpacity('0');

			popelOuter.inject(element,'before');
			element.remove();

			// preload first image and slide it in once loaded
			var preloadImage = new Element('img', { 'class': 'preload' }  );
			preloadImage.addEvent( 'load', function() { 
				popelOuter.setStyle('background-image','url('+imgsrc+')');
				popelOuter.setStyle('display','block');
				if ( iPhone ) {
					popelOuter.setStyle('height',preloadImage.height);
					popelOuter.setOpacity(1);
				} else {
					var revealfader = new Fx.Styles(popelOuter, {duration:500, wait:false, fps:30});
					revealfader.start( { 'height': preloadImage.height, 'opacity': 1 } ); 				

					var popelInner = new Element('div', { 'class': 'showwhenhovering' } );			
					
					popelInner.setStyle('background-position','50% 100%');
					popelInner.setStyle('background-repeat','no-repeat');
					popelInner.setStyle('width','100%');
					popelInner.setOpacity('0');

					popelInner.inject(popelOuter);

					popelInner.setStyle('height',preloadImage.height); 
					
					// once that's done - preload hover image and then setup mouse events
					var preloadOverImage = new Element('img', { 'class': 'preload' }  );
					preloadOverImage.addEvent( 'load', function() { 
						popelInner.setStyle('background-image','url('+overimgsrc+')');
						popelInner.setStyle('display','block');
						var hoverfader = new Fx.Styles(popelInner, {duration:500, wait:false, fps:30});
						popelOuter.addEvent( 'mouseover', function () { hoverfader.start({ 'opacity' : '1' });  } );
						popelOuter.addEvent( 'mouseout', function () { hoverfader.start({ 'opacity' : '0' }); } );
					} );
					preloadOverImage.setAttribute ('src', overimgsrc );

				}
								
			} );
			preloadImage.setAttribute ('src', imgsrc );
		}
	}
);

var slideInImage = new Class(
	{
		initialize: function(element) {
			if ( iPhone ) {
				element.setStyle( 'display', 'inline' );
			} else {
				this.imgsrc = element.getAttribute("src");
				this.slider = new Element('div', { 'class': 'slidein' } );
				this.slider.setStyle('background-position','50% 100%');
				this.slider.setStyle('background-repeat','no-repeat');
				this.slider.setStyle('height','0px');
				this.slider.setStyle('overflow','hidden');
				this.slider.setStyle('width','100%');
				this.slider.setOpacity('0');
				this.slider.inject(element,'before');
				element.remove();
				this.preloadOverImage = new Element('img', { 'class': 'preload' }  );

				this.preloadOverImage.addEvent( 'load', this.loadComplete.bind(this) );

//				preloadOverImage.addEvent( 'load', function() { 
//					slider.setStyle('background-image','url('+imgsrc+')');
//					slider.setStyle('display','block');
//					var revealfader = new Fx.Styles(slider, {duration:1000, wait:false, fps:30});
//					revealfader.start( { 'height': preloadOverImage.height, 'opacity': 1 } ); 
//				} );

				this.preloadOverImage.setAttribute ('src', this.imgsrc );
			}
		},
		loadComplete: function() { 
			this.slider.setStyle('background-image','url('+this.imgsrc+')');
			this.slider.setStyle('display','block');
			this.revealfader = new Fx.Styles(this.slider, {duration:1000, wait:false, fps:30});
			this.revealfader.start( { 'height': this.preloadOverImage.height, 'opacity': 1 } ); 
		}
	}
);

var InlineSlideShow = new Class(
	{
		showIndex:-1,
		totalShowCount: 1,
		initialdelay: 100,
		imagechangeinterval: 1000,
		transitiontime: 500,
		slideindex: -1,
		faders: {},
		showimages: {},
		initialize: function( theShowDiv, showIndex, totalShowCount ) {
			this.showDiv = theShowDiv;
			this.showIndex = showIndex;
			this.totalShowCount = totalShowCount;
			this.showDiv.setStyle('position','relative');
			this.showDiv.setStyle('overflow','hidden');
			this.showDiv.setStyle('height','187px');
			this.showDiv.setStyle('width','187px');
			this.showimages = theShowDiv.getElements('img');
			for ( var i = 0; i < this.showimages.length; i++ ) {
					this.showimages[i].setStyle('position','absolute');
					this.showimages[i].setStyle('z-index',100 + i );
					this.showimages[i].setStyle('top',0);
					this.showimages[i].setStyle('left',0);
					this.showimages[i].setOpacity(0);
					this.showimages[i].setStyle('display','block');
					this.faders[i] = new Fx.Styles( this.showimages[i], {duration: this.transitiontime, wait:false});
			}
			if ( this.showimages.length > 0 ) {
				this.faders[0].start({ 'opacity': 1 }); 
				this.showimages[0].setOpacity(1);
			}
			if ( this.showimages.length > 1 ) {
				this.delayedSetupFunciton.delay( ( ( 1 + showIndex ) * this.imagechangeinterval ) + this.transitiontime + this.initialdelay, this );
//				this.delayedSetupFunciton.delay( this.imagechangeinterval + this.transitiontime, this );
			}
		},
		delayedSetupFunciton: function() {
			this.animateFunction();
			this.animateFunction.periodical( this.imagechangeinterval, this );
		},
		animateFunction: function() {
			var lastToShow = this.slideindex;
			this.slideindex = this.slideindex + 1;
			if ( this.slideindex >= this.showimages.length ) { this.slideindex = 0; }
			var nextToShow = this.slideindex;
				this.showimages[nextToShow].setOpacity(1);
				this.faders[nextToShow].start({ 'opacity': 1 });
			if ( lastToShow >= 0 ) { 
				this.showimages[lastToShow].setOpacity(0);
				this.faders[lastToShow].start({ 'opacity': 0 }); 
			}
		}
	}
);

var notInlineSlides = new Class(
	{
		slideShowObjs:{},
		initialize: function(selector) {
			var divs = $$(selector);
			for ( var i = 0; i < divs.length; i++ ) {
				this.slideShowObjs[i] = new InlineSlideShow( divs[i], i, divs.length );
			}
		}
	}
);

var InlineSlides = new Class(
	{
		initialize: function(selector) {
			this.selector = selector;
			var divs = $$(selector);
			divs.each(function( theDiv, theIndex, theArray ){ this.createInlineSlideShow( theDiv, theIndex, theArray ); }, this);
		},

		createInlineSlideShow: function(aDiv, divIndex, theDivs ) {
			var initialdelay = 100;
			var imagechangeinterval = 3000;
			var transitiontime = 1000;
			var slideindex = -1;
			if ( theDivs.length == 1 ) { imagechangeinterval = imagechangeinterval * 2; }
			var showimages = aDiv.getElements('img');
			if ( showimages.length > 1 ) {
				var nextImageDiv = new Element('div', { 'id': 'nextImageDiv', 'style': '{ display:block; margin:0px; padding:0px; height:187px; width:187px; }' });
				var lastImageDiv = new Element('div', { 'id': 'lastImageDiv', 'style': 'display:block; margin:0px; padding:0px; height:187px; width:187px;' });
				lastImageDiv.adopt(nextImageDiv);
				aDiv.adopt( lastImageDiv );
				var fader = new Fx.Styles( nextImageDiv, {duration: transitiontime, wait:false});
				var appearancefader = new Fx.Styles( nextImageDiv, {duration: transitiontime, wait:false});
				var animateFunction = function() {
					slideindex = slideindex + 1;
					if ( slideindex >= showimages.length ) { slideindex = 0; }
					nextImageDiv.setOpacity(0);
					lastImageDiv.setStyle ( 'background-image', nextImageDiv.getStyle('background-image') );
					nextImageDiv.setStyle ( 'background-image', 'url('+showimages[slideindex].getProperty('src')+')' );
					fader.start({ 'opacity': '1' });
				}
				var setupFunciton = function() {
					animateFunction();
					animateFunction.periodical( imagechangeinterval * theDivs.length );
				}
				slideindex = slideindex + 1;
				nextImageDiv.setOpacity(0);
				nextImageDiv.setStyle ( 'background-image', 'url('+showimages[slideindex].getProperty('src')+')' );
				appearancefader.start({ 'opacity': '1' });
				setupFunciton.delay( ( ( 1 + divIndex ) * imagechangeinterval ) + transitiontime + initialdelay );
			} else {
				if ( showimages.length == 1 ) {
					aDiv.setStyle ( 'background-image', 'url('+showimages[0].getProperty('src')+')' );
				}
			}
		}
	}
);

var IGButtonMenuClass = new Class(
	{
		initialize: function( moddiv ) {
			var cleanupfunc = function () {
				var parent = moddiv.getParent();
				var grandparent = parent.getParent();
				grandparent.adopt(moddiv);
				parent.remove();
			}
			moddiv.setStyle('display','block');
			var mySlide = new Fx.Slide( moddiv, { duration: 1000, onComplete: cleanupfunc } );
			mySlide.hide();
			mySlide.toggle();
			var menuitems = moddiv.getElements('a');
			menuitems.each ( 
				function ( item ) {
					var id = item.getAttribute('id');
					if ( id != 'current') { 
						item.setStyle('color','#FFF'); 
						item.setStyle('font-size','9px'); 
						item.setStyle('height','30px');
						item.setStyle('line-height','30px'); 
						var igbuttonfader = new Fx.Styles(item, {duration:500, wait:false, fps:30});
						item.addEvent( 'mouseover', function () { 
							igbuttonfader.stop(); 
							item.setStyle('color','#FF0'); 
							item.setStyle('font-size','12px'); 
						} );
						item.addEvent(
							'mouseout', 
							function () { 
								igbuttonfader.start( { 'color': '#FFF','font-size': '10px' } );
							}
						);
					}
				}
			);
		}
	}
);
var slideEffectClass = new Class (
	{
		initialize: function( slidesdiv ) {
			// how did the world forget what object oriented programming is all about?			
			this.startProcessing = this.startProcessingPrototype.bind(this);
			this.setUpPeriodicalUpdate = this.setUpPeriodicalUpdatePrototype.bind(this);
			this.periodicUpdate = this.periodicUpdatePrototype.bind(this);

			this.interval = 3000;
			this.transitionTime = 1000;
			this.initialdelay = 10;
			this.thediv = slidesdiv;
			this.showwidth = slidesdiv.getStyle('width');
			this.showheight = slidesdiv.getStyle('height');
			this.loaded = new Array();
			this.imgurls = new Array();
			this.imgels = new Array();
			this.slides = new Array();
			this.slidefx = new Array();
			this.slidedivs = slidesdiv.getElements('div.cdwslide');
			this.slideCount = this.slidedivs.length;
			this.nextToLoad = 0;
			this.showing = -1;
			this.loading = -1;

		},
		startProcessingPrototype: function ( initialdelay, slideinterval ) {
			this.interval = slideinterval;
			if ( this.interval < this.transitionTime * 2 ) { this.interval = this.transitionTime * 2; }
			this.initialdelay = initialdelay;
			for ( var i = 0; i < this.slideCount; i++ ) {
				this.loaded[i] = false;
				this.imgurls[i] = this.slidedivs[i].getAttribute('slide');
				this.slidefx[i] = new Fx.Styles(this.slidedivs[i], {duration:this.transitionTime, wait:false, fps:15 });
			}
			this.preload();
		},
		startShow: function () {
			if ( this.loaded[0] ) { this.initialShowTransition( 0 ); }
			this.setUpPeriodicalUpdate.delay( this.initialdelay );
		},
		setUpPeriodicalUpdatePrototype: function() {
			this.periodicUpdate();
			this.periodicUpdate.periodical(this.interval);
		},
		periodicUpdatePrototype: function () {
			var nextImage = this.showing + 1;
			if ( nextImage >= this.slideCount ) { nextImage = 0; }
			if ( this.loaded[nextImage] ) { this.transitionTo( nextImage ); }
		},
		slideInitialSetup: function ( slideIndex ) {
			this.slidedivs[slideIndex].setOpacity( 0 );
			this.slidedivs[slideIndex].setStyle( 'background-position', 'center center' );
			this.slidedivs[slideIndex].setStyle( 'background-image', 'url(' + this.imgurls[slideIndex] + ')' );
		},
		initialShowTransition: function ( index ) {
			this.slidedivs[index].setOpacity( 0 );
			this.slidedivs[index].setStyle( 'left', 'auto' );
			this.slidedivs[index].setStyle( 'right', 0 );
			this.slidedivs[index].setStyle( 'width', this.showwidth );
			this.slidedivs[index].setStyle( 'bottom', 0 );
			this.slidedivs[index].setStyle( 'top', 'auto' );
			this.slidedivs[index].setStyle( 'height', this.showheight );
			this.slidedivs[index].setStyle( 'z-index', 201 );
			this.slidefx[index].start( { 'opacity': 1 } );
			this.showing = index;
		},
		showTransition: function ( index ) {
			this.slidedivs[index].setStyle( 'z-index', 201 );
			this.slidedivs[index].setStyle( 'left', 0 );
			this.slidedivs[index].setStyle( 'right', 'auto' );
			this.slidedivs[index].setStyle( 'width', 0 );
				this.slidefx[index].start( { 'width': this.showwidth, 'opacity': 1 } );
		},
		hideTransition: function ( index ) {
			if ( index >= 0 ) {
				this.thediv.setStyle('background-image','none');
				this.slidedivs[index].setStyle( 'left', 'auto' );
				this.slidedivs[index].setStyle( 'right', 0 );
				this.slidedivs[index].setStyle( 'z-index', 202 );
				this.slidefx[index].start( { 'width': 0, 'opacity': 0 } );
			}
		},
		transitionTo: function ( showIndex ) {
			this.hideTransition( this.showing );
			this.showTransition(showIndex);
			this.showing = showIndex;
		},
		preload: function () {
			if ( this.nextToLoad < this.slideCount ) { 
				if ( this.loading == -1 ) { // not needed since we only recur from the load complete function...
					this.loading = this.nextToLoad;
					this.nextToLoad = this.nextToLoad + 1;
					this.imgels[this.loading] = new Element('img', { 'class': 'preload' }  );
					var loadcompletefunc = this.loadCompletePrototype.bind(this);
					this.imgels[this.loading].addEvent( 'load', function () { loadcompletefunc(); } );
					this.imgels[this.loading].setAttribute ('src', this.imgurls[this.loading] );
				}
			} else {
			}
		},
		loadCompletePrototype: function () {
			this.loaded[this.loading] = true;
			this.slideInitialSetup(this.loading);
			if ( this.loading == 0 ) { this.startShow(); }
			this.loading = -1;
			this.preload();
		}
	}
);
var applyEffectsClass = new Class(
	{	// It should be faster to do all the scan for objects that need effects in one pass
		initialize: function() {
			this.slideincount = 0;
			this.slideineffects = new Array();
			this.popcount = 0;
			this.popableeffects = new Array();
			this.hovercount = 0;
			this.hoverableeffects = new Array();
			this.menucount = 0;
			this.menueffects = new Array();
			this.slidecount = 0;
			this.slideeffects = new Array();
			var objs = $$('img.slidein, img.popable, img.hoverable, #ja-col1 .mod_mainmenu, div.cdwslides');
			objs.each( // note the binding to this //
				function ( obj ) { 
					var tag = obj.getTag();
					switch ( tag ) {
						case 'img':
							if ( obj.hasClass('slidein') ) {
								this.slideineffects[this.slideincount] = new slideInImage (obj);
								this.slideincount = this.slideincount + 1;
							}
							if ( obj.hasClass('popable') ) {
								this.popableeffects[this.popcount] = new Popables (obj);
								this.popcount = this.popcount + 1;
							}
							if ( obj.hasClass('hoverable') ) {
								this.hoverableeffects[this.hovercount] = new Hoverables (obj);
								this.hovercount = this.hovercount + 1;
							}
						break;
						case 'div':
							if ( obj.hasClass('mod_mainmenu') ) {
								this.menueffects[this.menucount] = new IGButtonMenuClass (obj);
								this.menucount = this.menucount + 1;
							}
							if ( obj.hasClass('cdwslides') ) {
								this.slideeffects[this.slidecount] = new slideEffectClass (obj);
								this.slidecount = this.slidecount + 1;
							}
						break;
					}
				},
				this // note the binding to this //
			);
			for ( var i = 0; i < this.slidecount; i++ ) {
				this.slideeffects[i].startProcessing( ( i * 1000 ) + 5000, 5000 + ( this.slidecount * 1000 ) );
			}
		}
	}
);


document.slides = null;
document.applyeffects = null;
window.addEvent( 'domready', function() {
	var slides = new InlineSlides('div.inlineslides'); 
	document.slides = slides;
	var applyeffects = new applyEffectsClass();
	document.applyeffects = applyeffects;
} );


sfHover = function() {
	var sfEls = document.getElementById("ja-mainnav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; ++i) {
		sfEls[i].onmouseover=function() {
			clearTimeout(this.timer);
			if(this.className.indexOf(" sfhover") == -1) {
				this.className+=" sfhover";
			}
		}
		sfEls[i].onmouseout=function() {
			this.timer = setTimeout(sfHoverOut.bind(this), 20);
		}
	}
}

function sfHoverOut() {
	clearTimeout(this.timer);
	this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

switchFontSize=function(ckname,val){
	var bd = $E('body');
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);		
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}

function fixIEPNG(el, bgimgdf, sizingMethod, type, offset){
	var objs = el;
	if(!objs) return;
	if ($type(objs) != 'array') objs = [objs];
	if(!sizingMethod) sizingMethod = 'crop';
	if(!offset) offset = 0;
	var blankimg = siteurl + 'images/blank.png';
	objs.each(function(obj) {
		var bgimg = bgimgdf;
		if (obj.tagName == 'IMG') {
			//This is an image
			if (!bgimg) bgimg = obj.src;
			if (!(/\.png$/i).test(bgimg) || (/blank\.png$/i).test(bgimg)) return;

			obj.setStyle('height',obj.offsetHeight);
			obj.setStyle('width',obj.offsetWidth);
			obj.src = blankimg;
			obj.setStyle ('visibility', 'visible');
			obj.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
		}else{
			//Background
			if (!bgimg) bgimg = obj.getStyle('backgroundImage');
			var pattern = new RegExp('url\s*[\(\"\']*([^\'\"\)]*)[\'\"\)]*');
			if ((m = pattern.exec(bgimg))) bgimg = m[1];
			if (!(/\.png$/i).test(bgimg) || (/blank\.png$/i).test(bgimg)) return;
			if (!type)
			{
				obj.setStyle('background', 'none');
				//if(!obj.getStyle('position'))
				if(obj.getStyle('position')!='absolute' && obj.getStyle('position')!='relative') {
					obj.setStyle('position', 'relative');
				}

				//Get all child
				var childnodes = obj.childNodes;
				for(var j=0;j<childnodes.length;j++){
					if((child = $(childnodes[j]))) {
						if(child.getStyle('position')!='absolute' && child.getStyle('position')!='relative') {
							child.setStyle('position', 'relative');
						}
						child.setStyle('z-index',2);
					}
				}
				//Create background layer:
				var bgdiv = new Element('IMG');
				bgdiv.src = blankimg;
				bgdiv.width = obj.offsetWidth - offset;
				bgdiv.height = obj.offsetHeight - offset;
				bgdiv.setStyles({
					'position': 'absolute',
					'top': 0,
					'left': 0
				});

				bgdiv.className = 'TransBG';

				bgdiv.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
				bgdiv.inject(obj, 'top');
				//alert(obj.innerHTML + '\n' + bgdiv.innerHTML);
			} else {
				obj.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
			}
		}
	}.bind(this));
}
