	$(document).ready(function() {
		
			if($('#home_gallery').length > 0) { // if homepage		
			$('#home_gallery').homeGallery();
			
		
		}
		
	
		
	});




// home gallery - quick fix
	var current = 0;
	var iv;
	jQuery.fn.extend({
		homeGallery: function() {
			
			// preloader
				$('.gallery_nav a').each(function() {
					
					objimg = new Image();
					objimg.src = $(this).attr('rel');
					
					
				});
			
			//
			$('#home_items h3').click(function(e) { 
						if ( $(this).hasClass('closed') ) {
							$('#home_items').animate({height:"350",opacity:"0.9"},900);
						  $(this).removeClass('closed');	
						} else {
					    $('#home_items').animate({height:"15",opacity:"0.5"},400);
						  $(this).addClass('closed');						
						}														 
						e.preventDefault(); 
			});
		
			
			$('.gallery_nav a').click(function(e) {
				clearInterval(iv);
				showHomeGallery($(this));
				e.preventDefault(); 
			 
			});
			
			iv = setInterval('randomItem()', 5000);
		
		}
	});
	function randomItem() {
		var max = $('.gallery_nav a').size();
		var rand = Math.floor(Math.random()*max);
		var item = $('.gallery_nav a')[rand];
		showHomeGallery($(item));
	}
	function showHomeGallery(currentItem) {
		if($('#home_gallery').length > 0) {
			
			$('.gallery_nav a').removeClass('current');
			
			var bg = currentItem.attr('rel');		
			if( bg != '') { 
			
				if(current == 1) {
				
					current = 2;
					$('#gallery_visual_2').css({
						'opacity': 0,
						'background-image': 'url('+bg+')'
					});
					$('#gallery_visual_2').stop().animate({opacity:'1'}, 1000);
				
				} else if (current == 2) {
				
					current = 1;
					$('#gallery_visual_1').css('background-image', 'url('+bg+')');
					$('#gallery_visual_2').stop().animate({opacity:'0'}, 1000);
				
				} else {
				
					current = 2;
					$('#gallery_visual_2').css({
						'opacity': 0,
						'background-image': 'url('+bg+')'
					});
					$('#gallery_visual_2').stop().animate({opacity:'1'}, 1000);
				
				}
			
				currentItem.addClass('current');
			
			}
			
		
			
			var pr = currentItem.attr('class');
			if( pr != undefined) {
				pr = pr.split('current').join('');
				pr = pr.split(' ').join('');
				$('.description img.proj').hide();
				$('.description img.'+pr+'_title').show();
			}
		}
	}







// show-hide errors

	function showError(v) {
		if(v != null && v != undefined) { if($('#error')) $('#error').html(v).show('slow');
		} else { if($('#error')) $('#error').show('slow');
		}
		return false;
	}
	
	function hideError() {
		if($('#error')) $('#error').hide('slow');
		return true;
	}
	
	function isEmail(v) {
		return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(v);
	}








	
			$(document).ready(function(){
    var check = 0;
    $("#checkAll").click(function(){        
        if( check == 0 ){
            $("input.check:checkbox").attr("checked", "checked");
            check = 1;
        }
        else{
            $("input.check:checkbox").removeAttr("checked");
            check = 0;
        }        
    });              
});
	




