/*
//version1
File Name   : main-new.js
Author      : Bang Daejong
*/

window.onload = function() {
	/* 110609 수정 */
    controlGNB();
	if(document.getElementById('highlight_01') != undefined){
		ellipsis('highlight_01');
		ellipsis('highlight_02');
		ellipsis('highlight_03');
	}
	/* //110609 수정 */
}

function controlGNB(){
    var VECHICLEGNB = document.getElementById('gnb-VECHICLE');
    var VECHICLESNB = document.getElementById('snb-VECHICLE');
	var aboutGNB = document.getElementById('gnb-about');
    var aboutSNB = document.getElementById('gnb-about').getElementsByTagName('div')[0];
    var shoppingFinanceGNB = document.getElementById('gnb-shoppingFinance');
    var shoppingFinanceSNB = document.getElementById('gnb-shoppingFinance').getElementsByTagName('div')[0];
    var serviceOwnersGNB = document.getElementById('gnb-serviceOwners');
    var serviceOwnersSNB = document.getElementById('gnb-serviceOwners').getElementsByTagName('div')[0];
    var newsEventsGNB = document.getElementById('gnb-newsEvents');
    var newsEventsSNB = document.getElementById('gnb-newsEvents').getElementsByTagName('div')[0];
	var mediaGNB = document.getElementById('gnb-media');
    var mediaSNB = document.getElementById('gnb-media').getElementsByTagName('div')[0];
	var contactGNB = document.getElementById('gnb-contact');
    var contactSNB = document.getElementById('gnb-contact').getElementsByTagName('div')[0];
	var etcGNB = document.getElementById('gnb-etc');

		//**** 20110329 add
		var etcSNB = null;
		if (etcGNB != null && etcGNB != "undefined"){
			if(etcGNB.getElementsByTagName('div').length > 0)
			etcSNB = etcGNB.getElementsByTagName('div')[0]
		}
		//**** 20110329 end


    //var etcSNB = document.getElementById('gnb-etc').getElementsByTagName('div')[0];


    var gnbs = [VECHICLEGNB, aboutGNB, shoppingFinanceGNB, serviceOwnersGNB, newsEventsGNB, mediaGNB, contactGNB, etcGNB];
    var snbs = [VECHICLESNB, aboutSNB, shoppingFinanceSNB ,serviceOwnersSNB, newsEventsSNB, mediaSNB, contactSNB, etcSNB];
    var index = -1;
    var timer = null;

    function overGNB(idx) {
        clearTimeout(timer);

        if (index != idx) {
            index = idx;

            for (var i = 0; i < gnbs.length; i++) {
            	//*** 20110329 ����
    						if( gnbs[i] == null || gnbs[i] == "undefined") continue;
                	jQuery(snbs[i]).stop();
            	//*** 20110329 ��

                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++) {
            	//*** 20110329 ����
    					if( gnbs[i] == null || gnbs[i] == "undefined") continue;
            	//*** 20110329 ��


							gnbs[i].getElementsByTagName('a')[0].className = 'gnb';
              jQuery(snbs[i]).slideUp();
            }
        }, 500);
    };

    for (var i = 0; i < gnbs.length; i++) {
    	//*** 20110329 ����
    	if( gnbs[i] == null || gnbs[i] == "undefined") continue;
    	//*** 20110329 ��

      gnbs[i].onmouseover = snbs[i].onmouseover = function() {
          var idx = i;
          return function(){ overGNB(idx); };
      }();

      gnbs[i].onmouseout = outGNB;
    }

    var articlePassengerLi = document.getElementById('article-passenger').getElementsByTagName('li');
    var articleRecreationalLi = document.getElementById('article-recreational').getElementsByTagName('li');

    for(var i=0;i<articlePassengerLi.length;i++){
        articlePassengerLi[i].onmouseover = function(){
            this.getElementsByTagName('p')[0].style.color = '#0f5699';

            this.onmouseout = function(){
                this.getElementsByTagName('p')[0].style.color = '#666';
            }
        }
        articlePassengerLi[i].onclick = function(){
            location.href = this.getElementsByTagName('a')[0].href;
        }
    }

    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;
        }
    }
}


