
// Fade image loader
$(function () {
  $('.fadeload').hide();//hide all the images on the page
});

var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(function() {//The load event will only fire if the entire page or document is fully loaded
  var int = setInterval("doThis(i)",150);//500 is the fade in speed in milliseconds
});

function doThis() {
    var images = $('img.fadeload').length;//count the number of images on the page
    if (i >= images) {// Loop the images
      clearInterval(int);//When it reaches the last image the loop ends
    }
    $('img:hidden.fadeload').eq(0).fadeIn(40);//fades in the hidden images one by one
    i++;//add 1 to the count
}

// Smooth Scroll
$(function(){
 
    $('a[href*=#]').click(function() {
 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
 
            var $target = $(this.hash);
 
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
 
            if ($target.length) {
 
                var targetOffset = $target.offset().top;
 
                $('html,body').animate({scrollTop: targetOffset}, 600);
 
                return false;
 
            }
 
        }
 
    });
 
});



// Images fade animation
$(function(){
  $(".fadeload").hover(function(){
    $(this).stop().animate({opacity: "0.2"}, 350);
  },
  function(){
    $(this).stop().animate({opacity: "1"}, 125);
  });
});

// Go Top button animation
$(function(){
  $("#gotop a").hover(function(){
    $(this).stop().animate({top: "-20px" , height: "30px"}, {duration:125 , easing : "easeInCubic"});
  },
  function(){
    $(this).stop().animate({top: "-10px" , height: "20px"}, {duration:600 , easing : "easeOutBounce"});
  });
});


// Themifier animation
$(function(){
  $("#custom_theme").css("display","none");     
  $("#themifier").click(function(){
    $("#custom_theme").fadeToggle("fast", "linear");
    $(this).toggleClass("close_panel", 80);
  });
});

$(function(){
  $('.hidden').css("display", "none");
  $(".toggler a").click(function() {
    $(this).parent().children('.hidden').slideToggle("slow");
  });
});


$(function(){               
  $("#top_menu ul ul").css({display: "none"});
  $('#top_menu ul li').hover(function(){
    $('ul', this).slideDown(140);
  },
  function(){
    $('ul', this).slideUp(125);
  });
});

// Flickr fade animation
$(function(){
  $(".flickr_gallery img").hover(function(){
    $(this).stop().animate({opacity: "0.5"});
  },function(){
    $(this).stop().animate({opacity: "1"});
  });
});

// Portfolio Grid
$(function(){
  $(".grid .infos").css("opacity","0");
  $(".grid li").hover(function(){
    $(this).find(".infos").stop().animate({opacity: "1", top: "0px"});
    $(this).find(".thumbnail_item").stop().animate({opacity: "0.5"}, 350);
  },function(){
    $(this).find(".infos").stop().animate({opacity: "0", top: "265px"});
    $(this).find(".thumbnail_item").stop().animate({opacity: "1"}, 350);
  });
  
});

// Portfolio LIST
$(function(){
  $(".list .zoom").css("opacity","0");
  $(".list .zoom").hover(function(){
    $(this).stop().animate({opacity: "1"});
  },function(){
    $(this).stop().animate({opacity: "0"});
  });
  
});

// Captcha system
$(function(){
$("#errorcaptcha").css({opacity: "0"});
$("#check").keyup(function () {
    var rep = $(this).val();
    var n1 = document.getElementById('num1').innerHTML;
    var n2 = document.getElementById('num2').innerHTML;
    var n3 = parseInt(n1) + parseInt(n2);
          if( n3 == rep ){
      $("#submitter").prepend('<input type="submit" name="contact_submit" id="contact_submit" value="Send Now" />').animate({opacity: "1"},{duration:350});
      $("#errorcaptcha").text(" ").animate({opacity: "0"},{duration:150});
    }
    else {
      $("#errorcaptcha").text("Not good!").animate({opacity: "1"},{duration:350});
      $("#submitter").prepend('').animate({opacity: "0"},{duration:150}).empty();
    }
    });
});

$(function() {  
    $("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square'}); 
});


// GALLERY SLIDESHOW


// GALLERY FILTER

$(function(){

  $("#the_gallery a").css("opacity","0.8");
  
  
  $(".filter .all").click(function(){
    
    // Reinitialization of all elements
    $("#the_gallery li").stop().animate({opacity: '0.7'});
    $("#the_gallery li").find("a").css("top","0px");
    
    
  });
  
  if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
    
    $(".filter a").click(function(){
    
    $(".filter a").removeClass("current");
    $(this).addClass("current");

    // Get the title attribut
    thisItem = $(this).attr('rel');
    
      if(thisItem == "all") {
          
          // Opacity 0.3 on all elements
          $("#the_gallery li").stop().animate({width: '160px'});
          $("#the_gallery li").find("a").css("top","0px");
          
          // Opacity 1 on all elements with li parent has attribut of the filter in class
          $('#the_gallery li.'+thisItem).stop().animate({width: '160px'});
          $('#the_gallery li.'+thisItem).find("a").css("top","0px");
          
          } else {
    
          // Opacity 0.3 on all elements
          $("#the_gallery li").stop().animate({width: '0px'});
          $("#the_gallery li").find("a").css("top","160px");
          
          // Opacity 1 on all elements with li parent has attribut of the filter in class
          $('#the_gallery li.'+thisItem).stop().animate({width: '160px'});
          $('#the_gallery li.'+thisItem).find("a").css("top","0px");
      }
    
    
  });
    
  } else {
  
  $(".filter a").click(function(){
    
    $(".filter a").removeClass("current");
    $(this).addClass("current");

    // Get the title attribut
    thisItem = $(this).attr('rel');
    
      if(thisItem == "all") {
          
          // Opacity 0.3 on all elements
          $("#the_gallery li").stop().animate({opacity: '1'});
          $("#the_gallery li").find("a").css("top","0px" , "visibility","visible");
          
          // Opacity 1 on all elements with li parent has attribut of the filter in class
          $('#the_gallery li.'+thisItem).stop().animate({opacity: '1'});
          $('#the_gallery li.'+thisItem).find("a").css("top","0px" , "visibility","visible");
          
          } else {
    
          // Opacity 0.3 on all elements
          $("#the_gallery li").stop().animate({opacity: '0.3'});
          $("#the_gallery li").find("a").css("top","160px");
          
          // Opacity 1 on all elements with li parent has attribut of the filter in class
          $('#the_gallery li.'+thisItem).stop().animate({opacity: '1'});
          $('#the_gallery li.'+thisItem).find("a").css("top","0px");
      }
    
    
  });
  }
  
  
  
    $("#the_gallery li").hover(function(){
        $(this).find("a").stop().animate({opacity: '0.9'});
        $(this).find("div.tooltip").css({opacity: '0'}).show();
        $(this).find("div.tooltip").stop().animate({opacity: '1'}, 500);
    },function(){
        $(this).find("a").stop().animate({opacity: '0.8'});
        $(this).find("div.tooltip").stop().animate({opacity: '0'}, 500);
    });

});

// PORTFOLIO
$(function() {  
    $(".item_infos").css("right","-340px");
    
    $(".item_big").hover(function(){
        $(this).find(".item_infos").stop().animate({right: '0px'},{ duration:340, easing: 'easeOutCirc'});
    },function(){
        $(this).find(".item_infos").stop().animate({right: '-340px'},{ duration:300, easing: 'easeOutCirc'});
    });
});

$(function() {  
    $(".preview").hover(function(){
        $(this).find("a").stop().animate({opacity: '0.7'}).show();
    },function(){
        $(this).find("a").stop().animate({opacity: '0'}).show();
    });
});
