$(document).ready (function(){
	
	$(".slider-carousel").jcarousel({
		scroll:1,
		auto:9,
		wrap:"both",
		visible:1,
        itemFirstInCallback: mycarousel_itemFirstInCallback,
        initCallback: mycarousel_initCallback,
        start: 1
		
	});
	
	$("form.jqtransform").jqTransform();
	
	
	$('ul.dd').hide();
	$('#navigation ul li').hover(function(){ 
		$(this).find('ul.dd').stop(true,true).show();
		$(this).find('a:eq(0)').addClass('hover');
	 },
	 function(){  
		$(this).find('ul.dd').stop(true,true).hide();
		$(this).find('a:eq(0)').removeClass('hover');
 	});
	
	
	var lightbox_photos;
	var num_lightbox_photos;
	var area_lightbox;
	var num_area_lightbox;
	
	lightbox_photos = $('a[rel*=lightbox]');
	num_lightbox_photos = lightbox_photos.length;
	
	area_lightbox = $('area[rel*=lightbox]');
	num_area_lightbox = area_lightbox.length;

	if(num_lightbox_photos > 0) {
		$('a[rel*=lightbox]').lightBox();	
	}
	if(num_area_lightbox > 0) {
		$('area[rel*=lightbox]').lightBox();
	}
	
	// back to top button
	$(function(){$.fn.scrollToTop=function(){$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("fast","easeInOutExpo")}var scrollDiv=$(this);$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("fast")}else{$(scrollDiv).fadeIn("fast")}});$(this).click(function(){$("html, body").animate({scrollTop:0},"slow", "easeInOutExpo")})}});


	$(function() {
	$("#toTop").scrollToTop();
	});

	var openspeed=850;
	var closespeed=250;
	var easingtype="easeOutElastic";

	//top button
	$('#toTop').hover(
	function() {$(this).stop().animate({ backgroundPosition: "24px 5px" }, openspeed, easingtype);}, 
	function() {$(this).stop().animate({ backgroundPosition: "24px 12px" }, closespeed);}
	);
});

function mycarousel_initCallback(carousel) {
	    $('.slider-navigation a').bind('click', function() {
	        carousel.scroll($.jcarousel.intval($(this).text()));
	        return false;
	    });	        
};
	
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	$('.slider-navigation a').removeClass('active');
	$('.slider-navigation a').eq(idx-1).addClass('active');
};

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

	function allfields(msg_fr)
	{
	var emailID=document.contact.mail

		if ((document.contact.namec.value=="") ||
		 	(document.contact.postal.value=="") ||
		 	(document.contact.mail.value=="") ||
		 	(document.contact.address.value=="") ||
		 	(document.contact.comunity.value=="") ||
		 	(document.contact.moving_date.value=="") ||
		 	((document.contact.abouta.checked==false) &&
		 	(document.contact.aboutb.checked==false) &&
		 	(document.contact.aboutc.checked==false) &&
		 	(document.contact.aboutd.checked==false) &&
		 	(document.contact.aboute.checked==false) &&
            (document.contact.aboutf.checked==false)) ||
            (document.contact.message=="")
			)
		{
	   		alert(msg_fr);
	   		return false;
		}

		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}

		return true;
	}


