$(function () {
	$(".example").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#ebebeb',
		'overlayOpacity'	: 0.7
	});
	$("#various4").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	$('#fr_input1,#fr_input2,#fr_input3').css({color:'#d4d0c8'});
	$('#fr_input1,#fr_input2,#fr_input3').focus(function() {
		$(this).css({color:'#d4d0c8'});
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
			$(this).css({color:'#000'});
		}
	});
	$('input#fr_input1,#fr_input2,#fr_input3').blur(function() {
		$(this).css({color:'#000'});
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(this).css({color:'#d4d0c8'});
		}
	});
	var w = $(window).width();
	var item = 236+18;
	var all_item = Math.round(w/(item+52));
	var win = (all_item*item);
	
	$('#portfolioCarousel').jcarousel({
		scroll: all_item
	});
	$(".jcarousel-container.jcarousel-container-horizontal").width(win-16);
	$(".jcarousel-clip.jcarousel-clip-horizontal").width(win-16);
	if($.browser.msie) {
		$(".mcent").width(w-359);
	} else {
		$(".mcent").width(w-363);
	}
	$('img').mouseover(function() {
		$(this).closest('.b').animate({ 'marginLeft' : "+=15px" }, 100)
		.animate({ 'marginLeft' : "-=30px" }, 100)
		.animate({ 'marginLeft' : "+=15px" }, 100);
	});
});

function checkform(){
	theForm = document.fr_contact;
	var error = "";
	error += validateEmpty(theForm.topic, 'TOPIC');
	error += validateEmail(theForm.email, 'YOUR E-MAIL');
	error += validateEmpty(theForm.texta, 'YOUR TEXT');
	
	if(error=="") { alert('Jūsų žinutė išsiūsta.'); theForm.submit(); }
}

function validateEmpty(fld, val) {
	if (fld.value == val) {
		fld.style.border = '1px solid Red';
		return "a";
	} else {
		fld.style.border = 'none';
		return "";
	}
}
function trim(s) {
	return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld, val) {
	var tfld = trim(fld.value);
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if (fld.value == val) {
		fld.style.border = '1px solid red';
		return "a";
	} else if (!emailFilter.test(tfld)) {
		fld.style.border = '1px solid red';
		return "a";
	} else if (fld.value.match(illegalChars)) {
		fld.style.border = '1px solid red';
		return "a";
	} else {
		fld.style.border = 'none';
		return "";
	}
}

function pic_click(id) {
	$.post("post.php", { id: id } );
}
