$(document).ready(function(){
	
//Scrol
$('#menu li a, #logo').click(function() {
	var elementClicked = $(this).attr("href");
	var destination = $(elementClicked).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-0}, 1000 );		   
	return false;
});	

//Portfolio Image
$("#realisation li").hover(function () {						 
	$(this).find("img").stop(true, true).animate({ opacity: 0.2 }, 500);
	$(this).find("a.p-link").stop(true, true).animate({ left: 0, bottom:0  }, 500);
	$(this).find("a.p-img, a.p-video").stop(true, true).animate({ right: 0, top:0  }, 700);
	$(this).find("p").stop(true, true).fadeIn(1000);
}, function() {
	$(this).find("img").stop(true, true).animate({ opacity: 1.0 }, 500);
	$(this).find("a.p-link").stop(true, true).animate({ left: '-62px', bottom: '-62px' }, 500);
	$(this).find("a.p-img, a.p-video").stop(true, true).animate({ right: '-62px', top:'-62px'  }, 700);
	$(this).find("p").stop(true, true).fadeOut(1000);
});


//Portfolio Filtred
$("a.active").parent("li").fadeIn(0);
$(".filter").hover(function () {						 
	$(this).find(".portfolio-cat li").fadeIn(300);
}, function() {
	$(this).find(".portfolio-cat li").fadeOut(300);
	$(this).find("a.active").parent("li").fadeIn(300);
});

//PORTFOLIO			  
Grid();
$('#selecter').mobilyselect({
			collection: 'all',
			animation: 'fade',
			duration: 750
});


//OPEN CONTATC PAGE 
$("a.open-page").live('click',function(){
   $("a.open-page").removeClass('open-page');
   $(this).addClass("close-page");
   $(".contact-page").animate({right:"30%", marginRight:"-247px"},800);	 
});

//CLOSE CONTACT PAGE
$("a.close-page").live('click',function(){
   $("a.close-page").removeClass('close-page');
   $(this).addClass("open-page");
   $(".contact-page").animate({right:"-495px", marginRight:"0"},800);	 
});


var current_nav = 'home';

scroll_function = function(){
	
	$(".scrol-page, .scrol-home, .scrol-contact").each(function(index) {
		var h = $(this).offset().top;
		var y = $(window).scrollTop();
					
		if(y + 360 >= h && y < h + $(this).height() && $(this).attr('id') != current_nav) {
			
			current_nav = $(this).attr('id');
			
			$('#menu a').removeClass('current');
			$('.nav_' + current_nav).addClass('current').show("fast");	
				
		}
	});	
}
$(window).scroll(function(){
		scroll_function();
});




function smartColumns() { 
  
    $("ul.blog-post").css({ 'width' : "100%"});

    var colWrap = $("ul.blog-post").width(); 
    var colNum = Math.floor(colWrap / 250);
    var colFixed = Math.floor(colWrap / colNum);

    $("ul.blog-post").css({ 'width' : colWrap});
    $("ul.blog-post li").css({ 'width' : colFixed});

}	

smartColumns();

$(window).resize(function () {
    smartColumns();
});




//CONTACT FORM
var options = { 
			target: '#progress', 
			success:  showResponse
		}
$("#contact-form").validate({
	submitHandler: function(form) {
		$(form).ajaxSubmit(options); 
	}
});
function showResponse() {
		$('#progress').fadeIn(500).delay(3000).fadeOut(500);
}

//PRETY PHOTO
$("a[rel^='prettyPhoto']").prettyPhoto();


//Single Page Show	
$('.popup').live('click',function(){
	pag = $(this).attr('href');
	$('<div class="single-wraper"></div>').hide().appendTo('body');
	$('<div class="single-page loading2"></div>').hide().appendTo('body').load(pag);
	$('.single-wraper').fadeIn(300, function() {
				$('.single-page').slideDown(300);
			});
	return false;
});	


//Single Page Show	
$('.s-popup').live('click',function(){
	pag = $(this).attr('href');

	$('.single-page').fadeOut(500, function() {
		$(this).remove();
	});	
	
	$('<div class="single-page loading2"></div>').hide().appendTo('body').load(pag);
	$('.single-wraper').fadeIn(500, function() {
				$('.single-page').fadeIn(500);
	});
	return false;
});	

  
//Toggle
$(".close").click(function(){$("#seting").toggle("fast");
$(this).toggleClass("openpanel");return false});
$(".toggle-block").hide(); 

$("p.toggle").click(function(){
		$(this).toggleClass("active").next().slideToggle(500);
		return false; 
});
	
//Accordion
$('.acc-block').hide();
$('.acc-header:first').addClass('active').next().show();
$('.acc-header').click(function(){
	if( $(this).next().is(':hidden') ) {
		$('.acc-header').removeClass('active').next().slideUp();
		$(this).toggleClass('active').next().slideDown();
	}
	return false;
});
	
				
});

