$(document).ready(function(){	
	
	if(jcarousel == "yes") {
		jQuery('.carousel-news').jcarousel({
			animation: "slow",
			auto: 6,
			scroll: 1,
			initCallback: mycarousel_initCallback
		});
		
		jQuery('.carousel-events').jcarousel({
			animation: "slow",
			scroll: 2
		});
	}

	
	if (validate == "yes" ) {
		$('body a.lightBox').lightBox();	
	}
		
	// fix for target='_blank'
	$('a[href^="http://"], a[href^="https://"], .external').attr({
		target: "_blank"
	});	
	
	//img hover
	$(function(event) {
	  $("img.hover").hover(function(event) {
			$(this).attr("src", $(this).attr("src").split(".").join("_on."));  // adds -hover to the name of the image
	  }, function(event) {
			$(this).stop(true,false); // prevents the creation of stacked actions
			$(this).attr("src", $(this).attr("src").split("_on.").join("."));  // removes -hover from the name of the image
	  });
	});
	
	$(".resize").imageResize({
		lightBox:true,
		maxWidth:290
	}); 
});


$(function () {
    var tabContainers = $('div.tabs > div');
    tabContainers.hide().filter(':first').show();
    
    $('div.tabs ul.tabNavigation a').click(function () {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');
            return false;
    }).filter(':first').click();
});

function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}


function validateMail() {	
	if (document.getElementById("name").value == 0) {
		alert('Please tell us your name');
		document.getElementById("name").focus();
		return false;
	}		
	if (document.getElementById("email").value.length < 1 ) {
		alert('Please tell us your email');
		document.getElementById("email").focus();
		return false;
	}	
	if (echeck(document.getElementById("email").value) == false){
		document.getElementById("email").focus();
		return false;
	}
	return true;
}// end function



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('Please enter a valid email address');
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert('Please enter a valid email address');
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert('Please enter a valid email address');
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert('Please enter a valid email address');
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert('Please enter a valid email address');
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert('Please enter a valid email address');
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert('Please enter a valid email address');
	    return false;
	 }
	 return true;					
}
