/*
//version1
File Name   : sub_GNB.js
Author      : Bang Daejong
*/

/*
window.onload = function() {
    controlGNB();
    controlSearch();
}
*/

function onloadGNB() {
    controlGNB();
    //controlSearch();
}

if (window.addEventListener) {
    window.addEventListener("load", onloadGNB, false);
}
else if (window.attachEvent) {
    window.attachEvent("onload", onloadGNB);
}

function controlGNB(){
    var showroomGNB = document.getElementById('gnb-showroom');
    var showroomSNB = document.getElementById('snb-showroom');
	var postvenditaGNB = document.getElementById('gnb-postvendita');
    var postvenditaSNB = document.getElementById('snb-postvendita');
	var newsGNB = document.getElementById('gnb-news');
    var newsSNB = document.getElementById('snb-news');
	var mondoGNB = document.getElementById('gnb-mondo');
    var mondoSNB = document.getElementById('snb-mondo');
	var specialGNB = document.getElementById('gnb-special');
   // var specialSNB = document.getElementById('snb-special');
	//var configuratoreGNB = document.getElementById('gnb-configuratore');
   // var configuratoreSNB = document.getElementById('snb-configuratore');
 

   var gnbs = [showroomGNB, postvenditaGNB, newsGNB, mondoGNB];
   var snbs = [showroomSNB, postvenditaSNB, newsSNB, mondoSNB];
    var index = -1;
    var timer = null;

    function overGNB(idx) {
        clearTimeout(timer);

        if (index != idx) {
            index = idx;

            for (var i = 0; i < gnbs.length; i++) {
                jQuery(snbs[i]).stop();

                if (i == index) {
                    gnbs[i].getElementsByTagName('a')[0].className = 'gnb on';
                    snbs[i].style.height = null;
					
                    snbs[i].style.minHeight = 0;
					
						jQuery(snbs[i]).slideDown();
					
                }
                else {
                    gnbs[i].getElementsByTagName('a')[0].className = 'gnb';
                    snbs[i].style.display = 'none';
                }
            }
        }
    };

    var outGNB = function() {
        clearTimeout(timer);

        timer = setTimeout(function() {
            index = -1;

            for (var i = 0; i < gnbs.length; i++) {
                gnbs[i].getElementsByTagName('a')[0].className = 'gnb';
					
						jQuery(snbs[i]).slideUp();
					
                
            }
        }, 500);
    };

    for (var i = 0; i < gnbs.length; i++) {
        gnbs[i].onmouseover = snbs[i].onmouseover = function() {
            var idx = i;
            return function(){ overGNB(idx);};
        }();

        gnbs[i].onmouseout = snbs[i].onmouseout = outGNB;
    }

    /*
    function overGNB(GNB,SNB){
        GNB.className = 'gnb on';
        //SNB.style.display = 'block';
        SNB.style.height = null;
        jQuery(SNB).slideDown();

        SNB.onmouseover = function(){
            if (window.gnb_timer) {
                clearTimeout(window.gnb_timer);
                window.gnb_timer = null;
            }
            GNB.className = 'gnb on';
            //SNB.style.display = 'block';
            SNB.style.height = null;
            jQuery(SNB).slideDown();
        }

        GNB.onmouseout = function(){
            window.gnb_timer = setTimeout(function() {
                GNB.className = 'gnb';
                //SNB.style.display = 'none';
                jQuery(SNB).slideUp();
            }, 100);
        }
        SNB.onmouseout = function(){
            window.gnb_timer = setTimeout(function() {
                GNB.className = 'gnb';
                //SNB.style.display = 'none';
                jQuery(SNB).slideUp();
            }, 100);
        }
    }

    showroomGNB.onmouseover = function(){
        overGNB(showroomGNB,showroomSNB);
    }

    companyOverviewGNB.onmouseover = function(){
        overGNB(companyOverviewGNB,companyOverviewSNB);
    }

    hyundaiExperienceGNB.onmouseover = function(){
        overGNB(hyundaiExperienceGNB,hyundaiExperienceSNB);
    }
    */

    
	
	

    //for(var i=0;i<articleRecreationalLi.length;i++){
//        articleRecreationalLi[i].onmouseover = function(){
//            this.getElementsByTagName('p')[0].style.color = '#0f5699';
//
//            this.onmouseout = function(){
//                this.getElementsByTagName('p')[0].style.color = '#666';
//            }
//        }
//        articleRecreationalLi[i].onclick = function(){
//            location.href = this.getElementsByTagName('a')[0].href;
//        }
//    }
}
function facebookControl( type ){ // facebook?´ë¦­?ˆ&igrave;"???¸&igrave;¶œ, ?Œë¼ë¯¸í"° ê°'&igrave;œ¼ë¡?open, close ?"ë‹¬
	var e = document.getElementById('facebook');
	
	if(type=='open'){
		e.style.display = 'inline';
		window.fbAsyncInit = function() {
		FB.init({appId: 184484190795 , status: true, cookie: true, xfbml: true});
		};
		(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol +
		 '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);}());
	} else if(type=='close'){
		e.style.display = 'none';
		
	}
}
//function controlSearch(){
//    var searchInput = document.getElementById('article-search').getElementsByTagName('input')[0];
//
//    searchInput.onclick = function(){
//        searchInput.style.backgroundImage = 'none';
//    }
//}

