$(document).ready(function(){
  $('#header').find('ul.submenu').hide();
  
  $('#header .menu li').hover(function(){
    $(this).addClass('hover');
    $(this).find('a').first().addClass('hover');
    $(this).find('ul.submenu').first().show(0,function(){
      $(this).find('ul.submenu').show().hide();
    });
  },function(){
    $(this).removeClass('hover');
    $(this).find('a').first().removeClass('hover');
    $(this).find('ul.submenu').hide(0);
  });
  
  $('#search-lang select').change(function(){
    if ($(this).val()) document.location = $(this).val(); 
  });

});

var coverflipPause = false;

function coverflip_rotate()
{
  if (!coverflipPause)
  {
  	$('#flip').jcoverflip('next', 1);
	}	
	setTimeout("coverflip_rotate()", 3000);
}

function init_coverflip()
{
  $('#flip').jcoverflip({
    current: 2,
    time: 500,
    beforeCss: function( el, container, offset ){
                if (offset==0)
              		return [
              			//$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 70 - 40*offset )+'px', bottom: '7px' }, { } ),
              			$.jcoverflip.animationElement( el, { width: '55px', top: '7px' }, { } ),
              			$.jcoverflip.animationElement( el.find( 'img' ), { width: '45px' }, {} )
              		];
              	else 
              		return [
              			//$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 70 - 40*offset )+'px', bottom: '15px' }, { } ),
              			$.jcoverflip.animationElement( el, { width: '35px', top: '15px' }, { } ),
            			  $.jcoverflip.animationElement( el.find( 'img' ), { width: '30px' }, {} )
              		];
            		  
            			 
  	},
  	afterCss: function( el, container, offset ){

            		
            		if (offset==0)
              		return [
              			//$.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 55 + 40*offset )+'px', bottom: '7px' }, { } ),
              			$.jcoverflip.animationElement( el, { width: '50px', top: '7px' }, { } ),
              			$.jcoverflip.animationElement( el.find( 'img' ), {  width: '45px' }, {} )
              		];
              	else
              		return [
              			//$.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 70 + 40*offset )+'px', bottom: '15px' }, { } ),
              			$.jcoverflip.animationElement( el, { width: '35px', top: '15px' }, { } ),
            			  $.jcoverflip.animationElement( el.find( 'img' ), { width: '30px' }, {} )
              		];

  	},
  	currentCss: function( el, container ){
            		return [
            			//$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 15 )+'px', bottom: 0 }, { } ),
            			$.jcoverflip.animationElement( el, { width: '70px', top: '0px' }, { } ),
            			$.jcoverflip.animationElement( el.find( 'img' ), { width: '60px' }, { } )
            		];
  	},
  	titleAnimateIn: function( titleElement, time, offset ){
  	 titleElement.css({opacity: 0, display: 'block'});
	 }
  });
  
  $("#flip").mouseover(function(){
		coverflipPause = true;
		$('#flip').jcoverflip('option', 'time', 500);
	});
	
	$("#flip").mouseout(function(){
	 coverflipPause = false;
	 $('#flip').jcoverflip('option', 'time', 500);
	});
	
	setTimeout("coverflip_rotate()", 3000);
}

