

// Add some addition jScript functionality needed for the slider
// this is a small helper extension i stole from
// http://www.texotela.co.uk/code/jquery/reverse/
// it merely reverses the order of a jQuery set.
$.fn.reverse = function() {
    return this.pushStack(this.get().reverse(), arguments);
};

// create two new functions: prevALL and nextALL. they're very similar, hence this style.
$.each( ['prev', 'next'], function(unusedIndex, name) {
    $.fn[ name + 'ALL' ] = function(matchExpr) {
        // get all the elements in the body, including the body.
        var $all = $('body').find('*').andSelf();

        // slice the $all object according to which way we're looking
        $all = (name == 'prev')
             ? $all.slice(0, $all.index(this)).reverse()
             : $all.slice($all.index(this) + 1)
        ;
        // filter the matches if specified
        if (matchExpr) $all = $all.filter(matchExpr);
        return $all;
    };
});

// Form field focus routines

$(document).ready(function() {
			$('input[type="text"],textarea[type="textarea"]').addClass("idleField");
       		$('input[type="text"],textarea[type="textarea"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"],textarea[type="textarea"]').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
});





// Email protection

$(document).ready(function(){
		$('a.email').each(function(){
			e = this.rel.replace('/','@');
			this.href = 'mailto:' + e;
			$(this).text(e);
		});
	});




function delquote(str){
 return (str=str.replace(/["']{1}/gi,""));
}


// The Newsletter script

$(document).ready(function(){

	$(document).pngFix();

	var invalidMailError	= "E-mail is<br />not valid.";
	var duplicateMailError	= "E-mail is<br />already in<br />the list.";
	var systemError			= "An error<br />occurred.<br />Please try<br />again.";
	var successMessage		= "Your e-mail<br />is added to<br />the list.";
	
	$(".successBalloon").hide();
	$(".errorBalloon").hide();
	$(".resultText").hide();
	$(".loader").hide();
	
    $('form#newsletterForm').bind('submit', function(e){
		$(".successBalloon").hide();
		$(".errorBalloon").hide();
		$(".resultText").hide();
		$(".loader").show();
		var email  = $('input#email').val();
        e.preventDefault();
		
		$.ajax({
			type: 'POST',
			url: 'newsletter.php?email='+email,
			data: '',
			success: function(theResponse){
				$(".resultText").fadeIn("slow");
				$(".resultText").animate({opacity: 1.0}, 3000);
				$(".resultText").fadeOut(1500);
				
				if (theResponse == 1) {
					$(".successBalloon").fadeIn("slow");
					$(".successBalloon").animate({opacity: 1.0}, 3000);
					$(".successBalloon").fadeOut(1500);
					$(".resultText").html(successMessage);
				}
				if (theResponse == 2) {
					$(".errorBalloon").fadeIn("slow");
					$(".errorBalloon").animate({opacity: 1.0}, 3000);
					$(".errorBalloon").fadeOut(1500);
					$(".resultText").html(invalidMailError);
				}
				if (theResponse == 3) {
					$(".errorBalloon").fadeIn("slow");
					$(".errorBalloon").animate({opacity: 1.0}, 3000);
					$(".errorBalloon").fadeOut(1500);
					$(".resultText").html(duplicateMailError);
				}
				$(".loader").hide();
			},
			error: function(){
				$(".errorBalloon").fadeIn("slow");
				$(".errorBalloon").animate({opacity: 1.0}, 3000);
				$(".errorBalloon").fadeOut(1500);
				$(".resultText").html(systemError);
				$(".loader").hide();
			}		
		});
	});
			
});
	
