 $(".portfolioImages img").lazyload({
     effect      : "fadeIn", skip_invisible : false, threshold :1200
 });



/* Skills scroller  */
 
var menuSlider=function(){
	var m,e,g,s,q,i; e=[]; q=8; i=8;
	return{
		init:function(j,k){
			m=document.getElementById(j); e=m.getElementsByTagName('li');
			var i,l,w,p; i=0; l=e.length;
			for(i;i<l;i++){
				var c,v; c=e[i]; v=c.value; if(v==1){s=c; w=c.offsetWidth; p=c.offsetLeft}
				c.onmouseover=function(){menuSlider.mo(this)}; c.onmouseout=function(){menuSlider.mo(s)};
			}
			g=document.getElementById(k); g.style.width=w+'px'; g.style.left=p+'px';
		},
		mo:function(d){
		    $("#slide").css({'visibility':'visible'});
			clearInterval(m.tm);
			var el,ew; el=parseInt(d.offsetLeft); ew=parseInt(d.offsetWidth);
			m.tm=setInterval(function(){menuSlider.mv(el,ew)},i);
		},
		mv:function(el,ew){
			var l,w; l=parseInt(g.offsetLeft); w=parseInt(g.offsetWidth);
			if(l!=el||w!=ew){
				if(l!=el){var ld,lr,li; ld=(l>el)?-1:1; lr=Math.abs(el-l); li=(lr<q)?ld*lr:ld*q; g.style.left=(l+li)+'px'}
				if(w!=ew){var wd,wr,wi; wd=(w>ew)?-1:1; wr=Math.abs(ew-w); wi=(wr<q)?wd*wr:wd*q; g.style.width=(w+wi)+'px'}
			}else{clearInterval(m.tm)}
}};}();

function scrollSkills() {

if ($('.menu').length != 0) {
menuSlider.init('menu','slide'); 
}
var lastSkill = $("#sibSkills article").length;

  $('#sibSkills .skillActive').fadeIn(500).delay(110000).fadeOut(300, function() {
        $('#sibSkills article').removeClass('skillActive');
        $('.menu li').removeClass('active').attr('value', '2' ) ; ;
         
      if (($(this).index()+1) === lastSkill){
      $("#sibSkills article").first().addClass('skillActive');
      $('#menu>:nth-child(1)').addClass('active').attr('value', '1' );
      
      } else {
     
      $(this).next().addClass('skillActive'); 
      $('#menu>:nth-child('+($(this).index()+2)+')').addClass('active').attr('value', '1' );
      
      }
      
      scrollSkills(); //loop 
	});
  
  
/*  $(".menu li:not(.active)").click(function(event){   */
 $(".menu li:not(.active)").live('click', function(e) {
 e.preventDefault();
        $("#sibSkills article").stop(true, true);
        $(".menu li").removeClass('active').attr('value', '2' ) ;
		$(this).addClass('active').attr('value', '1' );
		$('#sibSkills article').fadeOut(200); 
		$('#sibSkills>:nth-child('+($(this).index()+1)+')').delay(200).fadeIn();
        menuSlider.init('menu','slide'); 
	});
	  
  
}
 
/* Portfolio galleries */

$('.projectText img').click(function() {
var parentArticle = $(this).parents('article'); 
$(parentArticle).find('.portfolioImages img').removeClass('out');
$(parentArticle).find('.portfolioImages .active').addClass('out');
$(parentArticle).find('.portfolioImages .' + $(this).attr("title")).addClass('next');
$(parentArticle).find('.portfolioImages .next').fadeIn(500).addClass('active').removeClass('next');
$(parentArticle).find('.portfolioImages .out').removeClass('active').hide();

$('.projectText img').removeClass('activeThumb');
$(this).addClass('activeThumb');

});
 
 
/*  Site rollovers  */

jQuery(function( $ ){
    $(".rollOver").css({'visibility':'visible'});
    $(".rollOver").css({'opacity':'0'});
    
    
$('#triptych > div').hover(
		function() {
			$(this).find('.rollOver').stop().fadeTo(500, .8);
		},
		function() {
			$(this).find('.rollOver').stop().fadeTo(500, 0);
		}
	)

});

/* portfolio form */

 $('#morePortfolio .pinkButton').click(function(f) { 
f.preventDefault();
$('#morePortfolio form').slideToggle('slow'); { 
         $('#morePortfolio .pinkButton').fadeOut(); 
        };   
   });
  

/* contact form */

/* slider */

 

 $('.slideForm').click(function() { 

$('#extended_form').slideToggle('slow', function() { 
     if ($('#extended_form:visible').length > 0){
         $('.slideForm').html('<span>or</span> Tell me less...');
    }else{
         $('.slideForm').html('<span>or</span> Tell me more...');
        };   
  });
   
  });
  
  
/* form validation */

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
};

function validate(formData, jqForm, options) { 
    var form = jqForm[0];  
    $('.formError').removeClass('formError');
    if (!form.name.value) { 
        $('#name').addClass('formError');
        $('label[for=name] span').show();
    } 
    if (!form.message.value) {  
     $('label[for=message] span').show();
        $('#message').addClass('formError'); 
    } 
    
    if( !isValidEmailAddress(form.email.value) ) {
    $('label[for=email] span').show();
    $('#email').addClass('formError');  
        }
        
     if (!form.name.value || !form.message.value || !isValidEmailAddress(form.email.value)) {  
     
       if (form.scroll.value == 'true'){
       $( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
       };
        return false; 
    } 
}


/* Get url query string */
function getUrlVars() {
	var vars = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		vars[key] = value;
	});
	return vars;
}


/* Social media share bubbles */

/* Un-comment commented markup
 * Version: 1.0
 * Date: 2010-01-28
 * Author: Romuald Brunet <romuald@chivil.com>
 */
(function($) {
	$.fn.uncomment = function(recurse) {
		$(this).contents().each(function() {
			if ( recurse && this.hasChildNodes() ) {
				$(this).uncomment(recurse);
			} else if ( this.nodeType == 8 ) { 
				var e = $('<span>' + this.nodeValue + '</span>');
				$(this).replaceWith(e.contents());
			}
		});
	};
})(jQuery);
 
 
 $('.shareLink').click(function(e) {
 e.preventDefault(); 
 $(this).parent().find('.shareCounters').uncomment(true);
 $(this).parent().find('.shareCounters').fadeToggle(); 
  });
  



 /* HTML 5 video links */
 jQuery(function( $ ){
    $("#preload_play").css({'visibility':'visible'});
    $("#preload_play").css({'opacity':'0'});
    
    
$('#mainGraphic').hover(
		function() {
			$('#preload_play').css( 'cursor', 'pointer' ).stop().fadeTo(500, .8);
		},
		function() {
			$('#preload_play').css( 'cursor', 'default' ).stop().fadeTo(500, 0);
		}
	)

});












$(document).ready(function() { 


var pageState = getUrlVars()["state"]; 

 
if (pageState != 'extended'){
 $('.slideForm').show();
} else {
$('#extended_form').show();
};

/* HTML 5 video link */

$('#preload_play').click(function(a) {
 $(this).fadeOut(400, function(s) {
 $(this).remove();
 });
  $('#siblify_intro').css({'visibility':'visible'}).get(0).play(); 
 });


 //Bind ajaxForm to the FreeForm 
$('#freeform').ajaxForm({
   
  beforeSubmit:validate,
   success:function(rtn){
     $("#contactFormArea").slideUp(function() { 
            $("#thankyou").slideDown(); 
            } ); 
  }
  });
 
 
$('#morePortfolioForm').ajaxForm({
   beforeSubmit:validate,
   success:function(rtn){
     $("#morePortfolio form").slideUp(function() { 
            $("#thankyou").slideDown(); 
            } ); 
  }
  });

  

    
	$("a.fancyLink").fancybox({
		'overlayOpacity': .8, 'overlayColor': '#000', 'hideOnOverlayClick': 'false', 'hideOnContentClick': 'false'
		
	}); 
	
	 
    $('nav li a').each(function() {
        $(this).css('width', $(this).width());
    });
 
	
	scrollSkills();
});












