var slide_func = function(time){
	var myFx = new Fx.Slide('slider_outer', {
		duration: time
	});
	myFx.slideOut();
	$('product_big').getChildren().morph({
		'height': '85px',
		'width': '85px'
	});
	$("visibility").set('class', 'open');
}

window.addEvents({'domready': function(){
		if($$('.tx-photogals-pi1-big img')[0]){
			var singleImage = $$('.tx-photogals-pi1-big img')[0];
			singleImage.set('styles', {
				'opacity': 0,
				'visibility': 'visible'
			});
			singleImage.fade('in');
		}

// -- SLIDER -- //
	    var elements = $$('.slider_element');
	
		if(elements[0]){
			slider_el = new Element('div', {'class': 'slider_element'});
			$('slider_inner').grab(slider_el, 'top');  
			
			var size = elements[0].getSize();
			var total_elements = elements.length;

			var slider_outer = $('slider_outer').getSize();
			
			var element_size = elements[0].getSize().x;
			var move_knob = 915 / total_elements;

			var total_size = (size.x  * (total_elements-1) -600);		

			var slider = $('slider');
			var total_el = total_elements - 4;
			var mySlider = new Slider(slider, slider.getElement('.knob'), {
				range: [1, -total_size],
					wheel: true,
					steps: total_el,
				onChange: function(pos){
				  if (pos) $('slider_inner').tween('margin-left', pos);
				}
				
			});	

			var per = (total_size) / (total_elements-4);
			var pernew = -1;
		
			var direction = true;

			var periodicalID;
			var begin = function() {
				periodicalID = (function(){
				if (this.step >= -total_size && direction){
					pernew = this.step - per;
					if(this.step == -total_size){direction = false}
				}
				if (direction == false){
					pernew = this.step + per;
					if(this.step == 1){direction = true}
				}
				this.set(pernew);
				}).periodical(5000, mySlider);
			}
			
			if(total_elements > 4) {

				$("slider_outer").addEvents({
				  mouseenter: function() {
					clearInterval(periodicalID);
				  },
				  mouseleave: begin
				});
	
				$("slider_left").addEvent("click", function() {
					pernew = mySlider.step+per;
					mySlider.set(pernew);
					direction = false;
				});
				
				$("slider_right").addEvent("click", function() {
					pernew = mySlider.step-per;
					 mySlider.set(pernew);
					direction = true;
				});
			}
			
     			var visibility = $("visibility");
			var product_big = $('product_big').getChildren();
			
			visibility.set('text',$$('.crumbs_inner a')[2].get('text'));
			
			var mySlide = new Fx.Slide('slider_outer');

			if(Cookie.read('slider') == 'opened' ){
				mySlide.show();
				visibility.set('class', 'close');
				if(total_elements > 4) begin();
			}else if(Cookie.read('slider') == 'closed' ){
				mySlide.hide();
				visibility.set('class', 'open');
				clearInterval(periodicalID);
				product_big.setStyle('height',85);
				product_big.setStyle('width',85);
			}
			else{
				visibility.set('class', 'close');
				if(total_elements > 4) begin();
				/*if(total_elements > 4) window.setTimeout("slide_func(2000)", 2000);*/
			}

			visibility.addEvent("click", function(e) {
					e = new Event(e);	
					mySlide.toggle();
					if($('slider_outer').getParent().getStyle('height').toInt() != 0 ){
						Cookie.write('slider', 'closed', {duration: 30});
						clearInterval(periodicalID)
						this.set('class', 'open');
						product_big.morph({
							  'height': '85px',
							  'width': '85px'
							});
					}else{
						Cookie.write('slider', 'opened', {duration: 30});
						if(total_elements > 4) begin();
						this.set('class', 'close');
						product_big.morph({
							  'height': '145px',
							  'width': '145px'
						});
					}
					e.stop();
			});
			if(total_elements <= 4) {
				$("slide_wrap").setStyle('display', 'none');	
			} 
			


				
		}  // IF
	
// -- DROP DOWN SELECT -- //

	        if($('rsel')){
			var dropdown = new Form.Dropdown($('rsel'));
			dropdown.element.adopt(dropdown.element.getElement('.menu'));
		
			$$('.select li').addEvent("click", function() {
				parent.location = $('rsel').value;	
			});
		}
	
// -- ART SLIDER -- //					
	
		if($('SlideItMoo_outer')){
			new SlideItMoo({
				overallContainer: 'SlideItMoo_outer',
				elementScrolled: 'SlideItMoo_inner',
				thumbsContainer: 'SlideItMoo_items',		
				itemsVisible:3,
				elemsSlide:2,
				duration:300,
				itemsSelector: '.tx-photogals-pi1-small',
				itemWidth: 155,
				showControls:1,
				startIndex:5,
				onChange: function(index){		
				}
		
			});
			
			if($$(".tx-photogals-pi1-small").length == 2){
			
				var txElement  = new Element('div', {'class': 'tx-photogals-pi1-small', style: 'border-right: 1px solid black'});
				txElement.inject($('SlideItMoo_items'));
				var txElement  = new Element('div', {'class': 'tx-photogals-pi1-small', style: 'border-right: 1px solid black'});
				txElement.inject($('SlideItMoo_items'));
				var txElement  = new Element('div', {'class': 'tx-photogals-pi1-small', style: 'border-right: 1px solid black'});
				txElement.inject($('SlideItMoo_items'));
			};	
			if($$(".tx-photogals-pi1-small").length == 1){
			
				var txElement  = new Element('div', {'class': 'tx-photogals-pi1-small'});
				txElement.inject($('SlideItMoo_items'));
				var txElement  = new Element('div', {'class': 'tx-photogals-pi1-small', style: 'border-right: 1px solid black'});
				txElement.inject($('SlideItMoo_items'));
			};
			
			
		} // IF SlideItMoo_outer
	
// -- CONT_RIGHT_MENU -- //	


		var cont_select = $$('#content_right div.content_inner')[0];
		var target_class = '';
		var right_box = $$('#content_right div.box');
	
		if(right_box[0]){
		
			menuUL  = $$('#content_right ul.csc-menu')[0];
			var menuLI = '';
			$$('.box .csc-header h1').setStyle('display', 'none');
			$$('#content_right ul.csc-menu')[0].empty();
			right_box.setStyle('display', 'none');
			right_box[0].setStyle('display', 'block');

			cont_select.getElements('.box h1').each(function(foo, index){											 
				if(index == 0) 
					menuLI = new Element('li', {'class': 'current', html:'<a href="#a">'+foo.get('text')+'</a>'});
				else
					menuLI = new Element('li', {html:'<a href="#a">'+foo.get('text')+'</a>'});
				menuLI.inject(menuUL);

				menuLI.addEvent("click", function(e) {
					e.stop();
					right_box.fade('hide').setStyle('display', 'none');
					
					menuUL.getChildren('li').removeClass('current');
					$(this).addClass('current');
					
					target_class = foo.getParent('.box').get('class').replace(/box /g, "");

					$$('#content_right .'+target_class).each(function(e, index){
							e.setStyle('display','block').fade('in');
					});

				});

			});
			
			
			
// -- PRESS SLIDER -- //	

			press = new Element('div', {id: 'press_outer'});
			press.inject($('content_left'));
			press = new Element('div', {id: 'press_inner'});
			press.inject($('press_outer'));
			press = new Element('div', {id: 'press_items'});
			press.inject($('press_inner'));

			cont_select.getElements('.press').each(function(foo, index){
				if(index > 1) {

					press = new Element('div', {'class': 'press_element', html:foo.innerHTML});
					press.inject($('press_items'));
				}
				
			});
			
			
			$$('#press_inner .csc-textpic-image').setStyles({'width':133,'margin':0});
				
			//alert( $$('#content_right .content_inner')[0].getStyle('height') )
			//alert( $('press_outer').getStyle('height') )
			
			
			new SlideItMoo({
				overallContainer: 'press_outer',
				elementScrolled: 'press_inner',
				thumbsContainer: 'press_items',		
				itemsVisible:1,
				elemsSlide:1,
				duration:1500,
				itemsSelector: '.press_element',
				itemWidth: 499,
				showControls:0,
				startIndex:5,
				autoSlide: 7000,
				onChange: function(index){

				}
			
			});
	
		}
// -- HOME SLIDESHOW -- //
		var cont = document.id('content_border');
		if(cont){

			var images = cont.getElements('img');				
			var image_size = images[0].getSize();

			if(image_size.x == 1000 && image_size.y == 265){
			
			
			
				var title  = new Element('div', {'class': 'title'});
				var counter  = new Element('div', {'class': 'counter'});
			
				var current  = new Element('span', {'class': 'current'});
				var spacer  = new Element('span', {'html': '.'});
				var total  = new Element('span', {'class': 'total'});
			
			
				title.inject(cont, 'bottom');
				counter.inject(cont, 'bottom');
			
				current.inject(counter);
				spacer.inject(counter);
				total.inject(counter, 'bottom');
				
				
			if (Browser.ie6 || Browser.ie7 || Browser.ie8){

				var showDuration = 7000;
				var currentIndex = 0;
				var interval;

				title.set('text', images[0].get('alt'));
				current.set('text', '1');
				total.set('text', images.length);
				
				images.setStyles({
					position: 'absolute',
					left: 0,
					top: 0
				});
				
				images.each(function(img,i){ 
					if(i > 0) {
						img.set('opacity',0);
					}
				});

				var show = function() {
					//images[currentIndex].fade('out');
					
					images[currentIndex].set('tween', {duration: 1000});
					images[currentIndex].tween('opacity',0);
					
					//images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
					
					images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].set('tween', {duration: 1000});
					images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].tween('opacity',1);
					
					title.set('text', images[currentIndex].get('alt'));
					current.set('text', currentIndex+1);
				};


				interval = show.periodical(showDuration);

			
			
			
			}else{
									 
				var grid = new ImageDrawer.Grid({
					gridHeight: 53,
					gridWidth: 100,
					interval: 70,
					duration: 600,
					transition: 'expo:in'
				});
				new Gradually.Slideshow(cont, {
					drawer: grid,
					images: images,
					zIndex: 3000,
					interval: 4000
				});
			}
				
			}
		}
	  
		  
	}
	
});
window.addEvent('load',function(){
				
			$$("div.slider_element img").each(function(e, index){
				Reflection.add(e, { 'height': 3/15, 'opacity': 5/15 });
			});
});




// GOOGLE ANALYTICS //

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-28592729-1']);
_gaq.push(['_trackPageview']);


(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

