$(document).ready(function(){


	$(".needed").blur(function(){
		if($(this).val() == ""){
			$(this).addClass("frmerror");
		}else{
			if($(this).attr("name") == "txtemail"){
				checkemail(this);
			}else if($(this).attr("name") == "txtphone"){
				checkphone(this);
			}else{
				$(this).removeClass("frmerror");
			}
		}
	})
	
	
	$(".lnkexchange").click(function(){
		$(".needed").each(function(index, value){
			if($(this).val() == ""){
				$(this).addClass("frmerror");
			}else{
				if($(this).attr("name") == "txtemail"){
					checkemail(this);
				}else if($(this).attr("name") == "txtphone"){
					checkphone(this);
				}else{
					$(this).removeClass("frmerror");
				}
			}
		})
		
		
		if($(".frmerror").size() > 0){
			return false;
		}else{
			return true;
		}
	})

	
	$(".information").click(function(){		
		var id = $(this).attr("href");
		if($(id).size() == 1){
			$(".info-content").hide();
			$(id).css({ "top": $(this).offset().top -136, "left": "522px"})
			$(id).fadeIn();
		}
		return false;
	})

		
	$(".close").click(function(){
		$(this).parent("p").parent("div").fadeOut();
		return false;
	})
	

//	$(".form").validate({
//		rules: {
//			field: {
//			  required: true,
//			  email: true,
//			  number: true
//			}
//		}
//	});

	$('.cycle ul').cycle({
		fx: 'fade'
	});

	$('#nav').superfish();

//	$('dl.gallery-item a').attr('rel','gallery');
//	$('dl.gallery-item a[rel="gallery"]').colorbox();

//	$('#movie').flash({
//		swf: '/wp-content/themes/bb/video/slider.swf',
//		height: 200,
//		width: 600
//	});

	$('a.top').click(function(){
	     $('html, body').animate({scrollTop: '0px'}, 300);
	     return false;
	});
	
});


function checkemail(obj){
	if(jQuery(obj).val().match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == null){
		jQuery(obj).addClass("frmerror");
	}else{
		jQuery(obj).removeClass("frmerror");
	}
}

function checkphone(obj){
	if(jQuery(obj).val().match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/) == null){
		jQuery(obj).addClass("frmerror");
	}else{
		jQuery(obj).removeClass("frmerror");
	}
}
