$j(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if ($j("#contactForm").is(":hidden")){
			$j("#contactForm").slideDown("slow");
			$j("#backgroundPopup").css({"opacity": "0.7"});
			$j("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			$j("#contactForm").slideUp("slow");
			$j("#backgroundPopup").fadeOut("slow");  
		}
	}
	$j('.summit_link').click(function(){
        var parent = $j(this).parent();
        var name = null; 
        var date = null; 
		var all_text = null;
		if($j(parent).find('.summit_name').size()>0){
			name=$j(parent).find('.summit_name').first().html();
		}
		if($j(parent).find('.summit_date').size()>0){
			date = $j(parent).find('.summit_date').first().html();
		}
		if($j(parent).find('.summit_text').size()>0){
			all_text = $j(parent).find('.summit_text').first().html();
		}
		if(all_text!=null){
			$j('#message').val(all_text);
		} else {
			$j('#message').val('I would like more information on the ' + name + (date!=null?' on '+date:''));
		}
        $j(document).scrollTo(0,800,{queue:true});
        contact();
    });
    $j('.turnkey').click(function(){
        $j('#message').val('Please send me information about Briteskies’ Magento TurnKey Solution.');
        contact();
    });
	//run contact form when any contact link is clicked
	$j(".contact,  .close-button a").click(function(){contact()});
	
	//animation for same page links #
	$j('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $jtargetId = $j(this.hash), $jtargetAnchor = $j('[name=' + this.hash.slice(1) +']');
		  var $jtarget = $jtargetId.length ? $jtargetId : $jtargetAnchor.length ? $jtargetAnchor : false;
			if ($j(this.hash).length) {
				$j(this).click(function(event) {
					var targetOffset = $j(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					$j('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});



   //submission scripts
  $j('.contactFormx').submit( function(){
		//statements to validate the form	
		/*var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$j/;
		var email = document.getElementById('e-mail');
		if (!filter.test(email.value)) {
			$j('.email-missing').show();
		} else {$j('.email-missing').hide();}
		if (document.cform.name.value == "") {
			$j('.name-missing').show();
		} else {$j('.name-missing').hide();}	
		if (document.cform.message.value == "") {
			$j('.message-missing').show();
		} else {$j('.message-missing').hide();}		
		if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.message.value == "")){
			return false;
		} */

		//if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.message.value != "")) {
			//hide the form
			//$j('.contactForm').hide();
      if(!$j('#contactForm').valid()){
          return false;
      }
		    $j('.input_boxes').animate({borderBottomWidth:'4', borderTopWidth:'4'},'fast').slideUp('slow');
			//show the loading bar
			//$j('.loader').append($j('.bar'));
			//$j('.bar').css({display:'block'});
		
			//send the ajax request
			$j.post('mail.php',{name:$j('#name').val(),
							  email:$j('#e-mail').val(),
							  message:$j('#message').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $j('.bar').css({display:'none'});
			  $j('.loader').append(data);
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('$j("#backgroundPopup").fadeOut("slow"); $j("#contactForm").slideUp("slow")', 2000);
			
			//stay on the page

		//}
      return false;
  });
	//only need force for IE6  
//	$j("#backgroundPopup").css({
//		"height": document.documentElement.clientHeight
//	});
});
