/**************************
   HOMEPAGE
**************************/

window.onload = function() {
   home = $('home');
   if(home) {
        banner();
    }
    menu();
    checkCookie();
};

function newsVideo(id) {
    $('splash').hide();
    if(id == 1) {
        $('parentVideo2').hide();
        $('parentVideo3').hide();
        $('thumbVideo1').hide();
        $('thumbVideo2').show();
        $('thumbVideo3').show();
        $('parentVideo'+id).show();
    }

    if(id == 2) {
        $('parentVideo1').hide();
        $('parentVideo3').hide();
        $('thumbVideo2').hide();
        $('thumbVideo1').show();
        $('thumbVideo3').show();
        $('parentVideo'+id).show();
    }

    if(id == 3) {
        $('parentVideo1').hide();
        $('parentVideo2').hide();
        $('thumbVideo1').show();
        $('thumbVideo2').setStyle({marginRight:'0px'});
        $('thumbVideo2').show();
        $('thumbVideo3').hide();
        $('parentVideo'+id).show();
    }
}

var i = 0;
function news() {
    if(i == 3) {
        i = 0;
    } else {
        i++;
    }
    setTimeout(function(){ listNews(i); }, 2000);
}

function listNews(j) {
if(j == 0) {
    $('news'+j).appear();
    $('news1').hide();
    $('news2').hide();
    $('news3').hide();
}

if(j == 1) {
    $('news'+j).appear();
    $('news2').hide();
    $('news3').hide();
    $('news0').hide();
}

if(j == 2) {
    $('news'+j).appear();
    $('news0').hide();
    $('news1').hide();
    $('news3').hide();
}

if(j == 3) {
    $('news'+j).appear();
    $('news0').hide();
    $('news1').hide();
    $('news2').hide();
}

setTimeout("news()",5000);
}//end function



var setLM = 0;
var setOLM = 0;
function hideSubLeftMenu(id) {
    for(i = 1;i<10; i++) {
        $('child'+id).hide();
    }
}

function leftMenu(idChilds) {
    if(setLM) {
        clearTimeout(setLM);
    }

    //$('child'+idChilds).show();
    Effect.SlideDown('child'+idChilds);
    Event.observe('child'+idChilds, 'mouseover', function(event) {
        if(setLM) {
            clearTimeout(setLM);
        }
        $('child'+idChilds).show();
    });

    Event.observe('child'+idChilds, 'mouseout', function(event) {
        //setOLM = setTimeout("$('child"+idChilds+"').hide();", 1000);
        //$('child'+idChilds).hide();
        Effect.SlideUp('child'+idChilds);
    });
}

function leftMenuOut(idChilds) {
      setLM = Effect.SlideUp('child'+idChilds);
}

function menu() {
    var setSo = 0;
    var setSe = 0;
    var setPr = 0;
    var setNe = 0;
    var setAb = 0;
    var setPart = 0;

    //SERVICES
    Event.observe('menu2', 'mouseover', function(event) {
         $('sub2').show();
            if(setSe)
                    clearTimeout(setSe);
    });

    Event.observe('menu2', 'mouseout', function(event) {
             setSe = setTimeout("$('sub2').hide()", 100);
    });


    Event.observe('sub2', 'mouseover', function(event) {
            $('sub2').show();
    });


    Event.observe('sub2', 'mouseout', function(event) {
            $('sub2').hide();
    });

    //NEWS
    Event.observe('menu27', 'mouseover', function(event) {
            $('sub27').show();
            if(setNe)
                    clearTimeout(setNe);
    });

    Event.observe('menu27', 'mouseout', function(event) {
            setNe = setTimeout("$('sub27').hide()", 100);
    });


    Event.observe('sub27', 'mouseover', function(event) {
            $('sub29').show();
    });

    Event.observe('sub27', 'mouseout', function(event) {
            $('sub27').hide();
    });


    //ABOUT

    Event.observe('menu30', 'mouseover', function(event) {
            $('sub30').show();
            if(setAb)
                    clearTimeout(setAb);
    });


    Event.observe('menu30', 'mouseout', function(event) {
     setAb = setTimeout("$('sub30').hide()", 100);
    });

    Event.observe('sub30', 'mouseover', function(event) {
            $('sub30').show();
    });


    Event.observe('sub30', 'mouseout', function(event) {
            $('sub30').hide();
    });

    //PARTNERS
    Event.observe('menu23', 'mouseover', function(event) {
            $('sub23').show();
            if(setPart)
                    clearTimeout(setPart);
    });

    Event.observe('menu23', 'mouseout', function(event) {
            setPart = setTimeout("$('sub23').hide()", 100);
    });


    Event.observe('sub23', 'mouseover', function(event) {
            $('sub23').show();
    });


    Event.observe('sub23', 'mouseout', function(event) {
            $('sub23').hide();
    });


} //end function menu


//page how it works
function itemsShow(id){
    
    ///mil = $('milestones').descenda
for(i = 1; i< 5; i++) {
    $('item'+i).hide();
}

$('item'+id).appear();

var mil = $('milestones').childElements();
for(i=0; i< mil.length; i++) {
var aclass = mil[i].hasClassName('active');
if(aclass) {
    mil[i].removeClassName('active');
}
}

   mil[id-1].addClassName('active');

}


function hideBanners() {
	for(i = 1; i<5; i++){
       		$('pic'+i).hide();
	 }
}

var rotate = 0;
var t = 0;
var idBannerActiv = 0;



function rotateBanner(id) {
    var k = 1;
    hideBanners();
    if(k >= 1 || k <= 4) {

        if(id)
            k = id;
	$('pic'+k).show();
	k ++;
	if(k > 4)
		k = 1;
	rotate = setTimeout('rotateBanner('+k+')', 10000);
    }
}



function banner() {
    rotateBanner(1);

    Event.observe('banner1', 'click', function(event) {
        clearTimeout(rotate);
        rotateBanner(1);
    });


//DOI
    Event.observe('banner2', 'click', function(event) {
        clearTimeout(rotate);
        rotateBanner(2);
    });



//TREI
    Event.observe('banner3', 'click', function(event) {
        clearTimeout(rotate);
        rotateBanner(3);
    });


//PATRU
    Event.observe('banner4', 'click', function(event) {
        clearTimeout(rotate);
        rotateBanner(4);
    });

}//end function


//COOKIE BANDA OMNIVSERV
var banda = 0;
function getCookie(c_name) {
    if (document.cookie.length>0) {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1) {
            c_start=c_start + c_name.length+1 ;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function setCookie(c_name,value,expire) {
    var exdate=new Date();
    exdate.setHours(exdate.getHours()+3);
    document.cookie=c_name+ "=" +escape(value)+((expire==null) ? "" : "; expires="+exdate.toUTCString());
}


function checkCookie() {
    banda=getCookie('banda');
    if (banda!=null && banda!="") {
        $('banda').morph('height:10px');
        $('right_banda').removeClassName('bgwhite');
        $('right_banda').addClassName('bgred');
       $('pointW').hide();
       $('pointR').show();
    } else {
        $('banda').show();
    }
}

//BANDA FOOTER OMNIVSERV
omnvs = 0;
setB = 0;
function footerBanda() {
    Event.observe('close', 'click', function(event) {
          $('banda').morph('height:10px;');
          omnvs = 1;
          $('right_banda').removeClassName('bgwhite');
          $('right_banda').addClassName('bgred');

         setCookie('banda', 'inactive', 1);
    });

    Event.observe('banda', 'mouseover', function(event) {
        var h = $('banda').getHeight();
        if(h == 45) {
           $('right_banda').removeClassName('bgwhite');
           $('right_banda').addClassName('bgred');
           $('pointW').hide();
           $('pointR').show();
        }
        if(h == 10) {
            $('banda').morph('height:45px');
        }
        clearTimeout(setB);
    });

    Event.observe('banda', 'mouseout', function(event) {
        var h = $('banda').getHeight();
        if(omnvs == 0 && h == 45) {
            $('right_banda').removeClassName('bgred');
            $('right_banda').addClassName('bgwhite');
            $('pointR').hide();
            $('pointW').show();

            if(banda) {
               setB = setTimeout("$('banda').morph('height:10px');", 5000);
               $('right_banda').removeClassName('bgwhite');
               $('right_banda').addClassName('bgred');
               $('pointW').hide();
               $('pointR').show();
            }
        }
    });

    if(omnvs) {
        var h = $('banda').getHeight();
        if(h == 10) {
            $('banda').morph('height:45px');
            $('right_banda').removeClassName('bgwhite');
            $('right_banda').addClassName('bgred');
        } else {
            h = $('banda').getHeight();
            if(h == 45) {
                omnvs = 0;
            }
        }
    }
}