
window.addEvent('domready', function(){
	// PNG transparency fix for IE 6
	if ((Browser.Engine.trident) && (document.body.filters)) 
	{
		$$('img').each(function(img){
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
			}
		});
	}
	
	$$('h1.pagetitle, h2').each(function(el){
		el.addClass('replace');
	});
	
	if(typeof sIFR == "function"){
		sIFR.replaceElement("h1.pagetitle", named({sFlashSrc: bsc.site.scripts+"scripts/javascript/sifr/1/chalet.swf", sColor: "#4d555c", sWmode: "transparent"}));
		sIFR.replaceElement("h2", named({sFlashSrc: bsc.site.scripts+"scripts/javascript/sifr/1/chalet.swf", sColor: "#4d555c", sWmode: "transparent"}));
	};
	
	// Home slideshow
	if ($('slideshow'))
	{
		var slideshow = new Slideshow($$('#slideshow ul'));
	}
});

window.addEvent('load', function(){
	// PNG transparency fix for IE 6
	if ((Browser.Engine.trident) && (document.body.filters)) 
	{
		$$('img').each(function(img){
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
			}
		});
	}
});



/*
	Slideshow v0.1
	Requires MooTools 1.2
	
	Author: Andrew Ferri <andrew@blacksheepcreative.co.nz>
	Date: 24 November 2009
*/

var Slideshow = new Class({
	Implements: [Options, Events],
	
	options: {
		transition: Fx.Transitions.Sine.easeOut,
		pauseLength: 7000,
		imageTransitionSpeed: 900,
		textTransitionSpeed: 400
	},
	
	initialize: function(containers,options)
	{
		this.setOptions(options);
		containers.each(function(ul){
			this.createSlideshow(ul);
		}.bind(this));
	},
	
	createSlideshow: function(ul)
	{
		ul.getElements('li').each(function(el){ this.prepLi(el); }.bind(this));
		ul.store('currentLi',ul.getElement('li:first-child'));
		this.setActive(ul.retrieve('currentLi'));
		var func = function(){
			this.runSlideshow(ul);
		};
		func.periodical(this.options.pauseLength,this);
	},
	
	runSlideshow: function(ul)
	{
		if (ul.retrieve('currentLi').getNext())
		{
			var nextLi = ul.retrieve('currentLi').getNext();
		} else
		{
			var nextLi = ul.getElement('li:first-child');
		}
		
		ul.retrieve('currentLi').hide();
		nextLi.show();
		ul.store('currentLi',nextLi);
	},
	prepLi: function(li)
	{
		li.addClass('active');
		li.setStyles({
		'opacity':	0,
		'z-index':	10
		});
		var fx = new Fx.Morph(li, {duration: this.options.imageTransitionSpeed, transition: this.options.transition});
		var textFx = new Fx.Morph(li.getElement('p'), {duration: this.options.imageTransitionSpeed, transition: this.options.transition});
		li.hide = function(){
			fx.start({'opacity':0});
		};
		li.show = function(){
			fx.start({'opacity':1});
		};
	},
	
	setActive: function(li)
	{
		li.setStyles({
		'opacity':	1,
		'z-index':	5
		});
	}
});
