window.addEvent('domready', function(){	
	
	var aboutItems = $$('#about-navigation li');
	
	if(aboutItems){
		for(var i=0; i<aboutItems.length; i++){
			if(i != aboutItems.length -1){
				aboutItems[i].set('html', aboutItems[i].get('html') + ' | ');
			}
		} 
	}
	
	var productItems = $$('#product-navigation li');
	
	if(productItems){		
		for(var i=0; i<productItems.length; i++){		
			if(i != productItems.length -1){
				productItems[i].set('html', productItems[i].get('html') + ' | ');
			}
		} 
	}
	
	checkSubMenu();
	
	/* Forms */
	var formEnquiry = $('general-enquiry-container');	
	var formRequest = $('request-a-quote-container');
	var linkEnquiry = $('general-enquiry-link');
	var linkRequest = $('request-a-quote-link');
	
	if(formEnquiry){ formRequest.setStyle('display', 'none'); }
	
	if(linkEnquiry && linkRequest){
		linkEnquiry.addEvent('click', function(e){
			formRequest.setStyle('display', 'none');
			formEnquiry.setStyle('display', '');
			$('form-container-top').className = 'general-enquiry';
			linkEnquiry.setStyle('color', '#003572');
			linkRequest.setStyle('color', '#FFF');
		});
		
		linkRequest.addEvent('click', function(e){
			formEnquiry.setStyle('display', 'none');
			formRequest.setStyle('display', '');
			$('form-container-top').className = 'request-a-quote';
			linkRequest.setStyle('color', '#003572');
			linkEnquiry.setStyle('color', '#FFF');
		});
	}
  
  //Form Validation
  var generalEnquiry = $('general-submit');
  
  if(generalEnquiry){
    generalEnquiry.addEvent('click', function(e){
      new Event(e).stop();                    
      
      if($('ge-first-name').get('value') == ''){
        alert('Please enter your first name.');
      }
      else if($('ge-last-name').get('value') == ''){
        alert('Please enter your last name.');
      }
      else if($('ge-email').get('value') == ''){
        alert('Please enter your email.');
      }
      else{           
        form = document.getElementsByName('General-Enquiry');
        form[0].submit();
      }
      
    });    
  }
  
  var requestSubmit = $('request-submit');
  
  if(requestSubmit){
    requestSubmit.addEvent('click', function(e){
      new Event(e).stop();                    
      
      if($('re-first-name').get('value') == ''){
        alert('Please enter your first name.');
      }
      else if($('re-last-name').get('value') == ''){
        alert('Please enter your last name.');
      }
      else if($('re-email').get('value') == ''){
        alert('Please enter your email.');
      }
      else{                   
        form = document.getElementsByName('Request-a-Quote');
        form[0].submit();
      }
      
    });    
  }
  
	
	var productLinks = $$('.product-detail-links');
	var productDetails = $$('.product-details');			
	
	if(productLinks.length >= 1 && productDetails.length >= 1){			
		
		//Display first product by default
		productDetails[0].setStyle('display', 'block');
		productLinks[0].set('class', 'active');
		
		productLinks.addEvent('click', function(e){			
			var id = $(this).get('id').substring(21)

			productDetails.setStyle('display', 'none');
			productLinks.set('class', '');
			
			$(this).set('class', 'active');
			
			$('product-details-' + id).setStyle('display', 'block');			
		});      
	}

	$$('#menu li').addEvent('mouseover', function(e){
		$$('.sub-navigation-child').setStyle('display', 'none');

		if($(this).get('class').contains('item-113')){
 			$('about-navigation').setStyle('display', 'block'); 
		}	
		else if($(this).get('class').contains('item-114')){
 			$('product-navigation').setStyle('display', 'block'); 
		}
	});	

	var content = $('content');

	if(content){
		content.addEvent('mouseover', function(e){				
			checkSubMenu();					
		});
	}

	var sidingHotspot = $('hotspot-aluminum-siding');

	if(sidingHotspot){
		sidingHotspot.addEvent('mouseover', function(e){
			sidingHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/aluminum-siding-active.png) no-repeat');
		});
		
		sidingHotspot.addEvent('mouseout', function(e){
			sidingHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/aluminum-siding.png) no-repeat');
		});
	}

	var awningsHotspot = $('hotspot-awnings');

	if(awningsHotspot){
		awningsHotspot.addEvent('mouseover', function(e){
			awningsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/awnings-active.png) no-repeat');
		});
		
		awningsHotspot.addEvent('mouseout', function(e){
			awningsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/awnings.png) no-repeat');
		});
	}

	var windowsHotspot = $('hotspot-windows');

	if(windowsHotspot){
		windowsHotspot.addEvent('mouseover', function(e){
			windowsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/windows-active.png) no-repeat');
		});
		
		windowsHotspot.addEvent('mouseout', function(e){
			windowsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/windows.png) no-repeat');
		});
	}

	var doorsHotspot = $('hotspot-doors');

	if(doorsHotspot){
		doorsHotspot.addEvent('mouseover', function(e){
			doorsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/doors-active.png) no-repeat');
		});
		
		doorsHotspot.addEvent('mouseout', function(e){
			doorsHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/doors.png) no-repeat');
		});
	}

	var faciaHotspot = $('hotspot-facia');

	if(faciaHotspot){
		faciaHotspot.addEvent('mouseover', function(e){
			faciaHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/sofits-active.png) no-repeat');
		});
		
		faciaHotspot.addEvent('mouseout', function(e){
			faciaHotspot.setStyle('background', 'url(templates/allumination/images/hotspots/sofits.png) no-repeat');
		});
	}
});

//Show submenu if one if its children are the active page
function checkSubMenu(){	
	var subMenuItems = $$('.sub-navigation-child li');
	
	if(subMenuItems){
		$$('.sub-navigation-child').addClass('sub-nav-hide');
		
		for(var i=0; i<subMenuItems.length; i++){
			if(subMenuItems[i].get('class').contains('active')){									
				subMenuItems[i].getParent().getParent().removeClass('sub-nav-hide');
			}
		}
	}
	
	return;
}

