// -----------------------------------------------------------------------------------
//
//	CrescentProMenu v1.0
//	by Alonzo Turner - http://www.subtextproductions.com
//	01/16/08
//
//	For more information on this script, visit:
//	http://www.subtextproductions.com/opensource/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Lokesh Dhakar(huddletogether.com), Thomas Fuchs(mir.aculo.us), Sam Stephenson(prototypejs.org), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	TABLE OF CONTENTS
	-----------------

	CRESCENT PRO MENU CLASS DECLARATION
	- initialize()
	- highlight()
	- scrollface()
	- animate()
	
	INSTANTIATION
	- addLoadEvent(initMenu)
	
*/
// -----------------------------------------------------------------------------------


var CrescentProMenu = Class.create({
	initialize: function(){
		this.effectDuration = 1.0;
		this.yposition = 0;
		this.menuLinks = $('buttons_').select('a');
		this.expertsPage = false;
		this.successPage = false;
		this.subMenu = false;
		this.subMenuPosition = "";
// -----------------------------------------------------------------------------------
//		Iterate through each link in the menu and add a function for on mouseover.
//		This will move the scrollbar to align with each link on when the mouse
//		activates that link.
// -----------------------------------------------------------------------------------
		this.menuLinks.each(function(s){
			s.onmouseover = function(){
				switch(this.id){
				case "home-button_":
					$('scroll-face_').setStyle({ top: '0px' });
					break;
				case "reserved-button_":
					$('scroll-face_').setStyle({ top: '27px' });
					break;
				case "color-button_":
					if(myMenu.subMenu){
						if(myMenu.subMenuPosition == "color" || myMenu.subMenuPosition == "tools"){
							$('scroll-face_').setStyle({ top: '54px' });
						}else{
							$('scroll-face_').setStyle({ top: '74px' });
						}
					}else{
						$('scroll-face_').setStyle({ top: '54px' });
					}
					break;
				case "business-button_":
					if(myMenu.subMenu){
						if(myMenu.subMenuPosition == "tools"){
							$('scroll-face_').setStyle({ top: '81px' });
						}else{
							$('scroll-face_').setStyle({ top: '101px' });
						}
					}else{
						$('scroll-face_').setStyle({ top: '81px' });
					}
					break;
				case "success-button_":
					if(myMenu.subMenu){
						$('scroll-face_').setStyle({ top: '128px' });
					}else{
						$('scroll-face_').setStyle({ top: '108px' });
					}
					break;
				case "tips-button_":
					if(myMenu.subMenu){
						$('scroll-face_').setStyle({ top: '156px' });
					}else{
						if(myMenu.successPage){
							$('scroll-face_').setStyle({ top: '156px' });
						}else{
							$('scroll-face_').setStyle({ top: '136px' });
						}
					}
					break;
				case "custom-button_":
					if(myMenu.subMenu){
						$('scroll-face_').setStyle({ top: '187px' });
					}else{
						if(myMenu.expertsPage || myMenu.successPage){
							$('scroll-face_').setStyle({ top: '187px' });
						}else{
							$('scroll-face_').setStyle({ top: '167px' });
						}
					}
					break;
					
				case "scholarship-button_":
					if(myMenu.subMenu){
						$('scroll-face_').setStyle({ top: '226px' });
					}else{
						if(myMenu.expertsPage || myMenu.successPage){
							$('scroll-face_').setStyle({ top: '226px' });
						}else{
							$('scroll-face_').setStyle({ top: '206px' });
						}
					}
					break;
					
				case "products-button_":
					if(myMenu.subMenu){
						$('scroll-face_').setStyle({ top: '263px' });
					}else{
						if(myMenu.expertsPage || myMenu.successPage){
							$('scroll-face_').setStyle({ top: '263px' });
						}else{
							$('scroll-face_').setStyle({ top: '243px' });
						}
					}
					break;
					
				
				}
				myMenu.scrollface(false);
				myMenu.scrollface2(false);
			}
		});
		
// -----------------------------------------------------------------------------------
//		Do the same thing to the larger "RagMat" button at the bottom of the menu.
// -----------------------------------------------------------------------------------
		$('survey-button_').onmouseover = function(){
			$('scroll-face_').setStyle({ top: '380px' });
			myMenu.scrollface2(true);
			myMenu.scrollface(false);
		}		
			

// -----------------------------------------------------------------------------------
//		Do the same thing to the larger "RagMat" button at the bottom of the menu.
// -----------------------------------------------------------------------------------
		$('ragmat-button_').onmouseover = function(){
			$('scroll-face_').setStyle({ top: '312px' });
			myMenu.scrollface2(false);
			myMenu.scrollface(true);
		}

// -----------------------------------------------------------------------------------
//		Replace the standard 'draw' method of the draggable object. This modified
//		method will ensure that the object is not dragged outside the boundaries of
//		its parent element.
// -----------------------------------------------------------------------------------
		Draggable.addMethods({
			draw: function(point) {
				var parentSize = this.element.up().getDimensions();
				var thisSize = this.element.getDimensions();
				var boundaries = [parentSize.width - thisSize.width, parentSize.height - thisSize.height];
// -----------------------------------------------------------------------------------
//				Get the dimensions of the parent element and the draggable element.
//				Calculate the boundaries for positioning the draggable element within
//				the parent.
// -----------------------------------------------------------------------------------
				var pos = Position.cumulativeOffset(this.element);
				if(this.options.ghosting) {
					 var r	 = Position.realOffset(this.element);
					 pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
				}
				
				var d = this.currentDelta();
				pos[0] -= d[0]; pos[1] -= d[1];
				
				if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
					 pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
					 pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
				}
				
				var p = [0,1].map(function(i){ 
					 return (point[i]-pos[i]-this.offset[i]) 
				}.bind(this));
				
				if(this.options.snap) {
					if(Object.isFunction(this.options.snap)) {
						p = this.options.snap(p[0],p[1],this);
					} else {
						if(Object.isArray(this.options.snap)) {
							p = p.map( function(v, i) {
							return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
						} else {
							p = p.map( function(v) {
					 		return (v/this.options.snap).round()*this.options.snap }.bind(this))
					 	}
					}
				}
				
				var style = this.element.style;
				if((!this.options.constraint) || (this.options.constraint=='horizontal')){
					switch(true){
					case p[0] < 0:
						style.left = "0px";
						break;
					case p[0] > boundaries[0]:
						style.left = boundaries[0] + "px";
						break;
					default:
						style.left = p[0] + "px";
					}
				}
				if((!this.options.constraint) || (this.options.constraint=='vertical')){
					switch(true){
					case p[1] < 0:
						style.top = "0px";
						break;
					case p[1] > boundaries[1]:
						style.top = boundaries[1] + "px";
						break;
					default:
						style.top = p[1] + "px";
					}
				}
				
				if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
			}
		});
	},
	
	highlight: function(someElement){
		this.menuLinks.each(function(s){
			if(s != someElement){
				s.removeClassName('highlight_');
			}else{
				s.addClassName('highlight_');
			}
		});
	},
	
	scrollface: function(someBoolean){
		if(someBoolean){
			$('scroll-face_').setStyle({
				height: "63px",
				backgroundImage: "url(images/scroll-face-long.png)"
			});
		
		}else{
			if(parseInt($('scroll-face_').getStyle('height')) == 63){
				$('scroll-face_').setStyle({
					height: "30px",
					backgroundImage: "url(images/scroll-face.png)"
				});
			}
		}
	},
	
	scrollface2: function(someBoolean){
		if(someBoolean){
			$('scroll-face_').setStyle({
				height: "49px",
				backgroundImage: "url(images/scroll-face-long.png)"
			});
		
		}else{
			if(parseInt($('scroll-face_').getStyle('height')) == 49){
				$('scroll-face_').setStyle({
					height: "30px",
					backgroundImage: "url(images/scroll-face.png)"
				});
			}
		}
	},
	
	animate: function(someObject){
		var myDrag = new Draggable(someObject, {
			snap: [1, 30],
			starteffect: function(someElement){},
			endeffect: function(someElement){},
// -----------------------------------------------------------------------------------
//			When dragging ends set the hidden form elements with the final position
//			of the draggable element.
// -----------------------------------------------------------------------------------
			onDrag: function(someDrag, someEvent){
				var someElement = someDrag.element;
				var somePosition = parseInt(someElement.getStyle('top'));
				if(myMenu.yposition != somePosition){
					myMenu.yposition = somePosition;
					switch(somePosition){
					case 0:
						myMenu.highlight($('home-button_'));
						myMenu.scrollface(false);
						break;
					case 30:
						myMenu.highlight($('reserved-button_'));
						myMenu.scrollface(false);
						break;
					case 60:
						myMenu.highlight($('color-button_'));
						myMenu.scrollface(false);
						break;
					case 90:
						myMenu.highlight($('business-button_'));
						myMenu.scrollface(false);
						break;
					case 120:
						myMenu.highlight($('success-button_'));
						myMenu.scrollface(false);
						break;
					case 150:
						myMenu.highlight($('tips-button_'));
						myMenu.scrollface(false);
						break;
					case 180:
						myMenu.highlight($('custom-button_'));
						myMenu.scrollface(false);
						break;
					case 185:
						myMenu.highlight($('custom-button_'));
						myMenu.scrollface(false);
						break;
					case 240:
						myMenu.highlight(null);
						myMenu.scrollface(true);
						break;
					default:
						myMenu.highlight(null);
						myMenu.scrollface(false);
						break;
					}
				}
			}
		});
	}
});


// -----------------------------------------------------------------------------------
//
//	AutoScroll v1.0
//	by Alonzo Turner - http://www.subtextproductions.com
//	01/16/08
//
//	For more information on this script, visit:
//	http://www.subtextproductions.com/opensource/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Lokesh Dhakar(huddletogether.com), Thomas Fuchs(mir.aculo.us), Sam Stephenson(prototypejs.org), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	TABLE OF CONTENTS
	-----------------

	AUTO SCROLL CLASS DECLARATION
	- initialize()
	- animate()
	
	INSTANTIATION
	- addLoadEvent(initScroll)
	
*/
// -----------------------------------------------------------------------------------

var AutoScroll = Class.create({
	initialize: function(){
		if ($('content_')==null){
			var scrollContainers = $('trends-content_').select('div.content-container_');
		}else{
		var scrollContainers = $('content_').select('div.content-container_');
		}
		if(scrollContainers.length > 0){
			this.containerHeight = parseInt(scrollContainers[0].getHeight()) - 30;
			this.content = scrollContainers[0].down();
			var contentHeight = parseInt(this.content.getHeight());
			this.scrollDelta = this.containerHeight - contentHeight;
			var scrollFace = scrollContainers[0].up().select('.scroll-face_');
			this.animate(scrollFace[0]);
		}
	},
		
	animate: function(someObject){
		var myDrag = new Draggable(someObject, {
			starteffect: function(someElement){},
			endeffect: function(someElement){},
// -----------------------------------------------------------------------------------
//	When dragging the object move the content section by an appropriate amount.
// -----------------------------------------------------------------------------------
			onDrag: function(someDrag, someEvent){
				if(myScroll.scrollDelta < 0){
					var someElement = someDrag.element;
					var somePosition = parseInt(someElement.getStyle('top'));
					var contentPosition = Math.floor((myScroll.scrollDelta/myScroll.containerHeight) * somePosition);
					myScroll.content.setStyle({ top: contentPosition + "px" });
					var someParent = someElement.up(1);
					
					
					if(navigator.appName == "Microsoft Internet Explorer"){
						if(someParent.id == "barb-content_"){
							if(somePosition > 240){
								if(parseInt($('barb-container_').getStyle('top')) == 0){
									$('barb-container_').setStyle({ top: "-448px" });
									//new Effect.Move('barb-container_', { x: 0, y: -446, duration: 0.5 });
								}
							}else{
								if(parseInt($('barb-container_').getStyle('top')) <= -448){
									$('barb-container_').setStyle({ top: "0px" });
								}
							}
						}
					}else{
						if(someParent.id == "barb-content_"){
							if(somePosition > 240){
								if(parseInt($('barb-container_').getStyle('top')) == 0){
									$('barb-container_').setStyle({ top: "-446px" });
									//new Effect.Move('barb-container_', { x: 0, y: -446, duration: 0.5 });
								}
							}else{
								if(parseInt($('barb-container_').getStyle('top')) <= -446){
									$('barb-container_').setStyle({ top: "0px" });
								}
							}
						}
					}
					
					if(navigator.appName == "Microsoft Internet Explorer"){
						if(someParent.id == "ragmat-dc-scroll_"){
							if(somePosition > 120){
								
									MM_swapImage('subnav','','images/RDC_ED_SubNav.jpg',1);
									
								
							}else{
								
									MM_swapImage('subnav','','images/RDC_MG_SubNav.jpg',1);
								
							}
						}
					}else{
						if(someParent.id == "ragmat-dc-scroll_"){
							if(somePosition > 120){
							
									MM_swapImage('subnav','','images/RDC_ED_SubNav.jpg',1);
									
							
							}else{
								
									MM_swapImage('subnav','','images/RDC_MG_SubNav.jpg',1);
								
							}
						}
					}
						
					
					
					
				}
			}
		});
	}
});

function initScroll() { myScroll = new AutoScroll(); }
Event.observe(window, 'load', initScroll, false);

// -----------------------------------------------------------------------------------
//
//	ThumbScroll v1.0
//	by Alonzo Turner - http://www.subtextproductions.com
//	01/16/08
//
//	For more information on this script, visit:
//	http://www.subtextproductions.com/opensource/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Lokesh Dhakar(huddletogether.com), Thomas Fuchs(mir.aculo.us), Sam Stephenson(prototypejs.org), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	TABLE OF CONTENTS
	-----------------

	THUMB SCROLL CLASS DECLARATION
	- initialize()
	- animate()
	
	INSTANTIATION
	- addLoadEvent(initMenu)
	
*/
// -----------------------------------------------------------------------------------

var ThumbScroll = Class.create({
	initialize: function(someFlag){
		this.contentHeight = parseInt($('thumb-content_').getHeight());
		this.scrollDelta = 446 - this.contentHeight;
		this.first = true;
		this.position = 0;
		this.button = "down";
		
		var thumbLinks = $('thumb-content_').select('a');
		
		for(var i=0; i < thumbLinks.length; i++){
			if(someFlag){
				thumbLinks[i].onclick = function(){
					var newPos = this.rel * -446;
					$('img-content_').setStyle({ top: newPos + "px" });
					switch(this.rel){
					case "1":
						var so = new SWFObject("flash/portfolio_2.swf", "portfolio-obj_", "1", "1", "9", "#FFFFFF");
						so.write("portfolios_");
					
						myMenu.subMenu = true;
						$('reserved-submenu_').src = "images/colortrends.jpg";
						$('reserved-submenu_').show();
						break;
					case "2":
						var so = new SWFObject("flash/portfolio.swf", "portfolio-obj_", "320", "446", "9", "#FFFFFF");
						so.write("portfolios_");
				
						myMenu.subMenu = true;
						$('reserved-submenu_').src = "images/colorandstyle.jpg";
						$('reserved-submenu_').show();
						break;
					
					case "3":
						myMenu.subMenu = true;
						$('reserved-submenu_').src = "images/cornerracks.jpg";
						$('reserved-submenu_').show();
						break;
					case "4":
						myMenu.subMenu = true;
						$('reserved-submenu_').src = "images/walldisplay.jpg";
						$('reserved-submenu_').show();
						break;
					case "5":
						myMenu.subMenu = true;
						$('reserved-submenu_').src = "images/lifetimewarranty.jpg";
						$('reserved-submenu_').show();
						break;
					case "6":
						myMenu.subMenu = false;
						$('reserved-submenu_').hide();
						break;
					}
					return false;
				}
				thumbLinks[i].onmouseover = function(){
					switch(this.rel){
					case "1":
						$('scroll-boundary').down().setStyle({ top: "0px" });
						$('thumb-highlight_').setStyle({ top: "0px" });
						break;
					case "2":
						$('scroll-boundary').down().setStyle({ top: "115px" });
						$('thumb-highlight_').setStyle({ top: "116px" });
						break;
					
					case "3":
						$('scroll-boundary').down().setStyle({ top: "5px" });
						$('thumb-highlight_').setStyle({ top: "8px" });
						break;
					case "4":
						$('scroll-boundary').down().setStyle({ top: "115px" });
						$('thumb-highlight_').setStyle({ top: "116px" });
						break;
					case "5":
						$('scroll-boundary').down().setStyle({ top: "224px" });
						$('thumb-highlight_').setStyle({ top: "226px" });
						break;
					case "6":
						$('scroll-boundary').down().setStyle({ top: "334px" });
						$('thumb-highlight_').setStyle({ top: "333px" });
						break;
					}
				}
			}else{
				
				thumbLinks[i].onclick = function(){
					var newPos = this.rel * -446;
					$('img-content_').setStyle({ top: newPos + "px" });
					switch(this.rel){
					case "1":
						myMenu.subMenu = true;
						myMenu.subMenuPosition = "color";
						$('reserved-submenu_').src = "images/colorandstyle.jpg";
						$('reserved-submenu_').show();
						break;
					case "2":
						myMenu.subMenu = true;
						myMenu.subMenuPosition = "color";
						$('reserved-submenu_').src = "images/colorbrochure.jpg";
						$('reserved-submenu_').show();
						break;
					case "3":
					window.location = "trends.html";
						myMenu.subMenu = true;
						myMenu.subMenuPosition = "color";
						$('reserved-submenu_').src = "images/colorbrochure.jpg";
						$('reserved-submenu_').show();
						break;
					case "4":
						myMenu.subMenu = true;
						myMenu.subMenuPosition = "color";
						$('reserved-submenu_').src = "images/worksheet.jpg";
						$('reserved-submenu_').show();
						break;
					}
					return false;
				}
				thumbLinks[i].onmouseover = function(){
					switch(this.rel){
					case "1":
						$('scroll-boundary').down().setStyle({ top: "0px" });
						$('thumb-highlight_').setStyle({ top: "3px" });
						break;
					case "2":
						$('scroll-boundary').down().setStyle({ top: "110px" });
						$('thumb-highlight_').setStyle({ top: "111px" });
						break;
					case "3":
						$('scroll-boundary').down().setStyle({ top: "219px" });
						$('thumb-highlight_').setStyle({ top: "221px" });
						break;
					case "4":
						$('scroll-boundary').down().setStyle({ top: "329px" });
						$('thumb-highlight_').setStyle({ top: "328px" });
						break;
					}
				}
			}
		}
	},
		
	animate: function(someObject){
		var myDrag = new Draggable(someObject, {
			snap: [1, 34],
			starteffect: function(someElement){},
			endeffect: function(someElement){},
// -----------------------------------------------------------------------------------
//			When dragging ends set the hidden form elements with the final position
//			of the draggable element.
// -----------------------------------------------------------------------------------
			onDrag: function(someDrag, someEvent){
				/*if(myThumb.first){
					myThumb.first = false;
					new Effect.Move($('img-content_'), { x: 0, y: -446, mode: 'relative', duration: 0.5, queue: 'end' });
				}*/
				var someElement = someDrag.element;
				var somePosition = parseInt(someElement.getStyle('top'));
				var newPosition;
				switch(somePosition){
				case 0:
					newPosition = "0px";
					break;
				case 34:
					newPosition = "-40px";
					break;
				case 68:
					newPosition = "-80px";
					break;
				case 102:
					newPosition = "-120px";
					break;
				case 136:
					newPosition = "-160px";
					break;
				case 170:
					newPosition = "-200px";
					break;
				case 204:
					newPosition = "-240px";
					break;
				case 238:
					newPosition = "-280px";
					break;
				case 272:
					newPosition = "-320px";
					break;
				}
				$('thumb-content_').setStyle({ top: newPosition });
				$('thumb-highlight_').setStyle({ top: (somePosition -4) + "px" });
				if(this.position != somePosition){
					var newIndex = ((this.position - somePosition)/34) * 446;
					//new Effect.Move($('img-content_'), { x: 0, y: newIndex, mode: 'relative', duration: 0.5, queue: 'end' });
					this.position = somePosition;
				}
			},
			
			onEnd: function(someDrag, someEvent){
				//new Effect.Move($('img-content_'), { x: 0, y: -446, mode: 'relative', duration: 0.5 });
				var someElement = someDrag.element;
				var somePosition = parseInt(someElement.getStyle('top'));
				var someOther = parseInt($('thumb-content_').getStyle('top'));
			}
		});
	},
	
	
	showcontent: function(someIndex){
		var newPos = (someIndex + 1) * -446;
		$('img-content_').setStyle({ top: newPos + "px" });
		switch(someIndex){
		case 0:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/colortrends.jpg";
			$('reserved-submenu_').show();
			break;
		case 1:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/colorandstyle.jpg";
			$('reserved-submenu_').show();
			break;
		case 2:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/customframing.jpg";
			$('reserved-submenu_').show();
			break;
		case 3:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/crescentconnection.jpg";
			$('reserved-submenu_').show();
			break;
		case 4:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/cornerracks.jpg";
			$('reserved-submenu_').show();
			break;
		case 5:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/walldisplay.jpg";
			$('reserved-submenu_').show();
			break;
		case 6:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/lifetimewarranty.jpg";
			$('reserved-submenu_').show();
			break;
		case 7:
			myMenu.subMenu = false;
			$('reserved-submenu_').hide();
			break;
		}
	}
});	


function postcardOpen(divName){
	if (document.getElementById(divName).style.visibility=='visible'){
		document.getElementById(divName).style.visibility='hidden';
		}else{
			document.getElementById(divName).style.visibility='visible';
		}
		}
function postcardClose(divName){
		document.getElementById(divName).style.visibility='hidden';
		}
		
		
function reservedSubNav(n){
	switch(n){
		case 0:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/colortrends.jpg";
			$('reserved-submenu_').show();
			break;
		case 1:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/colorandstyle.jpg";
			$('reserved-submenu_').show();
			break;
		case 2:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/customframing.jpg";
			$('reserved-submenu_').show();
			break;
		case 3:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/crescentconnection.jpg";
			$('reserved-submenu_').show();
			break;
		case 4:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/cornerracks.jpg";
			$('reserved-submenu_').show();
			break;
		case 5:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/walldisplay.jpg";
			$('reserved-submenu_').show();
			break;
		case 6:
			myMenu.subMenu = true;
			$('reserved-submenu_').src = "images/lifetimewarranty.jpg";
			$('reserved-submenu_').show();
			break;
		case 7:
			myMenu.subMenu = false;
			$('reserved-submenu_').hide();
			break;
		}
}
	
