/*
File Name   : main-new.js
Author      : Bang Daejong
*/

window.onload = function() {
	controlVisual();
	sideBanner();
    controlGNB();
    controlSearch();
	controlMicrosite();
	linkFooter();
}

/*
function controlVisual(){
	var obj = document.getElementById('visualList').getElementsByTagName('li');

	for(var i=0;i<obj.length;i++){
		obj[i].onclick = function(){
			document.getElementById('visualImg').getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src;
			return false;
		}
	}
}
*/

function controlVisual(){
	var obj = document.getElementById('visualList').getElementsByTagName('li');

	for(var i=0;i<obj.length;i++){
		obj[i].onclick = function(){
			document.getElementById('visualImg').src = this.getElementsByTagName('img')[0].src;
		}
	}
}

function sideBanner(){
    var num = 0;

    var section = document.getElementById('side-banner');
    var elements = section.getElementsByTagName('li');
    var prev = document.getElementById('prev');
    var next = document.getElementById('next');

    for(var i=0;i<elements.length;i++){
        if(i>4){
            elements[i].style.display = 'none';
        }
    }

    prev.onclick = function(){
        if(elements[0].style.display != 'none'){
            return false;
        }

        for(var i=0;i<elements.length;i++){
            elements[i].style.display = 'none';
        }

        for(var j=0;j<5;j++){
            elements[num+j-1].style.display = '';
        }

        num--;
		return false;
    }

    prev.onmouseover = function(){
        prev.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src = prev.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src.replace(".gif","-on.gif");

        prev.onmouseout = function(){
            prev.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src = prev.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src.replace("-on.gif",".gif");
        }
    }

    next.onclick = function(){
        if(elements[elements.length-1].style.display != 'none'){
            return false;
        }

        for(var i=0;i<elements.length;i++){
            elements[i].style.display = 'none';
        }

        for(var j=0;j<5;j++){
            elements[num+j+1].style.display = '';
        }

        num++;
		return false;
    }

    next.onmouseover = function(){
        next.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src = next.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src.replace(".gif","-on.gif");

        next.onmouseout = function(){
            next.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src = next.getElementsByTagName('a')[0].getElementsByTagName('img')[0].src.replace("-on.gif",".gif");
        }
    }
}

function controlGNB(){
    var showroomGNB = document.getElementById('showroom');
    var showroomSNB = document.getElementById('snb-showroom');
    var companyOverviewGNB = document.getElementById('companyOverview');
    var companyOverviewSNB = document.getElementById('companyOverview').getElementsByTagName('div')[0];
    var hyundaiExperienceGNB = document.getElementById('hyundaiExperience');
    var hyundaiExperienceSNB = document.getElementById('hyundaiExperience').getElementsByTagName('div')[0];

    var gnbs = [showroomGNB, companyOverviewGNB, hyundaiExperienceGNB];
    var snbs = [showroomSNB, companyOverviewSNB, hyundaiExperienceSNB];
    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 = 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);
    }
    */

    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;
        }
    }
}

function controlSearch(){
    var searchInput = document.getElementById('article-search').getElementsByTagName('input')[0];

    searchInput.onclick = function(){
        searchInput.style.backgroundImage = 'none';
    }
}

function controlMicrosite() {
	var chk = 0;
	var icon = document.getElementById('menuDock').getElementsByTagName('a')[1];
	var close = document.getElementById('close-microsite');
	var layer = document.getElementById('microsite');
	var list = document.getElementById('microsite').getElementsByTagName('ul')[0].getElementsByTagName('li');
	var paging = document.getElementById('microsite').getElementsByTagName('ul')[1].getElementsByTagName('li');;

	icon.onclick = function(){
		layer.style.display = 'block';
	}
	close.onclick = function(){
		layer.style.display = 'none';
	}

	for(var i=0;i<list.length;i++){
		list[i].onmouseover = function(){
			this.getElementsByTagName('p')[0].style.color = '#0f5699';

			this.onmouseout = function(){
				this.getElementsByTagName('p')[0].style.color = '#333';
			}
		}
		//list[i].onclick = function(){
		//	location.href = this.getElementsByTagName('a')[0].href;
		//}
	}

	for(var i=0;i<paging.length;i++){
		paging[i].onclick = function(){
			var thumbs = this.parentNode.getElementsByTagName("li");

			for(var i=0;i<list.length;i++){
				list[i].style.display = 'block';
			}

			for(var i=0;i<thumbs.length;i++){
				list[i].style.display = 'block';

				if (this == thumbs[i]) {
					for(var j=0;j<i*3;j++){
						list[j].style.display = 'none';
					}
				}
			}

			//for(var j=0;j<paging.length;j++){
			//	paging[j].getElementsByTagName('img')[0].src = paging[j].getElementsByTagName('img')[0].src.replace("-on.gif",".gif");
			//}

			//this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace(".gif","-on.gif");
		}
	}
}

function linkFooter(){
	document.getElementById('rss').getElementsByTagName('a')[0].onclick = function(){
		var url = this.href;
		popup_bookmark1(url);
		return false;
	}
	document.getElementById('bookmark').getElementsByTagName('a')[0].onclick = function(){
		var url = this.href;
		popup_bookmark1(url);
		return false;
	}
	document.getElementById('addTo').getElementsByTagName('a')[0].onclick = function(){
		var url = this.href;
		popup_bookmark1(url);
		return false;
	}
}

/*flash menudock*/
function facebookControl( type ){ // facebook?´ë¦­?ˆì„???¸ì¶œ, ?Œë¼ë¯¸í„° ê°’ìœ¼ë¡?open, close ?„ë‹¬
	var e = document.getElementById('facebook');
	
	if(type=='open'){
		e.style.display = 'block';
	} else if(type=='close'){
		e.style.display = 'none';
	}
}


function callExternalInterface() {  //  microSite?ì„œ ?«ê¸° ë²„íŠ¼???Œë??„ì‹œ ?Œëž˜???´ë? ?¨ìˆ˜ ?¸ì¶œ
	thisMovie("main_epr").microSiteClose();
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}
/*//flash menudock*/



function chageMicroSite(e)
{
    try
    {
        if(e == 1)
        {
            document.getElementById("MicroSiteListUl1").style.display = "block";
            document.getElementById("MicroSiteListImg1").src = "/Images/Web/main/new/btn-paging-microsite-on.gif";
            document.getElementById("MicroSiteListUl2").style.display = "none";
            document.getElementById("MicroSiteListImg2").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            document.getElementById("MicroSiteListUl3").style.display = "none";
            document.getElementById("MicroSiteListImg3").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            
        }
        else if(e == 2)
        {
            document.getElementById("MicroSiteListUl1").style.display = "none";
            document.getElementById("MicroSiteListImg1").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            document.getElementById("MicroSiteListUl2").style.display = "block";
            document.getElementById("MicroSiteListImg2").src = "/Images/Web/main/new/btn-paging-microsite-on.gif";
            document.getElementById("MicroSiteListUl3").style.display = "none";
            document.getElementById("MicroSiteListImg3").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            
        }
        else
        {
            document.getElementById("MicroSiteListUl1").style.display = "none";
            document.getElementById("MicroSiteListImg1").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            document.getElementById("MicroSiteListUl2").style.display = "none";
            document.getElementById("MicroSiteListImg2").src = "/Images/Web/main/new/btn-paging-microsite.gif";
            document.getElementById("MicroSiteListUl3").style.display = "block";            
            document.getElementById("MicroSiteListImg3").src = "/Images/Web/main/new/btn-paging-microsite-on.gif";
        }
    }
    catch(x)
    {
    }
}

//InYourCountry
function OpenCountry( url ){
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac','InYourCountry');dcsOffsite(url)
    //document.location.href = url;
	window.open(url, '_blank');
	//alert( url ) // select country ?ì„œ êµ?? ? íƒ???¸ì¶œ?˜ëŠ” ?ë°”?¤í¬ë¦½íŠ¸ ?¨ìˆ˜, xml?ì„œ ì¡°ì ˆê°€??
}


function microSiteOpen( id ){  // microSite?¬ì´???´ë¦´?? xml?ì„œ ?ë°”?¤í¬ë¦½íŠ¸ ?¨ìˆ˜ ë°??„ë‹¬?˜ëŠ” ?Œë¼ë¯¸í„°ê°??˜ì • ?????‡ìŠµ?ˆë‹¤. 
	//alert( id )
}

//MAIN VISUAL
function visual(url, title)
{
    alert(url + "," + title);
}

//MICRO SITE
function microsite(url, title, type)
{
    //alert("microsite:" + url + "," + title + "," + type);
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac',title);dcsOffsite(url);
    if(type == '0')
        window.open(decodeURIComponent(url), "_blank");
    else
        document.location.href = decodeURIComponent(url);
    
}

//BANNER
function banner(url, title, target)
{
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac',title);dcsOffsite(url);
        
	if(target == '0')
	    document.location.href = decodeURIComponent(url);
	else if(target == '1')
	    window.open(decodeURIComponent(url), "_blank");
	else    
	{
	    alert('Ã¢ ¼Ó¼ºÀÌ µî·Ï µÇ¾î ÀÖÁö ¾Ê½À´Ï´Ù.');
	    return;		
	}
}

//PRESS RELEASE
function pressRelease(url, title)
{
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac','PressRelease');dcsOffsite(url);
//    document.location.href = decodeURIComponent(url);
    window.open(decodeURIComponent(url), "_blank");
}

//YouTobe
function YouTobe_url(url)
{
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac','Youtube');dcsOffsite(url);
    window.open(decodeURIComponent(url), "_blank");    
}

function f_url(url, title)
{
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac','Facebook');dcsOffsite(url);
    facebook.Open(url, title);
}

function t_url(url, title)
{
    dcsMultiTrack('DCS.dcssip','worldwide.hyundai.com','DCS.dcsuri','/banner.aspx','WT.ac','Youtube');dcsOffsite(url);
    twitter.Open(url, title);
}


var facebook = {
    SetActionUrl: 'http://facebook.com/sharer.php',

    popupSize: {
        w: 800,
        h: 600
    },

    Open: function(URL, AddTitle) {
        var popupWidth = this.popupSize.w, popupHeight = this.popupSize.h;

        window.open(this.SetActionUrl + '?u=' + encodeURIComponent(URL) + '&t=' + encodeURIComponent(AddTitle)
                                    , 'Facebook', 'width=' + popupWidth + ', height=' + popupHeight
                                      + ',resizable=yes,scrollbars=yes');
    }

};  


var twitter = {

    SetActionUrl: 'http://twitter.com/share',

    popupSize: {
        w: 800,
        h: 600
    },

    Open: function(URL, AddText) {
        var popupWidth = this.popupSize.w, popupHeight = this.popupSize.h;
        
        window.open(this.SetActionUrl + '?url=' + encodeURIComponent(URL) + '&text=' + encodeURIComponent(AddText)
                                      , 'Twitter', 'width=' + popupWidth + ', height=' + popupHeight
                                      + ',resizable=yes,scrollbars=yes');
    }
}



