$(function(){
    $("ul#nav li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul#nav li ul li:has(ul)").find("a:first").append(" &raquo; ");
});
/* Plugin to make variable height divs equal heights */
$.fn.sameHeights = function() {
	$(this).each(function(){
		var tallest = 0;
		$(this).children().each(function(i){
			if (tallest < $(this).height()) { tallest = $(this).height(); }
		});
		$(this).children().css({'height': tallest});
	});
	return this;
};
$(document).ready(function(){
	$('#header_bg').cycle({
		fx:    'fade',
		delay: -1000
	});
	$("#content_single > p").hide();
	$("ul.recentPost li:last-child").css("border-bottom", "none");		
	$('#highlight_box ul').sameHeights();


	$('a[href*=#]').bind('click', function(e) {
										   
	e.preventDefault(); //prevent the "normal" behaviour which would be a "hard" jump
	 
	var target = $(this).attr("href"); //Get the target
	 
	// perform animated scrolling by getting top-position of target-element and set it as scroll target
	$('html, body').stop().animate({ scrollTop: $(target).offset().top }, 2000, function() {
	location.hash = target; //attach the hash (#jumptarget) to the pageurl
	});
	 
	return false;
	});
	(function($) {
		$(function() { //on DOM ready
			$("#scroller").simplyScroll({
				autoMode: 'loop'
			});
		});
	});
// Begin Form Handling.	
	$('form#ajax_form .submit').click(function(){

		$('#ajax_form .error').hide();	//if error visibile, hide on new click
		
		var first_name = $('input#first_name').val();
		if (first_name == "" || first_name == " " || first_name == "Name") {
			alert('Please enter your first name');
		    $('input#first_name').focus();										  
		    return false;
		}
		
		var last_name = $('input#last_name').val();
		if (last_name == "" || last_name == " " || last_name == "Name") {
			alert('Please enter your last name');
		    $('input#last_name').focus();										  
			
		    return false;
		}
		
		
		var email_test = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		var email = $('input#email').val();
		if (email == "" || email == " ") {
			alert('Please enter a valid email.');
		   $('input#email').focus();
		   return false;
		} else if (!email_test.test(email)) {
			alert('Please enter a valid email.');
		   $('input#email').select();
		   return false;
		}
		
		
		var phone_test = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
		var phone = $('input#phone').val();
		if (phone == "" || phone == " " || phone == "Phone Number") {
			alert('Please enter a valid phone number.');
		    $('input#phone').focus();
		    return false;
		}
		
		
		$('form#ajax_form').slideUp('fast').before('<div class="processing"><img src="images/form_ani.gif" alt="Processing Form" /><p>Processing Form</p></div>');
		var data_string = $('form#ajax_form').serialize();


	$.ajax({
		    type:       "POST",
		    url:        "includes/php/mail.php",
		    data:       data_string,
		    success:    function() {

		$('div.processing').slideUp('fast').before('<div id="success"></div>');
		$('#success').html('<h3>Thank you for your inquiry</h3><p>Your email has been sent.</p>').slideDown(3000);

		    }//end success function


		}) //end ajax call

		return false;


	}) //end click function
	

	var current_data = new Array();

	$('.clear').each(function(i){
		$(this).removeClass('clear').addClass('clear'+i);
		current_data.push($(this).val());

		$(this).focus(function(){
			if($(this).val() == current_data[i]) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			var stored_data = current_data[i];
			if($(this).val()==''){
				$(this).val(stored_data);
			}
		})
	});
})
	



$(window).load(function() {
	$("a.popup").fancybox();
	$(".fancybox").fancybox();
	
	$('#submit').click(function() {
		var pw = $('#password').val();
		if (pw != "") {
			$('#client_area').attr("src","client_area.php?client="+$('#password').val());
			$("#ftp_open").fancybox({
					'width'         		: 587,
					'height'        		: 373,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'						
			}).trigger('click');
		}else{
		$.fancybox('<p style="font-size:0.825em; margin:0;">Please check to make sure your typed in the folder ID correctly.</p>',{
					'autoDimensions'	: true,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
				   })	
		}
		return false;
	});		
	$('.video_link').click(function() {
		$(this).replaceWith('<a href="includes/video/Revcon Short HD_F8(16x9).flv" style="display:block;width:290px;height:161px;margin:0 0 20px 0" id="player"></a>');
		flowplayer("player", "includes/swf/flowplayer-3.2.5.swf");	
		return false;
	});
});
