window.menuEffect={}
currentFrame = 1;

var allHTMLTags = new Array();

function getElementByClass(theClass) {
	var allHTMLTags=document.getElementsByTagName('*');
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].className==theClass) {

			allHTMLTags[i].style.display='none';

		}
	}
}

function showSubnav(obj, idx, resetEffect){
	if(!obj.hasClassName('hover')){
		obj.addClassName('hover');
	}
}
function hideSubnav(obj, idx){
	if(obj.hasClassName('hover')){
		obj.removeClassName('hover');
	}
}

function toggleSubnavBranch(idx, resetEffect){
	if(document.getElementById('subNav'+idx).style.display == 'none'){
		getElementByClass('rhssubnav');
		showSubnavBranch(idx, resetEffect);
	}else{
		hideSubnavBranch(idx);
	}
	return false;
}
function showSubnavBranch(idx, resetEffect){
	if(window.menuEffect[idx]){window.menuEffect[idx].cancel();}
	p = Position.cumulativeOffset($('nav'+idx))
	l = ($('subNav'+idx).getDimensions().width) / 2;
	l2 = ($('nav'+idx).getDimensions().width) / 2;
	marginWidth = (document.all) ? 0 : 60;
	$('subNav'+idx).style.left = ((p[0] + l2) - (l + marginWidth)) + 'px';
	if(resetEffect){
		if($('subNav'+idx).style.display == 'none'){
//                      window.menuEffect[idx] = new Effect.Appear($('subNav'+idx),{duration:.25});
			window.menuEffect[idx] = new Effect.SlideDown($('subNav'+idx),{duration:.25});
		}
	}
	$('nav'+idx).className = (($('nav'+idx).className.indexOf('focus') > 0)) ? 'focus hover' : 'hover';
}
function hideSubnavBranch(idx){
	if(window.menuEffect[idx]){window.menuEffect[idx].cancel();}
//      window.menuEffect[idx] = new Effect.Fade($('subNav'+idx),{duration:.25});
	window.menuEffect[idx] = new Effect.SlideUp($('subNav'+idx),{duration:.25});
	document.getElementById('nav'+idx).className = '';
	$('nav'+idx).className = (($('nav'+idx).className.indexOf('focus') > 0)) ? 'focus' : '';
}

var showcase = Class.create();

showcase.prototype = {
	text : [],
	images : [],

	width : 0,
	height : 0,
	currentIdx : 0,

	initialize : function(p) {
		this.setProperties(p);
		this.buildViewer(this);
	},
	setProperties : function(p){
		this.text = p.text;
		this.images = p.images;
		this.width = p.width;
		this.height = p.height;
	},
	
	buildViewer : function(self){
		var viewer_main = Builder.node('div', {id:"showcase"}); // Main container
			with(viewer_main.style){
				width = this.width + 'px';
				height = this.height + 'px';
				overflow = 'hidden';
				position = 'relative';
			}

			Event.observe(viewer_main, 'mouseover', function(e){
				clearTimeout(window.showcaseTimer);
			 	/* if(window.naveffect){window.naveffect.cancel();}
				posTo = ( ( this.offsetHeight / 3 ) * 2 ) - $('showcase_menu').offsetTop;
				window.naveffect = new Effect.MoveBy($('showcase_menu'), posTo, 0); */
			});

			Event.observe(viewer_main, 'mouseout', function(e){
				window.showcaseTimer = setTimeout("scrollShowcase()", 5000);
			 	/* if(window.naveffect){window.naveffect.cancel();}
				posTo = this.offsetHeight - $('showcase_menu').offsetTop;
				window.naveffect = new Effect.MoveBy($('showcase_menu'), posTo, 0); */
			});

			var viewer_inner = Builder.node('div', {id:"showcase-inner"});
			with(viewer_inner.style){
				width = ( ( this.width * this.images.length ) + 30 ) + 'px';
			}

			var viewer_nav = Builder.node('div', {id:"showcase_nav"});
			with(viewer_nav.style){
				position = 'absolute';
				top = '100px';
				left = ( this.width - ( this.images.length * 15 ) ) + 'px';
			}

			this.images.each(
				function(src, idx){
					var img = Builder.node('img');
					img.src = src;
					img.idx = idx;
					viewer_inner.appendChild(img);
					
					var button = Builder.node('span');
					//button.src = 'themes/acon/assets/img/campaignButton.gif';
					with(button.style){
						fontWeight = "bold";
						if(idx == 0){
							color = "#F09";
						}else{
							color = "#FFF";
						}
						padding = "3px";
						cursor = "hand"
						cursor = "pointer"
					}
					
					button.innerHTML = (idx + 1);
					button.idx = idx;
					button.id = "showcase-button-"+idx;
					button.txt = self.text[idx];
					button.pos = 0 - (idx * self.width);

					Event.observe(button, 'click', function(e){
					 	if(window.effect){window.effect.cancel();}
						v.currentIdx = this.idx;
						posTo = this.pos + (-1 * $('showcase-inner').offsetLeft);
						window.effect = new Effect.MoveBy($('showcase-inner'), 0, posTo, {duration:0.5, afterFinish:function(){changeText(idx, self)}});
					});
					viewer_nav.appendChild(button);
				}
			)
			
		viewer_main.appendChild(viewer_inner);

			var viewer_menu = Builder.node('div', {id:"showcase_menu"});
			with(viewer_menu.style){
				position = 'absolute';
				top = (this.height - ( this.height / 3 )) + 'px'; /* Change to this.height */
				width = this.width;
				height = ( this.height / 3 ) + 'px';
				left = '0px';
			}
				var viewer_mask = Builder.node('div', {id:"showcase_mask"});
				with(viewer_mask.style){
					height = ( this.height / 3 ) + 'px';
					width = this.width;
				}
			viewer_menu.appendChild(viewer_mask);
				var viewer_text = Builder.node('div', {id:"showcase_text"});
				with(viewer_text.style){
//					width = ( ( this.width / 10 ) * 9 ) + 'px';
					width = (this.width - 20) + 'px';
				}
			viewer_menu.appendChild(viewer_text);
			viewer_menu.appendChild(viewer_nav);
		viewer_main.appendChild(viewer_menu);

		$(viewerDiv).appendChild(viewer_main);

	    new Effect.Appear($('showcase_mask'), { duration: .05, from: 0.0, to: 0.85 });
		$('showcase_text').innerHTML = self.text[0];
		window.showcaseTimer = setTimeout("scrollShowcase()", 5000);
		
	}
}
function scrollShowcase(){
		v.currentIdx = (v.currentIdx + 1 < v.images.length) ? v.currentIdx + 1 : 0;
	 	if(window.effect){window.effect.cancel();}
		posTo = (0 - (v.currentIdx * v.width)) + (-1 * $('showcase-inner').offsetLeft);
		window.effect = new Effect.MoveBy($('showcase-inner'), 0, posTo, {duration:0.5, afterFinish:function(){changeText(v.currentIdx, v)}});
		window.showcaseTimer = setTimeout("scrollShowcase()", 5000);
}

function changeText(idx, self){
	for(im = 0; im < self.images.length; im++){
		$("showcase-button-" + im).style.color = (im == idx) ? "#F09" : "#FFF";
	}
	$('showcase_text').nextValue = self.text[idx];
    new Effect.Fade($('showcase_text'), { duration: .25,afterFinish:function(self){
		$('showcase_text').innerHTML = $('showcase_text').nextValue;
		new Effect.Appear($('showcase_text'), {duration: .25});
	}});
}
aMenus = [];
window.effects = {};
function accordion(idx){

	if(!$("subNav"+idx).visible())window.effects[idx] = Effect.BlindDown($("subNav"+idx),{duration:.25})
	for(i=0; i<aMenus.length; i++){
	
		if(idx != aMenus[i]){
			if(window.effects[aMenus[i]])window.effects[aMenus[i]].cancel();
			if($("subNav"+aMenus[i]).visible()){
				window.effects[aMenus[i]] = Effect.BlindUp($("subNav"+aMenus[i]),{duration:.25})
			}
		}
	}
	
}


Event.observe(window, 'load', function(e){
	$A($$('fieldset.collapsible')).each(
		function(obj, idx){
			obj.id = "cfs_"+idx;
			$A(obj.getElementsByTagName('legend')).each(
				function(l){
					Event.observe(l, 'click', function(){
						if($("cfs_"+idx).hasClassName('collapsed')){
							$("cfs_"+idx).removeClassName('collapsed');
						}else{
							$("cfs_"+idx).addClassName('collapsed');
						}
					});
				}
			);
		}
	)
	if(navigator.appVersion.indexOf("MSIE") >= 0){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		
		if ((version >= 5.5) && (version < 7) && (document.body.filters)){
		   for(var i=0; i<document.images.length; i++){
		      var img = document.images[i]
		      var imgName = img.src.toUpperCase()
		      if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
		         var imgID = (img.id) ? "id='" + img.id + "' " : ""
		         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		         var imgStyle = "display:inline-block;" + img.style.cssText 
		         if (img.align == "left") imgStyle = "float:left;" + imgStyle
		         if (img.align == "right") imgStyle = "float:right;" + imgStyle
		         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		         var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + 
"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
		         img.outerHTML = strNewHTML
		         i = i-1
		      }
		   }
		}
	}
//        Event.observe($('nav888'), 'click', function(e){
//		e.preventDefault();
//	});
});


