// JavaScript Document
// IMAGE ENLARGE
window.addEvent('domready', function(){
	//call multiBox
	var initMultiBox = new multiBox({
		mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
		container: $(document.body),//where to inject multiBox
		descClassName: 'multiBoxDesc',//the class name of the description divs
		path: '../Files/',//path to mp3 and flv players
		useOverlay: true,//use a semi-transparent background. default: false;
		maxSize: {w:1200, h:1200},//max dimensions (width,height) - set to null to disable resizing
		addDownload: false,//do you want the files to be downloadable?
		pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
		addRollover: true,//add rollover fade to each multibox link
		addOverlayIcon: true,//adds overlay icons to images within multibox links
		addChain: true,//cycle through all images fading them out then in
		recalcTop: true,//subtract the height of controls panel from top position
		addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
	});
});





// Nav
window.addEvent('domready', function() {
	$$('.flood').each(function(item, index){	
		var div = item.getParent();
		var li = div.getParent();
		if(div && li){
			div.setStyle('display', 'block');
			var sub = new Fx.Slide(item, { duration: 200, link: 'cancel', transition: 'quad:out' }).hide();
			var subFx = new Fx.Tween(item, { duration: 200, link: 'cancel' });
			li.addEvents({
		    'mouseenter': function(){
		    	this.addClass('hover');
		    	subFx.cancel();
		    	sub.cancel();
		    	subFx.set('opacity', 1);
		    	sub.slideIn();
		    },
		    'mouseleave': function(){
		    	this.removeClass('hover');
		    	subFx.cancel();
		    	sub.cancel();
		     	subFx.start('opacity', 0);
		     	sub.slideOut();
		    }
			});
		}
	})
});

// Large Image Fade
var global_transitions=[ //IE transition strings
	"progid:DXImageTransform.Microsoft.Fade()"
]

function flashyslideshow(setting){
	this.wrapperid=setting.wrapperid
	this.imagearray=setting.imagearray
	this.pause=setting.pause
	this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into el.filters.play()
	this.currentimg=-1
	var preloadimages=[] //temp array to preload images
	for (var i=0; i<this.imagearray.length; i++){
		preloadimages[i]=new Image()
		preloadimages[i].src=this.imagearray[i][0]
	}
	if (this.currentimg = -1)
	{
			this.currentimg=Math.floor(Math.random()*this.imagearray.length)
	}
	document.write('<div id="'+this.wrapperid+'" class="'+setting.wrapperclass+'">'+this.getSlideHTML(this.currentimg)+'</div>')
	var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
	var wrapperdiv=document.getElementById(this.wrapperid)
	if (wrapperdiv.filters){ //if the filters[] collection is defined on element (only in IE)
		wrapperdiv.style.filter=global_transitions[effectindex] //define transition on element
		this.pause+=setting.transduration //add transition time to pause
	}
	this.filtersupport=(wrapperdiv.filters && wrapperdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
	var slideshow=this
	setInterval(function(){slideshow.rotate()}, this.pause)
}

flashyslideshow.prototype.getSlideHTML=function(index){
	document.getElementById('homebuilderinfo').style.background = this.imagearray[index][2]
	var slideHTML=(this.imagearray[index][1])? '<a href="'+this.imagearray[index][1]+'" class="homerightcol" target="_self" border="0px">\n' : '' //hyperlink slide?
	slideHTML += '<img src="' + this.imagearray[index][0] + '" class="homerightcolimg" title="' + this.imagearray[index][3] + '" border="0px" />'
	slideHTML+=(this.imagearray[index][1])? '</a>' : ''
	return slideHTML //return HTML for the slide at the specified index
}

flashyslideshow.prototype.rotate=function(){
	var wrapperdiv=document.getElementById(this.wrapperid)
	this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
	if (this.filtersupport)
		wrapperdiv.filters[0].apply()
	wrapperdiv.innerHTML=this.getSlideHTML(this.currentimg)
	if (this.filtersupport)
		wrapperdiv.filters[0].play(this.transduration)	
}


// !Product scroll Head
window.addEvent('domready', function() {
	var contentDiv = $('content');
	var productDiv = $('productsHead');
	var prev = $('leftHead');
	var next = $('rightHead');
	var currentPage = 0;
	var visible = 75;
	var pageUrl = new URI(document.location.toString());
	var pageView = pageUrl.get('data').view;
	var pageCookie = Cookie.read('productspage');
	var urlCookie = Cookie.read('url');
	
	if(productDiv){
		var products = productDiv.getChildren('.productHead');
		
		if(products.length > 1){
			var pages = Math.ceil(products.length / 1);

			var productFx = new Fx.Tween(productDiv, { duration: 500, link: 'cancel', transition: 'Quad:out' });
			
			productDiv.setStyles({
		    width: visible * pages,
		    position: 'absolute',
		    top: 0,
		    left: 0
			});

			//var prev = new Element('a', {
			//	'id': 'left',
			//	'href': '#',
		    //'html': 'Prev'
			//}).inject(contentDiv);
			var prevPage = function(e){ 
				e.preventDefault();
        currentPage--;
        gotoPage(true);
      }
			
			//var next = new Element('a', {
			//	'id': 'right',
		    //'href': '#',
		    //'html': 'Next'
			//}).inject(contentDiv);
			var nextPage = function(e){ 
				e.preventDefault();
        currentPage++;
        gotoPage(true);
      }
      			
			if(pageView && pageView > 0){
				currentPage = pageView;
				gotoPage(true);
			}else if(pageCookie && urlCookie){
			if (urlCookie == pageUrl.get('filename')) {
					currentPage = pageCookie;
					gotoPage(true);
				}else{
					gotoPage(false);
				}
			}else{
				gotoPage(false);
			}
		}	
	}
	
	function gotoPage(track){
		if(currentPage <= 0){
			prev.addClass('inactive');
			prev.removeEvent('click', prevPage);
		}else{
			prev.removeClass('inactive');
			prev.addEvent('click', prevPage);
		}
		if(currentPage >= pages-1){
			next.addClass('inactive');
			next.removeEvent('click', nextPage);
		}else{
			next.removeClass('inactive');
			next.addEvent('click', nextPage);
		}
		productFx.cancel();
		productFx.start('left', -visible * currentPage);
		Cookie.write('productspage', currentPage, { path: "/" });
		Cookie.write('url', pageUrl.get('filename'), { path: "/" });
	}
	
});



// !Product scroll Top
window.addEvent('domready', function() {
	var contentDiv = $('content');
	var productDiv = $('productsTop');
	var prev = $('left');
	var next = $('right');
	var currentPage = 0;
	var visible = 200;
	var pageUrl = new URI(document.location.toString());
	var pageView = pageUrl.get('data').view;
	var pageCookie = Cookie.read('productspage');
	var urlCookie = Cookie.read('url');
	
	if(productDiv){
		var products = productDiv.getChildren('.productTop');
		
		if(products.length > 1){
			var pages = Math.ceil(products.length / 1);

			var productFx = new Fx.Tween(productDiv, { duration: 500, link: 'cancel', transition: 'Quad:out' });
			
			productDiv.setStyles({
		    width: visible * pages,
		    position: 'absolute',
		    top: 0,
		    left: 0
			});

			//var prev = new Element('a', {
			//	'id': 'left',
			//	'href': '#',
		    //'html': 'Prev'
			//}).inject(contentDiv);
			var prevPage = function(e){ 
				e.preventDefault();
        currentPage--;
        gotoPage(true);
      }
			
			//var next = new Element('a', {
			//	'id': 'right',
		    //'href': '#',
		    //'html': 'Next'
			//}).inject(contentDiv);
			var nextPage = function(e){ 
				e.preventDefault();
        currentPage++;
        gotoPage(true);
      }
      			
			if(pageView && pageView > 0){
				currentPage = pageView;
				gotoPage(true);
			}else if(pageCookie && urlCookie){
				if(urlCookie == pageUrl.get('filename')){
					currentPage = pageCookie;
					gotoPage(true);
				}else{
					gotoPage(false);
				}
			}else{
				gotoPage(false);
			}
		}	
	}
	
	function gotoPage(track){
		if(currentPage <= 0){
			prev.addClass('inactive');
			prev.removeEvent('click', prevPage);
		}else{
			prev.removeClass('inactive');
			prev.addEvent('click', prevPage);
		}
		if(currentPage >= pages-1){
			next.addClass('inactive');
			next.removeEvent('click', nextPage);
		}else{
			next.removeClass('inactive');
			next.addEvent('click', nextPage);
		}
		productFx.cancel();
		productFx.start('left', -visible * currentPage);
		Cookie.write('productspage', currentPage, { path: "/" });
		Cookie.write('url', pageUrl.get('filename'), { path: "/" });
	}
	
});

// !Product scroll Belt
window.addEvent('domready', function() {
	var contentDiv = $('content');
	var productDiv = $('productsBelt');
	var prev = $('leftBelt');
	var next = $('rightBelt');
	var currentPage = 0;
	var visible = 100;
	var pageUrl = new URI(document.location.toString());
	var pageView = pageUrl.get('data').view;
	var pageCookie = Cookie.read('productspage');
	var urlCookie = Cookie.read('url');
	
	if(productDiv){
		var products = productDiv.getChildren('.productBelt');
		
		if(products.length > 1){
			var pages = Math.ceil(products.length / 1);

			var productFx = new Fx.Tween(productDiv, { duration: 500, link: 'cancel', transition: 'Quad:out' });
			
			productDiv.setStyles({
		    width: visible * pages,
		    position: 'absolute',
		    top: 0,
		    left: 0
			});

			//var prev = new Element('a', {
			//	'id': 'left',
			//	'href': '#',
		    //'html': 'Prev'
			//}).inject(contentDiv);
			var prevPage = function(e){ 
				e.preventDefault();
        currentPage--;
        gotoPage(true);
      }
			
			//var next = new Element('a', {
			//	'id': 'right',
		    //'href': '#',
		    //'html': 'Next'
			//}).inject(contentDiv);
			var nextPage = function(e){ 
				e.preventDefault();
        currentPage++;
        gotoPage(true);
      }
      			
			if(pageView && pageView > 0){
				currentPage = pageView;
				gotoPage(true);
			}else if(pageCookie && urlCookie){
			if (urlCookie == pageUrl.get('filename')) {
					currentPage = pageCookie;
					gotoPage(true);
				}else{
					gotoPage(false);
				}
			}else{
				gotoPage(false);
			}
		}	
	}
	
	function gotoPage(track){
		if(currentPage <= 0){
			prev.addClass('inactive');
			prev.removeEvent('click', prevPage);
		}else{
			prev.removeClass('inactive');
			prev.addEvent('click', prevPage);
		}
		if(currentPage >= pages-1){
			next.addClass('inactive');
			next.removeEvent('click', nextPage);
		}else{
			next.removeClass('inactive');
			next.addEvent('click', nextPage);
		}
		productFx.cancel();
		productFx.start('left', -visible * currentPage);
		Cookie.write('productspage', currentPage, { path: "/" });
		Cookie.write('url', pageUrl.get('filename'), { path: "/" });
	}
	
});

// !Product scroll Trouser
window.addEvent('domready', function() {
	var contentDiv = $('content');
	var productDiv = $('productsTrouser');
	var prev = $('leftTrouser');
	var next = $('rightTrouser');
	var currentPage = 0;
	var visible = 150;
	var pageUrl = new URI(document.location.toString());
	var pageView = pageUrl.get('data').view;
	var pageCookie = Cookie.read('productspage');
	var urlCookie = Cookie.read('url');
	
	if(productDiv){
		var products = productDiv.getChildren('.productTrouser');
		
		if(products.length > 1){
			var pages = Math.ceil(products.length / 1);

			var productFx = new Fx.Tween(productDiv, { duration: 500, link: 'cancel', transition: 'Quad:out' });
			
			productDiv.setStyles({
		    width: visible * pages,
		    position: 'absolute',
		    top: 0,
		    left: 0
			});

			//var prev = new Element('a', {
			//	'id': 'left',
			//	'href': '#',
		    //'html': 'Prev'
			//}).inject(contentDiv);
			var prevPage = function(e){ 
				e.preventDefault();
        currentPage--;
        gotoPage(true);
      }
			
			//var next = new Element('a', {
			//	'id': 'right',
		    //'href': '#',
		    //'html': 'Next'
			//}).inject(contentDiv);
			var nextPage = function(e){ 
				e.preventDefault();
        currentPage++;
        gotoPage(true);
      }
      			
			if(pageView && pageView > 0){
				currentPage = pageView;
				gotoPage(true);
			}else if(pageCookie && urlCookie){
			if (urlCookie == pageUrl.get('filename')) {
					currentPage = pageCookie;
					gotoPage(true);
				}else{
					gotoPage(false);
				}
			}else{
				gotoPage(false);
			}
		}	
	}
	
	function gotoPage(track){
		if(currentPage <= 0){
			prev.addClass('inactive');
			prev.removeEvent('click', prevPage);
		}else{
			prev.removeClass('inactive');
			prev.addEvent('click', prevPage);
		}
		if(currentPage >= pages-1){
			next.addClass('inactive');
			next.removeEvent('click', nextPage);
		}else{
			next.removeClass('inactive');
			next.addEvent('click', nextPage);
		}
		productFx.cancel();
		productFx.start('left', -visible * currentPage);
		Cookie.write('productspage', currentPage, { path: "/" });
		Cookie.write('url', pageUrl.get('filename'), { path: "/" });
	}
	
});