window.addEvent('domready', function() {
	$(document.body).getElements('a[rel=external]').set('target', '_blank');	// EXTERNAL LINKS	
	try {document.execCommand("BackgroundImageCache", false, true);	} catch(err) {}// BACKGROUND IMAGE CACHE
 	new SmoothScroll({ duration:700 }, window);// SMOOTH SCROLL PAGE
	var tooltip = new Tips($$('.tooltip'));// TOOL TIPS	

	Array.implement({
		shuffle: function() {
			//destination array
			for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
			return this;
		}
	});
	
	if($chk($('slideshow_holder'))){
		/* preloading */
		var imagesDir = 'images/slideshow/';
		var images = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg'];
		//images = images.shuffle();
		var holder = $('slideshow_holder');
		images.each(function(img,i){ images[i] = imagesDir + '' + img; }); //add dir to images
		var progressTemplate = 'Loading image {x} of ' + images.length;
		var updateProgress = function(num) {
			progress.set('text',progressTemplate.replace('{x}',num));
		};
		var progress = $('progress');
		updateProgress('0');
		var loader = new Asset.images(images, {
			onProgress: function(c,index) {
				updateProgress(index + 1);
			},
			onComplete: function() {
				var slides = [];
				/* put images into page */
				images.each(function(im) {
					slides.push(new Element('img',{
						src:im,
						width: 960,
						height: 306,
						styles: {
							opacity:0,
							top:0,
							left:0,
							position:'absolute',
							'z-index': 10
						}
					}).inject(holder));
					//holder.setStyle('background','url(images/general/holder.jpg) left top no-repeat');
				});
				var showInterval = 6000;
				var index = 0;
				progress.set('text','');
				(function() {slides[index].tween('opacity',1); }).delay(0);
				
				var start = function() {
					(function() {
						progress.set('text','');
						//holder.setStyle('background','');
						slides[index].fade(0);
						++index;
						index = (slides[index] ? index : 0);
						slides[index].fade(1);
						$$('#slideshow div.shadow').setStyles({'background-image': 'none', 'background-color': '#C7C3AA'});
					}).periodical(showInterval);
				};
	
				/* start the show */
				start();
			}
		});
	}
	
	/* ADD CLASSES TO DL RECORDSET BLOCKS SO THEY WORK WITH ACCORDION */
	$$('.accordion').getChildren().each(function(elem){
		elem.each(function(el){
			if(el.get('tag')=='dt') el.addClass('acc_title');
			if(el.get('tag')=='dd') el.addClass('acc_body');
		});
	});
	
	/* GENERIC ACCORDION  */
	var accordion = new Accordion($$('.acc_title'),$$('.acc_body'), {
		opacity: 0,
		alwaysHide: true,
		start:'all-closed',
		//transition: 'bounce:out',
		duration: 'long',
		onActive: function(toggler) { toggler.setStyle('color', '#6B0F2C'); },
		onBackground: function(toggler) { toggler.setStyle('color', '#240505'); }
	});
	
});

function openShop(){
	//window.open('shutters/index.php','shop','width=800,height=600,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no') 
	window.open('/shutters/index.php','shop','width=800,height=720,resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0') 
}
