$(document).ready(function() {                
	
	
	
	/*email protect*/
	$("span.mailto").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();
	});    



	// Open links in new window when rel="external" is applyed to a tag
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});


	$('#flash').cycle({ 
  	  fx:    'fade', 
    	speed:  1000 
 	});



	/*on focus for input boxes*/
	$.fn.resetValue = function() {
		return this.focus(function() {if( this.value == this.defaultValue ) {this.value = "";}})
		.blur(function() {if( !this.value.length ) {this.value = this.defaultValue;}});};

		//on the click of the search input, clear string
		if($("input#keywords").val() == "enter keywords...")
		{
			$("input#keywords").resetValue();
		}


	/* on the search form submit */
	$("form#search-form").submit(function(){
		//if the user submits search our products, clear string
		if($("input#keywords").val() == "enter keywords...")
		{
			$("input#keywords").val("");
		}

		//get the length of the string
		var searchLength = $("input#keywords").val().length;

		//if the search string is less than 3 characters alert the user
		if(searchLength >= 0 && searchLength < 3)
		{
			alert("You must place at least three characters");
			$("input#keywords").focus();
			return false;
		}
	});

  $("li#cap a.change").click(function() {
    var MyTime = new Date()

    $("li#cap").each(function() {
      $(this).find("div.image").find("img").attr("src","captcha/cap_image.asp?time=" + MyTime.getTime() + "")
    });

    return false;
  });
  
	
	if($("#Field1").val() == "first name"){$("#Field1").resetValue();}
	if($("#Field2").val() == "last name"){$("#Field2").resetValue();}
	if($("#Email-mailing").val() == "email"){$("#Email-mailing").resetValue();}
	if($("#Redeem").val() == "Enter Voucher Code"){$("#Redeem").resetValue();}

});