window.addEvent('domready', function() {

	/* drop down on Main Menu *
	if ($('globalMenu')) {
		$$('.effect','UL.basicMenu').each(function(obj){

			// Go through each LI child, process only if child is UL and class basicMenuSubMenu
			if (obj.childNodes[1] && obj.childNodes[1].tagName=='UL' && obj.childNodes[1].className=='basicMenuSubMenu' ){
				var fx = new Fx.Styles(obj.childNodes[1], {duration:300, wait:false,transition: Fx.Transitions.Quad.easeIn});
					obj.addEvent('mouseenter', function(){
						obj.childNodes[1].style.display = 'block';
						fx.start({ 'opacity':1	});
						obj.addClass('active');
					});
					obj.addEvent('mouseleave', function(){
						fx.start({ 'opacity':0 });
						obj.childNodes[1].style.display = 'none';
						obj.removeClass('active');
					});
			}
		});

	} // */


	/* Catalog Side Menu show/hide submenus */
	if ($('catalogSideMenu')) {
		var CatalogSidemenu;
		var counter = 0;
		$$('.menuItem','UL.basicMenuCatalog').each(function(obj){
			//CatalogSidemenu.containers = [counter];
			//console.log('obj',obj);
			/* Go through each LI child, process only if child is UL and class basicMenuSubMenu */
			if (obj.childNodes[1] && obj.childNodes[1].tagName=='UL' && obj.childNodes[1].className=='basicMenuSubMenuCatalog' &&
				obj.childNodes[0] && obj.childNodes[0].tagName=='A'){
				var target = obj.childNodes[0];
				var height = obj.childNodes[1].offsetHeight;
				var fxCatalogSidemenu = new Fx.Styles(obj.childNodes[1], {duration:300, wait:false, transition:Fx.Transitions.Quad.easeIn});

				if (target && target.addEvent){  //alert(target);
					target.addEvent('click', function(){
						// console.log('target is clicked',target );

						if (obj.childNodes[1].offsetHeight<=0){
							fxCatalogSidemenu.start({ 'height':height+'px', 'opacity':1	});
							obj.removeClass('nonactive');
						}else{
							fxCatalogSidemenu.start({ 'height':'0px', 'opacity':0 });
							obj.addClass('nonactive');
						}
					});
				}
				counter++;
			}
		});
	}

	/* Catalog Search Form - Expand search filter */
	if ($('productSearchFilter')){
		var fxSearchCatalogExpand = new Fx.Styles($('productSearchFilter'), {duration:300,wait:false,transition:Fx.Transitions.Quad.easeIn});
		var childNodes = $('productSearchFilter').childNodes;

		if ($('productSearchExpand')){
			//Expand
			$('productSearchExpand').addEvent('click',function(){
				fxSearchCatalogExpand.start({'height':'82px','opacity':1});
				$('productSearchFilter').style.visibilty='visible';
				$('productSearchHide').style.visibility='visible';
				$('productSearchExpand').style.visibility='hidden';
			});
		}

		if ($('productSearchHide')){
			//Hide
			$('productSearchHide').addEvent('click',function(){
				fxSearchCatalogExpand.start({'height':'0px','opacity':0});
				$('productSearchFilter').style.visibilty='hidden';
				$('productSearchHide').style.visibility='hidden';
				$('productSearchExpand').style.visibility='visible';
			});
		}
	}


	/* Virtual Shopping Cart */
	if ($('vcart_icon')){
		var vcart_display = false;
		var fxVirtualCart = new Fx.Styles($('vcart_wrapper'), {duration:300,wait:false,transition:Fx.Transitions.Quad.easeIn});

		if ($('vcart_icon')){
			$('vcart_icon').addEvent('click',function(){
				if (vcart_display==false){
					//Expand
					//fxVirtualCart.start({'height':'397px','opacity':1,'visibility':'visible'});
					fxVirtualCart.start({'height':'397px','opacity':1});
					vcart_display = true;
				}else{
					//Hide
					//fxVirtualCart.start({'height':'0px','opacity':0,'visibility':'hidden'});
					fxVirtualCart.start({'height':'0px','opacity':0});
					vcart_display = false;
				}
			});
		}
		if ($('closeVcart')){
			$('closeVcart').addEvent('click',function(){
				//Hide
				//fxVirtualCart.start({'height':'0px','opacity':0,'visibility':'hidden'});
				fxVirtualCart.start({'height':'0px','opacity':0});
				vcart_display = false;
			});
		}

	}
	/*
	//Virtual Cart using Fx.Slide
	var displayed = false;
	var slide = null;

	function toggleCart(e) {
		e = new Event(e);
		if (displayed == true) {
			slide.slideOut().chain(function() {$("vcart_wrapper").setStyle("display", "none");});
			displayed = false;
		} else {
			$("vcart_wrapper").setStyle("display", "block");
			slide.slideIn();
			displayed = true;
		}
		e.stop();
	}

	window.addEvent("domready", function() {
		slide = new Fx.Slide("vcart_box");
		displayed = false;

		slide.slideOut().chain(function() {$("vcart_wrapper").setStyle("display", "none");});
		$("vcart_icon").addEvent("click", function(e) {
			toggleCart(e);
		})
	});*/



	if ($('popupContainer')){
		var popupimages = $$('#popupContainer A');
		showHide(0);

	}
	function showHide(id){
		var popupfx = new Fx.Styles(popupimages[id], {duration:500, wait:false,transition: Fx.Transitions.Quad.easeOut});
		(function(){
				 	popupfx.start ({ 'top': 0});
				  }).delay(1000);
		(function(){
				  	popupfx.start ({'top':175});
					if (id+1 < popupimages.length){
						showHide(id+1);
					}else {
						showHide(0);
					}
		}).delay(5000);

	}

	//tickerInit();

	//adjust height of selectContainers on Footer
	selectMenuHeight();


})


