// JavaScript Document

$(document).ready(function()
{
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
		$("#close").show();
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
		$("#close").hide();
	});	
	
	$('#navigationDropdown').hover(function(){$(this).addClass('hov');},function(){$(this).removeClass('hov');});
	$('#nav_link_2').parent().hoverIntent(function(){$('#navigationDropdown').addClass('nav');},function(){$('#navigationDropdown').removeClass('nav');});
	
	$('div.portfolioTabs a').each(function(_i)
	{
	  var _row = (_i % 3);
      $(this).click(function()
      {
		 
         var _div = $(this).closest('div.portfolioEntry');
		 var _links = $('div.portfolioTabs a',_div);
		 
         $('div.portfolioTabs a',_div).each(function(_i2)
         {
           $(this).removeClass('on');
         });
		 
         $(this).addClass('on');

		var _href = $(this).attr('href');
		
       $('div.portfolioImage img',_div).each(function()
       {
          var _this = $(this);
          var _parent = _this.parent();

         if (_parent.css('background-image').search(_href) <= 0)
	     {
    	  	$('span.preloader',_div).show();
           var _img = new Image();

           $(_img).load(function()
           {
	       	$('span.preloader',_div).hide();
             _parent.css('background-image', 'url(' + this.src + ')')
            .css('background-repeat', 'no-repeat')
            .end()
            .animate({marginLeft: '-600px'}, 550, 'swing', function() {
            this.src = _href;
            $(this).css('marginLeft', '0');
            });
          })

            .attr('src', _href);
          }
      });

		return false;
      });
	});
	
	$('div.iconScrolldown a').click(function() 
	{
		var _href = $(this).attr('href');
		var _dest = $('a[name='+_href.substr(1)+']').offset().top;
	   	$('html:not(:animated),body:not(:animated)').animate({ scrollTop: _dest-20},800);
	   	return false;
	}); 
	
	$("a[rel^='contact']").prettyPopin({
		modal: false, /* true/false */
		width: 500, /* true/false */
		height: false, /* true/false */
		opacity: 0.1, /* value from 0 to 1 */
		animationSpeed: 'fast', /* slow/medium/fast */
		followScroll: true, /* true/false */
		loader_path: '/images/preloader-white.gif', /* path to your loading image */
		callback: function(){} /* callback called when closing the popin */
	});
	
});