/*
    * Browser.Engine.trident - (boolean) True if the current browser uses the trident engine (e.g. Internet Explorer).
    * Browser.Engine.gecko - (boolean) True if the current browser uses the gecko engine (e.g. Firefox, or any Mozilla Browser).
    * Browser.Engine.webkit - (boolean) True if the current browser uses the webkit engine (e.g. Safari, Google Chrome, Konqueror).
    * Browser.Engine.presto - (boolean) True if the current browser uses the presto engine (e.g. Opera 9).
    * Browser.Engine.name - (string) The name of the engine.
    * Browser.Engine.version - (number) The version of the engine. (e.g. 950)
    * Browser.Plugins.Flash.version - (number) The major version of the flash plugin installed.
    * Browser.Plugins.Flash.build - (number) The build version of the flash plugin installed.
*/


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function divSlider(id)
{
	$(id).slide('toggle');
}

//CONTACT PAGE
function contactPageSliders()
{
	if($('accordionList') !== null)
	{
		$$('.accordion').slide('hide');
		$('addresses0Content').slide('show');
		$$('.tab').addEvent('click', function(){
			$$('.accordion').slide('out');
			$(this.get('ext')).slide('in');
		});
	}
}

//HOMEPAGE
function homepageSlideShow()
{
	//homepageslider dependencies: slideshow.js / loop.js
	if($('navigation-slideshow') !== null)
	{
		var navSlideShow;
		document.addEvent('domready', function(){
		
			// cache the navigation elements
			var navs = $('navigation-slideshow').getElements('a');
		
			// create a basic slideshow
			navSlideShow = new SlideShow('navigation-slideshow', {
				autoplay: true,
				delay: 3000,
				selector: 'span', // only create slides out of the images
				transition: 'fade',
				onShow: function(data){
					// update navigation elements' class depending upon the current slide
					navs[data.previous.index].removeClass('current');
					navs[data.next.index].addClass('current');
				}
			});
		
			navs.each(function(item, index){
				// click a nav item ...
				item.addEvent('click', function(event){
					event.stop();
					// pushLeft or pushRight, depending upon where
					// the slideshow already is, and where it's going
					var transition = 'fade';
					// call show method, index of the navigation element matches the slide index
					// on-the-fly transition option
					navSlideShow.show(index, {transition: transition});
				});
			});
			
			$('navigation-slideshow').addEvent('mouseover', function(){
				navSlideShow.pause();
			});
			
			$('navigation-slideshow').addEvent('mouseout', function(){
				navSlideShow.play();
			});
		});
		
		$('whatsNew').fade('hide');
		$('download').fade('hide');
		//mHome
		//wNew
		
		$('dLoad').addEvent('click', function(){
			$('mainHome').fade('out');
			$('whatsNew').fade('out');
			$('download').fade('in');
			return false;
		});
		
		$('mHome').addEvent('click', function(){
			$('mainHome').fade('in');
			$('whatsNew').fade('out');
			$('download').fade('out');
			return false;
		});
		$('wNew').addEvent('click', function(){
			$('mainHome').fade('out');
			$('download').fade('out');
			$('whatsNew').fade('in');
			return false;
		});
	}	
}

//SHOWCASE PAGE
function showcase()
{
	if($('showcaseEx') !== null)
	{
		$$('.showcaseTip').fade('hide');
		$$('.showcaseLnk').fade('show');
		$$('.showcaseLnk').addEvent('click', function(){
			$$('.showcaseLnk').fade('out');
			this.fade('show');
			$$('.'+this.get('alt')).fade('in');
			$('showcaseImgProper').set('style', 'cursor: pointer;');
			return false;
		});
		
		$$('.showcaseClose').addEvent('click', function(){
			$$('.showcaseTip').fade('out');
			$$('.showcaseLnk').fade('in');	
			$('showcaseImgProper').set('style', 'cursor: default;');
			return false;
		});
		
		
	}
}
// PRODUCT PAGE AJAX
function ajaxThumb()
{
	$$('.paging').addEvent('click', function(){
		var req = new Request.HTML({
			method: 'get',
			url: this.get('ajax'),
			data: { 'do' : '1' },
			onRequest: function() {
			$('thumbAjax').fade('hide');
			},
			update: $('thumbAjax'),
			onComplete: function(response) {
			$('thumbAjax').fade('in');
			$$('.previewing').addEvent('click', function(){
				var req2 = new Request.HTML({
					method: 'get',
					url: this.get('ajax'),
					data: { 'do' : '1' },
					onRequest: function() {
					$('bigAjax').fade('hide');
					},
					update: $('bigAjax'),
					onComplete: function(response) {
					$('bigAjax').fade('in');
					}
				}).send();
			});
			}
		}).send();
		
	
		return false;
	});
	
	$$('.previewing').addEvent('click', function(){
		var req2 = new Request.HTML({
			method: 'get',
			url: this.get('ajax'),
			data: { 'do' : '1' },
			onRequest: function() {
			$('bigAjax').fade('hide');
			},
			update: $('bigAjax'),
			onComplete: function(response) {
			$('bigAjax').fade('in');
			}
		}).send();
	});
}
// CATALOGUE PAGE
function cataloguePage()
{
	if($('cataloguePage') !== null)
	{
		$$('.subCatList').fade('hide');
		$$('.start').fade('show');
		$$('.catLinks').addEvent('click', function(){
			$$('.subCatList').fade('out');
			var idname = this.get('title');
			$(idname.toLowerCase()).fade('in');
			return false;
		});
	}
}

window.addEvent('domready',function(){
	cataloguePage();
	ajaxThumb();
	contactPageSliders();
	showcase();
	homepageSlideShow();
	//procedurals:
	
	new Fx.SmoothScroll({
		  duration: 500
		},window);
	
	$$('.goTo').addEvent('click', function(){
		window.location = this.get('ext');
	});
		
	/*
//store titles and text
	$$('a.tipz').each(function(element,index) {
	  var content = element.get('title').split('::');
	  element.store('tip:title', content[0]);
	  element.store('tip:text', content[1]);
	});
	  
	  //create the tooltips
	  var tipz = new Tips('.tipz',{
	    className: 'tipz',
	    fixed: true,
	    hideDelay: 50,
	    showDelay: 50
	  });
*/

});
