$(document).ready(function() {

	jQuery.fn.delay = function(time,func){
		this.each(function(){
			setTimeout(func,time);
		});

		return this;
	};
	
	/*
	$(this).delay(2000,function(){
	    $('#wrap_sifr').animate({
				height: '210px'
			}, 1000 );
	  });
	*/
	
	/* module-gallery_index_controls */
// scroll actions
	//by default, the scroll is only done vertically ('y'), change it to both.
	$.scrollTo.defaults.axis = 'xy';
	var caption;
	var index;
	var speed = 200;
	var easing_set = 'easeOutCirc';
	var target;
	
	$('#module-gallery_index_controls a').click(function () { 
		$('#module-gallery_index_controls a').removeClass("active");
		$(this).addClass("active");
		caption = $(this).attr("rel");
		index = $(this).text();
		$('#module-gallery_index_controls_caption').html(caption);
		target = $('#gallery_index-'+index);
		$('#frame_index').stop().scrollTo( $(target), speed, { easing:easing_set });
		return false;
	});
	
	$('#module-index_quotes ul li').css('opacity', '0.0');
	
	$('#module-index_quotes ul').cycle({
		fx:    'fade', 
		speed:  1000,
		timeout:  5000
	});
	
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");

	function validEmail(email) {

		invalidChars = " /:,;"

		if (email == "") {
			return false
		}
		for (i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) > -1) {
				return false
			}
		}
		atPos = email.indexOf("@",1)
		if (atPos == -1) {
			return false
		}
		if (email.indexOf("@",atPos+1) > -1) {
			return false
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) {
			return false
		}
		if (periodPos+3 > email.length)	{
			return false
		}
		return true
	}

	function submitIt(subsForm) {
		if (!validEmail(document.subsForm.email.value))
			{
				alert("Invalid email address")
				document.subsForm.email.focus()
				document.subsForm.email.select()
				return false
			}


		var pref = "";
		var reqfields = new Array('City','Country','FirstName','LastName','State');

			for(i=0; i < reqfields.length;i++)
				{
					tempfield = "document.subsForm."+pref+reqfields[i]+".value";
					tempid = "document.subsForm."+pref+reqfields[i]+".id";
					tempval = eval(tempfield);
					tempid = eval(tempid);

					if(tempval=="")
						{
							alert("Please provide a "+tempid+".");
							return false;
						}
			}

		return true
	}
	
});
