// Custom alerts


var FixIE6 = new Class({
	Implements: [Options, Events],
	
	options:
	{
		AD_CssSelector:['.ie6fix','#nav a'], //css selector with pre-ceeding . or # etc
		AD_Dimension:'width', //can be: 'width', 'height', 'both'
		FI_CssSelector:['#pentagon_img'],
		FI_XPath:'/imgs/blank.gif',
		BG_CssSelector:$empty
	},
	
	initialize: function(options)
	{
		//alert("ie6 initialized");
		
		this.setOptions(options);
	
		//initialise all fixes
		this.AbsoluteDimensions();
		this.FixImage();
//		this.FixBackground();
		
	},
	
	//Some elements that need the ie png fix applying to them will not work unless absolutely positioned
	AbsoluteDimensions: function()
	{
		
		//get all the elements that need fixing absolutely
		var elem_str = this.options.AD_CssSelector.join(", ");
		
		//console.log(elem_str);
		$$(elem_str).each(function(item, index){
			//console.log(item);
			var size = item.getSize();
			
			//console.log(item.get('text')+" : "+size.x);
			
			if(this.options.AD_Dimension == "width")
			{
				item.setStyles({
					'width': size.x,
					'padding-left': 0,
					'padding-right':0, 
					'text-align':'center'
				});
			}
			else if(this.options.AD_Dimension == "height")
				item.setStyle('height', size.y);
			else if(this.options.AD_Dimension == "both")
			{
				item.setStyle('height', size.y);
				item.setStyle('width', size.x);
			}
		}.bind(this));
		
		
		
	},
	
	//makes the corporate id 
	FixImage: function()
	{
		//get all the elements that need fixing absolutely
		
		var elem_str = this.options.FI_CssSelector.join(", ");
		
		$$(elem_str).each(function(item, index){
								   
			//alert(item.get('src'));
								   
			//get the item size
			var size = item.getSize();
			
			//get the image details and set absolutes && switch img with transparent gif
			var img_details={ 'src':item.getProperty('src'), 'width':size.x, 'height':size.y };
			
			var mode ="crop";
			
			item.set('src', this.options.FI_XPath);
			
			//alert("height:"+img_details.height+"\nwidth:"+img_details.width+"\nnewsrc:"+img_details.src);
			
			item.setStyles({
				'width':img_details.width,
				'height':img_details.height,
				//'border':'1px solid #ff9900',
				'filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img_details.src + "', sizingMethod='" + mode + "')"			   
			});
		}.bind(this));
	},
	
	
	FixBackground: function()
	{
		//get all the elements that need fixing absolutely
		
		var elem_str = this.options.BG_CssSelector.join(", ");
		
		$$(elem_str).each(function(item, index){
								   
			
			//get the style - background repeat
			var style = item.getStyles('backgroundRepeat', 'backgroundImage');
			
			//clean up img src
			style.backgroundImage = style.backgroundImage.replace(/^\s*url\("?/, '').replace(/"?\)$/, '');
			
			//get the sizing method
			if(style.backgroundRepeat != 'no-repeat')
				var mode = 'scale';
			else
				var mode = 'crop';
			
			
			//set new styles
			item.setStyles({
				'backgroundImage':'none',
				'filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + style.backgroundImage + "', sizingMethod='" + mode + "')"
			});
		}.bind(this));
	}
	
	
	
});



window.addEvent('load', function(event){
	
	//initialise alert class
	if( Browser.Engine.trident4 )
	{
		var ie6fix = new FixIE6();
	}
});



