jQuery(document).ready(function() {                
	
	// Open links in new window
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").click(function(){this.target = "_blank";});
	
	//nav rounded corner
	$('ul#navigation li a.toplevel').corner("rounded 3px top bottom");
	$('#questions_to_ask_your_web_developer').corner("rounded 5px top bottom");
	$('#side_panel').corner("rounded 5px bl");

	//form text
	$('form#enquiry input[type = "text"], form#enquiry textarea').focus(function(){
		if($(this).attr("value") == $(this).attr("title")) $(this).attr("value", "");
	});
	$('form#enquiry input[type = "text"], form#enquiry textarea').blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", $(this).attr("title"));
	});

  $('input[type = "submit"]').css('font-size', '0px');
  $('input[type = "submit"]').css('line-height', '0px');
  $('input[type = "submit"]').css('text-indent', '-9999em');
  
  $('.button').append('<span class="end"><!-- --></span>');
  $('li.button-container input').css("cursor","pointer").hover(function(){$(this).addClass("inputhover");return false;},function(){$(this).removeClass("inputhover");});
  $('input.freebutton').css("cursor","pointer").hover(function(){$(this).addClass("inputhover1");return false;},function(){$(this).removeClass("inputhover1");});
  $('.button').hover(function(){
    $(this).css("background-position","0 -60px");
    $(this).find("span.end").css("background-position","-274px -90px");
    return false;
  },function(){
    $(this).css("cursor","pointer");
    $(this).css("background-position","0 0");
    $(this).find("span.end").css("background-position","-274px -30px");
  });
  
  // call to action hovers and jcarousel
  $("div#call_to_actions li, div#call_to_actions a").css("cursor","pointer");
  $("div#call_to_actions li").hover(function(){$(this).addClass('cta-over');return false;},function(){$(this).removeClass('cta-over');});
  $("div#call_to_actions a#back, div#call_to_actions a#forward").hover(function(){$(this).addClass('cta-over2');return false;},function(){$(this).removeClass('cta-over2');});
  $("div#call_to_actions li").click(function(){window.location = $(this).find('a').attr("href");});
  jQuery.easing.easeOutQuart = function (x, t, b, c, d) {return -c * ((t=t/d-1)*t*t*t - 1) + b;};
  var intval = 8000;
  jQuery('#ctas').serialScroll({
		items: 'li',
		prev:'#call_to_actions a#back',
		next:'#call_to_actions a#forward',
		queue: false,
		interval: intval,
		duration: 1200,
		start: 0,
		force:true,
		stop: true,
		lock: false,
		jump: false,
		cycle: true,
		easing: 'easeOutQuart',
		step: 1
	});
  
  var intval2 = 6000;
  jQuery('#news-headlines').serialScroll({
		items: 'li',
		interval: intval2,
		duration: 600,
		start: 0,
		force:true,
		stop: true,
		lock: false,
		jump: false,
		cycle: true,
		easing: 'linear',
		step: 1
	});
  
  //dropdown nav execute
	$('ul#navigation li.dropdown').hover(function(){$(this).addClass("over");return false;},function(){$(this).removeClass("over");});
	$('ul#navigation li.dropdown').hover(function(){$(this).find('ul').slideDown("fast");return false;},function(){$(this).find('ul').slideUp(100);});
  	$('ul#navigation li.dropdown').hover(function() {$('.over a').addClass('onsection');}, function() {$('.over a').removeClass('onsection');});
	
  //cycle
  jQuery("#cases").cycle({
    fx: 'scrollLeft', 
    speed:  'fast', 
    timeout: 6000,
    next: '#next',
    prev: '#previous'
  });

  jQuery("#cases2").cycle({
    fx: 'scrollLeft', 
    speed:  'fast', 
    timeout: 6000,
    next: '#next2',
    prev: '#previous2'
  });
  
   jQuery("#cases3").cycle({
    fx: 'scrollLeft', 
    speed:  'fast', 
    timeout: 6000,
    next: '#next3',
    prev: '#previous3'
  });
   
    jQuery("#cases4").cycle({
    fx: 'scrollLeft', 
    speed:  'fast', 
    timeout: 6000,
    next: '#next4',
    prev: '#previous4'
  });
	
	 jQuery("#cases5").cycle({
    fx: 'scrollLeft', 
    speed:  'fast', 
    timeout: 6000,
    next: '#next5',
    prev: '#previous5'
  }); 
  
  //email protect
	$("span.safermailing").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
		$(this).remove();
	}); 
	
  
});


// highlight active fields in forms
jQuery(document).ready(function () {
									 
	$('form.contact_form input').focus (
		function () {
			$(this).addClass('active');
		}
	);
	
	$('form.contact_form input').blur (
		function () {
			$(this).removeClass('active');
		}
	);
		
	$('form.contact_form textarea').focus (
		function () {
			$(this).addClass('active');
		}
	);
	
	$('form.contact_form textarea').blur (
		function () {
			$(this).removeClass('active');
		}
	);
	
	$('form.contact_form select').focus (
		function () {
			$(this).addClass('active');
		}
	);
	
	$('form.contact_form select').blur (
		function () {
			$(this).removeClass('active');
		}
	);
		
});

/***********************************************
* Safe email links - hide Email To field
***********************************************/

function hide_EmailForm() {
	var s1 = 'info';
	var s2 = '@';
	var s3 = 'webfirm.com';
	document.write('<input type="hidden" name="Em' + 'ail_To" value="' + s1 + s2 + s3 + '" />');
}

function hide_EmailForm2() {
	var s1 = 'corporate';
	var s2 = '@';
	var s3 = 'webfirm.com';
	document.write('<input type="hidden" name="Em' + 'ail_To" value="' + s1 + s2 + s3 + '" />');
}

//vanilla validation

	function ValidateForm(f){

		with(f){
			if (isEmpty(_1_Name.value) || _1_Name.value == "name" ) {
				alert("Please enter your Name");
				_1_Name.focus();
				return false;
			}

			if (isEmpty(_2_Company.value) || _2_Company.value == "company") {
				alert("Please enter your Company Name");
				_2_Company.focus();
				return false;
			}
			
			if (isEmpty(_3_Email_From.value) || _3_Email_From.value == "email") {
				alert("Please enter your Email Address");
				_3_Email_From.focus();
				return false;
			}
      
			if ( !isEmail(_3_Email_From.value) ) {
				alert("Please enter a valid Email Address.");
				_3_Email_From.focus();
				return false;
			}

			if (isEmpty(_4_Phone.value) || _4_Phone.value == 'phone') {
				alert("Please enter your Phone number");
				_4_Phone.focus();
				return false;
			}
			
			if (isEmpty(_5_State.value) || _5_State.value == 'state' ) {
				alert("Please enter your State");
				_5_State.focus();
				return false;
			}
			
			if (isEmpty(_6_Comments.value) || _6_Comments.value == "comments") {
				alert("Please enter your Comments");
				_6_Comments.focus();
				return false;
			}
		}
	return true;
 }

