Cufon.replace('blockquote, h1, .post h2, .blog-post h3, .links a', {fontFamily: 'Ronsard Crystal Medium'});  
Cufon.replace('#roamism, #nav, #footer h6, h4, #product-nav', {fontFamily: 'Orator Std', hover: true}); 
Cufon.replace('#sidebar h2', {fontFamily: "Jellyka - Estrya's Handwriting"});

function checkEmail(email) {	
	var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailVal = $("#" + email).val();
	return pattern.test(emailVal);
}
  
jQuery(function ($) {
	
	var $external 	= $('a[rel=external]'), 
		$email		= $('#subForm input.email'),
		$submit 	= $('#subForm input:submit'),
		$tiles      = $('div.product-tile');


	
	$external
		.click(function(){
			window.open(this.href);
			return false;   
		});
	
	function on_resize(e) {

		var $body   = $('body'),
		    $panel  = $('#panel'),
		    width   = $(window).width(),
		    height  = $(window).height(),
		    offset  = $('#footer').offset().top;
	
        if (width < 1200) {
            $body.removeClass('fluid');

        } else {
            $body.addClass('fluid');
        }
        if (height > 700) {
            $body.removeClass('fixed');
            $panel.height('auto');
        } else {
            $body.addClass('fixed');
            $panel.height(offset);   
       
        }
	
	}
	
	on_resize();

	$(window).bind('resize', on_resize);
	
	$tiles
	.click(function() {	    
		window.location = $(this).find('a').attr('href');
		return false; 		
	});
	

	$email
	.click(function() {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	})
	.blur(function() {
		if (this.value == '') {
			this.value = this.defaultValue;
		}
	});
	
	
    $submit
    .click(function() {	

        var $subForm 	    = $('form#subForm'),
            $form			= $("#theForm"), 
            $confirmation 	= $('#confirmation');

        $subForm.submit(function() { return false; });

        var formAction = $subForm.attr("action");
        var id = "ddkjud";
        var emailId = id + "-" + id;

        if (!checkEmail(emailId)) {
            alert("Please enter a valid email address");
            return;
        }

        var str = $subForm.serialize();

        //<![CDATA[
        var serialized = str + "&action=" + formAction;
        // ]]>

        $.ajax({
            url: "/wp-content/themes/roan/proxy.php",
            type: "POST",
            data: serialized,
            success: function(data){
                if (data.search(/invalid/i) != -1) {
                    alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
                } else {
                    $form.hide(); 
                    $confirmation.slideDown("slow");  
                    $confirmation.tabIndex = -1;
                    $confirmation.focus(); 
                }
            }
        });
    });
		
});
