/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Varien
 * @package     js
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * @classDescription simple Navigation with replacing old handlers
 * @param {String} id id of ul element with navigation lists
 * @param {Object} settings object with settings
 */
var mainNav = function() {

    var main = {
        obj_nav :   $(arguments[0]) || $("nav"),

        settings :  {
            show_delay      :   0,
            hide_delay      :   0,
            _ie6            :   /MSIE 6.+Win/.test(navigator.userAgent),
            _ie7            :   /MSIE 7.+Win/.test(navigator.userAgent)
        },

        init :  function(obj, level) {
            obj.lists = obj.childElements();
            obj.lists.each(function(el,ind){
                main.handlNavElement(el);
                if((main.settings._ie6 || main.settings._ie7) && level){
                    main.ieFixZIndex(el, ind, obj.lists.size());
                }
            });
            if(main.settings._ie6 && !level){
                document.execCommand("BackgroundImageCache", false, true);
            }
        },

        handlNavElement :   function(list) {
            if(list !== undefined){
                list.onmouseover = function(){
                    main.fireNavEvent(this,true);
                };
                list.onmouseout = function(){
                    main.fireNavEvent(this,false);
                };
                if(list.down("ul")){
                    main.init(list.down("ul"), true);
                }
            }
        },

        ieFixZIndex : function(el, i, l) {
            if(el.tagName.toString().toLowerCase().indexOf("iframe") == -1){
                el.style.zIndex = l - i;
            } else {
                el.onmouseover = "null";
                el.onmouseout = "null";
            }
        },

        fireNavEvent :  function(elm,ev) {
            if(ev){
                elm.addClassName("over");
                elm.down("a").addClassName("over");
                if (elm.childElements()[1]) {
                    main.show(elm.childElements()[1]);
                }
            } else {
                elm.removeClassName("over");
                elm.down("a").removeClassName("over");
                if (elm.childElements()[1]) {
                    main.hide(elm.childElements()[1]);
                }
            }
        },

        show : function (sub_elm) {
            if (sub_elm.hide_time_id) {
                clearTimeout(sub_elm.hide_time_id);
            }
            sub_elm.show_time_id = setTimeout(function() {
                if (!sub_elm.hasClassName("shown-sub")) {
                    sub_elm.addClassName("shown-sub");
                }
            }, main.settings.show_delay);
        },

        hide : function (sub_elm) {
            if (sub_elm.show_time_id) {
                clearTimeout(sub_elm.show_time_id);
            }
            sub_elm.hide_time_id = setTimeout(function(){
                if (sub_elm.hasClassName("shown-sub")) {
                    sub_elm.removeClassName("shown-sub");
                }
            }, main.settings.hide_delay);
        }

    };
    if (arguments[1]) {
        main.settings = Object.extend(main.settings, arguments[1]);
    }
    if (main.obj_nav) {
        main.init(main.obj_nav, false);
    }
};

document.observe("dom:loaded", function() {
    //run navigation without delays and with default id="#nav"
    //mainNav();

    //run navigation with delays
    mainNav("nav", {"show_delay":"100","hide_delay":"100"});
    
    
	$$('.faitem img').invoke('observe', 'mouseover', function(e) {
		var xsrc = Event.element(e).src;
		Event.element(e).src = xsrc.replace('inactive','active');			
	});
	
	$$('.faitem img').invoke('observe', 'mouseout', function(e) {
		var xsrc = Event.element(e).src;
		Event.element(e).src = xsrc.replace('active','inactive');
	});
	
	
	//footer quick contact...
     // action=/process-quick-contact.php
     
     
     
     $('qc-send').observe( 'click', function(e) {
		//var xsrc = Event.element(e).src;
		//Event.element(e).src = xsrc.replace('inactive','active');
		var berrors = false;
		e.stop();
		//var element = e.element();
		//alert('here');
		var name_value = $('qc-name').value;
		var email_value = $('qc-email').value;
		//var email_value = $('qc-name').value;
		
		if( name_value == "" || name_value == "Name" ) {
		 	berrors = true;
		}
		
		if( email_value == "" || email_value == "Name" ) {
		 	berrors = true;
		}
		
		if( berrors ) {
		     //show error messages
		     $('fferrormsg').update('Errors! Please check the quick contact form above.');
		     
		} else {
			$('qc-form').action = '/process-quick-contact.php';
		 	$('qc-form').submit();
		}	
		 
		 
	});
	
	
	//heat application
	$('happ-send').observe( 'click', function(e) {
		//var xsrc = Event.element(e).src;
		//Event.element(e).src = xsrc.replace('inactive','active');
		var berrors = false;
		e.stop();
		
		var name_value = $('happ-name').value;
		var email_value = $('happ-email').value;
		var address_value = $('happ-address').value;
		var city_value = $('happ-city').value;
		var state_value = $('happ-state').value;
		var zipcode_value = $('happ-zipcode').value;
		var email_value = $('happ-email').value;
		var phone1_value = $('happ-phone1').value;
		
		if( name_value == "" ) { berrors = true; }
		if( email_value == "" ) { berrors = true; }
		if( address_value == "" ) { berrors = true; }
		if( city_value == "" ) { berrors = true; }
		if( state_value == "" ) { berrors = true; }
		if( zipcode_value == "" ) { berrors = true; }
		if( email_value == "" ) { berrors = true; }
		if( phone1_value == "" ) { berrors = true; }
		
		if( berrors ) {
		     //show error messages
		     $('fferrormsg2').update('Errors! Please check the quick contact form above.');
		     
		} else {
			$('happ-form').action = '/process-heat-app.php';
		 	$('happ-form').submit();
		}	
		 
		 
	});
	
	
});




