/**
*       Javascript code on "jquery framework "
*       @developer: Valerio Zarba
*       @agenzy: Studio Riva S.N.C.;
*        
*        
*        
*/

var timer=0;
var move=0;
var c=0;
var IE = document.all?true:false
$.easing.elasout = function(x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
        if (a < Math.abs(c)) {a=c;var s=p/4;}
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
    
//show modal login
function login(){
    $("#modal-login").modal();    
}

function loginclose(){
    $.modal.close();
}



/**
    Aggornamento delle icone di stato nei menu
    
*/

$(window).ready(function(){
   
    $("#menu-grafica").mouseover(function(){
        //alert("Show");
        $("#submenu-grafica").show();
    });
    $("#menu-grafica").mouseout(function(){
        $("#submenu-grafica").hide();
    });
    //rezie area
    
    $(".workarea").width($(window).width());
    $(window).resize(function(){
         $('.workarea').width($(window).width());
    });    
    /**
    $nav_li=$("#layer-menu .colorize");
    $nav_li_a=$("#layer-menu .colorize a");
    var animSpeed=450; //fade speed
    var hoverTextColor="#fff"; //text color on mouse over
    var hoverBackgroundColor="#666"; //background color on mouse over
    
    var textColor=$nav_li_a.css("color");
    var backgroundColor=$nav_li.css("backgroundColor");
    //text color animation
    $nav_li_a.hover(function() {
        var $this=$(this);
        $this.stop().animate({ color: hoverTextColor }, animSpeed);
    },function(){
        var $this=$(this);
        $this.stop().animate({ color: textColor }, animSpeed);
        }
    );

    //background color animation
    $nav_li.hover(function() {
        var $this=$(this);
        $this.stop().animate({ backgroundColor: hoverBackgroundColor }, animSpeed);
    },function() {
        var $this=$(this);
        $this.stop().animate({ backgroundColor: backgroundColor}, animSpeed);
    });

    **/
    
    //load person interface
    $('.persona').click(function(ev){
                $.fancybox(
            		$(this).find(".infos").html()
            		,
            		{
                        'autoDimensions'	: false,
            			'width'             : 450,
            			'height'        	: 'auto',
            			'transitionIn'		: 'none',
            			'transitionOut'		: 'none'
            		}
            	);   
    });
    //contact-expand
    //start slider homepage
    if($("#slidehome")){
        var lista=$("#slidehome").find(".wsez");
        $(".wsez").width($(window).width());
        if(lista.length > 0 ){
            timer=setTimeout(loadSlider,5000,1);
        }   
    }
    $(document).mousemove(function(event){
        x=event.pageX;
        y=event.pageY;
    }); 
    
    //load fancybox per le immagini
    $("a.imageview").fancybox();
    
    
                   
});


/** goback for scrolling area**/
function goBack(){
    $('#listalavori').scrollTo(0,500);
    $('#mediaspace').remove();
}

/** Chiama Ajax per mostrare il lavoro**/
function showWork(id){
    
    /**
     
    var elem=$('#workdett');
    $('#listalavori').scrollTo(elem,500);
    //carico i dati del cliente via ajax
    $.get('index.php?loadWork='+id, function(data) {
      $('#workdett').html(data);
    });
    **/
}


function loadSlider(a){
     
     if($('#slidehome')){
                var lista=$("#slidehome .wsez")        
                var elem=$(".wsez:eq("+a+")");
                //alert(lista.length);
                if(lista.length==a){
                    move=0;
                    a=0;
                }else{
                    move+=$(".wsez").width();
                }
                var ll=$('#layer1').find("div");
                $(ll).scrollTo(move,2000,{easing:'elasout',axis:'x',queue:true, onAfterFirst:function(){
                        
                }});
                a++;
                timer=setTimeout(loadSlider,6000,a); 
     }
           
}

function showImage(a){
       var imm=$(a).attr("rel");
       $('#immagine_show').html("<a href='"+imm+"' class='imageview'><img src=\""+imm+"\"></a>");  
       $("a.imageview").fancybox();
}

function clearToolTip(){
    
 $(".tooltip").css('display','none');
 
 
}


function showToolTip(nome,a){
  	 
  	 
  	 if(IE){
  	     var mousey=window.event.clientY+10;
  	     var mousex=window.event.clientX+10;
  	 }else{
  	     var mousey=event.pageY+10;
  	     var mousex=event.pageX+10;
  	 }
  	 
  	 targ=a;
  	 //alert(IE);
  	 
     $("#"+nome).css({
      top: mousey
      , 
      left: mousex
      });
     
     $("#"+nome).fadeIn(1);
     
     $(targ).mousemove(function(e){
            if(IE){
          	     var mousey=window.event.clientY+10;
          	     var mousex=window.event.clientX+10;
          	 }else{
          	     var mousey=e.pageY+10;
          	     var mousex=e.pageX+10;
          	 }
            
            $("#"+nome).css({
              top: mousey
              , 
              left: mousex
             });
            
     });
     $(targ).mouseout(function(){
         clearToolTip();
     });
}





