/**
 * @author Nils Dehl <nils.dehl@dkd.de>
 */

var Main = new Class({
	options: {},
	
	initialize: function(options){
		// init FX
		this.initFx();
		// IE PNG Fix
		this.iePNGfix();
		// Menu
		this.theMenu = new Menu();
		// Scroller
		if ($('content_background')){
			this.theScroller = new ExtScroller();
		}
		
	},
	
	initFx: function(){
		var container = $(par.content.id);
		//container.setStyle('visibillity','block');
		var fxRow = new Fx.Style(container, 'opacity', {duration:par.content.duration, wait:true}).start(0,1);
	},
	iePNGfix: function(){
				if (window.ie6){
					$$('img').each(function(el){
								
					if ( (el.getTag() == "img") && el.getProperty('src').test(".png")) {
						var bgURL  = el.getProperty('src');
						var height = el.getProperty('height');
						var width  = el.getProperty('width');
						
						if( bgURL && bgURL !== '' && bgURL !== null && bgURL !== 'none') {
							var bgMatch3 = bgURL.match(/http:\/\/.+[a-zA-Z]/);
							if ( bgMatch3 ) {
								bgURL = bgMatch3[0];
							} else if (bgURL.substr(0,1) != '/') {
								bgURL = '/' + bgURL;
							}
						}
						// if parent is a A Tag
						var parentEl = el.getParent();
						if (parentEl.getTag() == 'a') {
							el.setStyles({
								background: 'none',
								filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
							});
							el.setProperty('src', '/clear.gif');
							el.setProperty('width', width);
							el.setProperty('height', height);
							
							parentEl.setStyles({
									filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", sizingMethod="crop", src="' + bgURL + '")',
									display: 'inline-block'
								});
						} else {
							el.setStyles({
								background: 'none',
								filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
							});
							el.setProperty('src', '/clear.gif');
							el.setProperty('width', width);
							el.setProperty('height', height);
							
							// Insert new span
							tempDiv = new Element('span', {
								'styles': {
									filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", sizingMethod="crop", src="' + bgURL + '")',
									display: "inline-block"
								}
							});
							tempDiv.setProperty('width', width);
							tempDiv.setProperty('height', height);
							
							// Images with full width must be scaled
							if (el.getStyle('width') == "100%") {
								tempDiv.setStyles({
									filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", sizingMethod="scale", src="' + bgURL + '")'
								});
							}
							
							
							tempDiv.injectAfter(el).adopt(el);
						}
	
					}
	
				});
	
			}	
		}
	
	
});

Main.implement(new Options());

// If all DOM Elements are loaded initialize the Main Class.
window.addEvent('domready', function() {
	theMain = new Main();
});

 