var topMenuTimeout = null

/* === INIT === */
$(function(){ 

    $('a.schedaTecnica').click(schedaOnClick)
    
    $('ul.thumbList > li > a ').click(schedaOnClick)
    
    $('ul.thumbList > li > a ').hover(
        function(){
            var aTag = $(this)
            thumbOnClick(aTag)            
            var imgTag = $('img',aTag.parent())            
            imgTag.stop(true,true)
            imgTag.animate({width:'102px',height:'123px',marginLeft:"-5px",marginTop:"-11px"})
        },
        function(){            
            var aTag = $(this)
            var imgTag = $('img',aTag.parent())                          
            imgTag.stop(true,true)
            imgTag.animate({width:'93px',height:'112px',marginLeft:"0px",marginTop:"0px"})
        })
        
    $('div#schedaTecnicaDialog p a.foto1').click(function(){        
        var id = $('#schedaTecnicaDialog').data('idf')
        loadDialogImg(id)
        $('div#schedaTecnicaDialog p a.foto2').removeClass('evidMenu')
        $(this).addClass('evidMenu')
        })
        
    $('div#schedaTecnicaDialog p a.foto2').click(function(){
        var id = $('#schedaTecnicaDialog').data('idf')
        loadDialogImg2(id)
        $('div#schedaTecnicaDialog p a.foto1').removeClass('evidMenu')
        $(this).addClass('evidMenu')
        })
        
    $('#menu-group-top-ul').hover(
        function(){ 
            clearTimeout(topMenuTimeout)
            topMenuTimeout = setTimeout(function(){slideMenuTop(true)},100) 
            },
        function(){
            clearTimeout(topMenuTimeout) 
            topMenuTimeout = setTimeout(function(){slideMenuTop(false)},500) 
            }
    )  
    
    
    /*$('#menu-group-ul li a').hover(
        function(){             
            //$(this).stop(true).animate({fontSize:'20px'}) 
            $(this).stop(true).css({backgroundColor:'#000',textShadow: '0 0 0.8em #F00, 0 0 0.8em #F00,0 0 0.8em #F00'})
        },
        function(){
            //$(this).stop(true).animate({fontSize:'11px'})            
            //$(this).stop(true).animate({backgroundColor:'#000'},2000).css({backgroundColor:'transparent',textShadow: '0 0 0'})
            $(this).stop(true).animate({backgroundColor:'#000',textShadow:'0 0 0.8em #000, 0 0 0.8em #000,0 0 0.8em #000'},2000).css({backgroundColor:'transparent',textShadow: '0 0 0'})
        }
    ) */  
    
    /* === fisheye === */
    $('#menu-group-ul li a').hover(
        function(){             
            $(this).stop(true).animate({fontSize:'18px'})
        },
        function(){
            $(this).stop(true).animate({fontSize:'11px'})            
        }
    )   
    /* ====== */
    
        
})  


function slideMenuTop(open){ 
    var ulTag =  $('#menu-group-top-ul')
    var pos = '-122px'
    if(open) pos = '0px'
    ulTag.stop(true,false)
    ulTag.animate({top:pos})     
}

function thumbOnClick(aTag){
    //var aTag = $(this)    
    var imgTag = $('img',aTag.parent())
    var id = imgTag.attr('alt')    
    $('#schedaTecnicaDialog').data('idf',id)
    $('#schedaTecnicaDialog').dialog( "option", "title", aTag.attr('title') )    
    loadDialogImg(id)         
}


function loadDialogImg(id){    
    var cacheImage = document.createElement('img')
    cacheImage.src = 'upload/gallery/scheda_tecnica/'+id+'_'+pvLang+'.jpg'    
    if(cacheImage.complete) imgLoaded(id,cacheImage)
    else    
    $(cacheImage).load(function(){imgLoaded(id,cacheImage)})
}

function loadDialogImg2(id){
    var cacheImage = document.createElement('img')
    cacheImage.src = 'upload/gallery/scheda_tecnica/'+id+'_int.jpg'    
    if(cacheImage.complete) imgLoaded(id,cacheImage)
    else    
    $(cacheImage).load(function(){imgLoaded(id,cacheImage)})
}

function imgLoaded(id,cacheImage){
        var schedaTecnicaTag = $('a.schedaTecnica')
        var schedaTecnicaImageTag = $('#schedaTecnicaDialog > img')
        schedaTecnicaTag.css('background-image',"url('upload/gallery/standard/"+id+".jpg')")
        schedaTecnicaImageTag.attr('src',cacheImage.src)
}

   
function schedaOnClick(){ 
    $('div#schedaTecnicaDialog p a.foto1').addClass('evidMenu')     
    $('div#schedaTecnicaDialog p a.foto2').removeClass('evidMenu')    
    jqDialogschedaTecnicaDialog()
}


