window.addEvent('domready',initialize);
window.addEvent('resize',resizeBg);

/*	Initialization */
	
	var couplesCarousel,stylesCarousel,shopCarousel;
	function initialize(){
	
		/*	Adjust background */
		
			$('backgroundBlur').setStyle('opacity',0);
			resizeBg();
			new Fx.Tween('backgroundBlur',{'duration':2000}).start('opacity',1);
		
		/*	Main menu */
		
			var mainMenu=new Swiff('/wp-content/themes/wc/flash/wc_nav.swf',{
		
				'container':$('mm'),
				'width':795,
				'height':100		
		
			});
		
		/*	Photo */
		
			if($('photo')) var photo=new Swiff('/wp-content/themes/wc/flash/'+$('photo').get('text')+'.swf',{
		
				'container':$('photo'),
				'width':290,
				'height':450		
		
			});
			
		/*	Enable scroller */
		
			if($('contentsTall')||$('contentsShort')){
		
				var C=$('contents');
				var D=C.getCoordinates();
				var E=$('contentsTall')?$('contentsTall').getCoordinates():$('contentsShort').getCoordinates();
				slider=new Slider('scrollTrack','scrollTab',{
					
					'mode':'vertical',
					'onChange':function(step){
						
						var ratio=step/100;
						C=$('contents');
						D=C.getCoordinates();
						E=$('contentsTall')?$('contentsTall').getCoordinates():$('contentsShort').getCoordinates();
						C.setStyle('margin-top',-Math.ceil(ratio*(D.height-E.height)));
					
					}
				
				});
				
				if(D.height-20<E.height) $('scrollTrack').destroy();
				
			}
			
		/*	Initialize gallery carousels */
		
			if($('couplesCarousel')) couplesCarousel=new Carousel({'target':$('couplesCarousel'),'viewWidth':642,'itemsPerView':6,'nextBtn':$('couplesNextBtn'),'previousBtn':$('couplesPreviousBtn'),'itemClass':'div.item'});
			if($('stylesCarousel')) stylesCarousel=new Carousel({'target':$('stylesCarousel'),'viewWidth':642,'itemsPerView':6,'nextBtn':$('stylesNextBtn'),'previousBtn':$('stylesPreviousBtn'),'itemClass':'div.item'});
			if($('shopCarousel')) shopCarousel=new Carousel({'target':$('shopCarousel'),'viewWidth':770,'itemsPerView':7,'nextBtn':$('shopNextBtn'),'previousBtn':$('shopPreviousBtn'),'itemClass':'div.item'});
		
		/*	Shop thumbs */
		
			initializeShopThumbs();
		
	}
	
/*	Background resizing */

	function resizeBg(){
		
		var D=window.getCoordinates();
		var ratio=D.width/1650;
		var newWidth=Math.ceil(ratio*1650);
		var newHeight=Math.ceil(ratio*1238);
		
		$('background').setStyles({'width':newWidth,'height':newHeight});
		
		$('backgroundNormal').width=newWidth;
		$('backgroundNormal').height=newHeight;
		
		$('backgroundBlur').width=newWidth;
		$('backgroundBlur').height=newHeight;
		
	}
	
/*	Shop popup */

	function initializeShopThumbs(){
	
		$$('a[rel=shop]').each(function(M,N){
		
			M.addEvent('click',function(e){
			
				var e=new Event(e);
				e.stop();
				showShopPopup(M);
			
			});
		
		});
	
		$$('a.email]').each(function(M,N){
		
			M.addEvent('click',function(e){
			
				var e=new Event(e);
				e.stop();
				showShopPopup(M.getPrevious().getPrevious().getPrevious().getPrevious());
			
			});
		
		});
	
	}

	var lightbox;
	function showShopPopup(A){
	
		lock();
		var w=window.getCoordinates();
		lightbox=new Element('form',{'method':'post','action':'/wp-content/themes/wc/send-enquiry.php','styles':{'position':'absolute','top':100,'left':w.width/2-150,'width':300,'height':410,'padding':5,'z-index':90000,'background-color':'#fff'}}).injectInside(document.body);
		new Element('div',{'text':'Enquire about this item','styles':{'font-size':16,'padding-bottom':5,'border-bottom':'1px solid #ccc'}}).injectInside(lightbox);
		new Element('div',{'html':A.get('html'),'styles':{'padding-top':5,'float':'left','width':110}}).injectInside(lightbox);
		new Element('div',{'html':'<strong>'+A.getNext().get('html')+' - '+A.getNext().getNext().get('html')+'</strong><br />'+A.getProperty('title'),'styles':{'float':'left','width':160,'padding-top':5,'font-size':10}}).injectInside(lightbox);
		new Element('div',{'text':'Your Name','styles':{'font-size':12,'clear':'both','padding-top':10}}).injectInside(lightbox);
		new Element('input',{'name':'name','styles':{'width':290,'margin-top':5}}).injectInside(lightbox);
		new Element('div',{'text':'Your Email','styles':{'font-size':12,'margin-top':5}}).injectInside(lightbox);
		new Element('input',{'name':'email','styles':{'width':290,'margin-top':5}}).injectInside(lightbox);
		new Element('div',{'text':'Your Enquiry','styles':{'font-size':12,'margin-top':5}}).injectInside(lightbox);
		new Element('textarea',{'name':'enquiry','styles':{'width':290,'height':100,'margin-top':5}}).injectInside(lightbox);
		new Element('a',{'class':'submit','events':{'click':function(){lightbox.submit();}}}).injectInside(lightbox);
		new Element('a',{'text':'close','styles':{'float':'right','padding-right':5,'padding-top':3},'events':{'click':hideShopPopup}}).injectInside(lightbox);
		new Element('input',{'type':'hidden','name':'product','value':A.getProperty('title')}).injectInside(lightbox);
		new Element('div',{'class':'clear'}).injectInside(lightbox);
	
	}
	
	function hideShopPopup(){
	
		unlock();
		lightbox.destroy();
	
	}
