/** Cufon **/

Cufon.replace('h1, h2, h3, h5, #menu a, .slidedeck h2');

/** SWFObject **/

swfobject.embedSWF("http://www.youtube.com/v/8Qwi7TeDhhg&hl=en_US&fs=1&rel=0", "video", "456", "280", "8");

/** Search label swap **/

(function($) {
    function toggleLabel() {
        var input = $(this);
        setTimeout(function() {
            var def = input.attr('title');
            if (!input.val() || (input.val() == def)) {
                input.prev('span').css('visibility', '');
                if (def) {
                    var dummy = $('<label></label>').text(def).css('visibility','hidden').appendTo('body');
                    input.prev('span').css('margin-left', dummy.width() + 3 + 'px');
                    dummy.remove();
                }
            } else {
                input.prev('span').css('visibility', 'hidden');
            }
        }, 0);
    };

    function resetField() {
        var def = $(this).attr('title');
        if (!$(this).val() || ($(this).val() == def)) {
            $(this).val(def);
            $(this).prev('span').css('visibility', '');
        }
    };

    $('input, textarea').live('keydown', toggleLabel);
    $('input, textarea').live('paste', toggleLabel);
    $('select').live('change', toggleLabel);

    $('input, textarea').live('focusin', function() {
        $(this).prev('span').css('color', '#4b4031');
    });
    $('input, textarea').live('focusout', function() {
        $(this).prev('span').css('color', '#c5c2be');
    });

    $(function() {
        $('input, textarea').each(function() { toggleLabel.call(this); });
    });

})(jQuery);

// Validate form

$(document).ready(function(){
	$("#contactForm").validate({
		rules: {
			email: {
				required:true,
				email:true
			}
		}
	});

	$("#newsletterForm").validate({
		rules: {
			email: {
				required:true,
				email:true
			}
		}
	});
});

// Form highlights

$(document).ready(function() {  
    $('input[type="text"], textarea').focus(function() {  
        $(this).addClass("active");  
    });  
    $('input[type="text"], textarea').blur(function() {  
        $(this).removeClass("active");
    });  
});



// Slide
$(document).ready(function() {
	if ($('.slides').length) {
		var itemLength = $('dl dd').length;
		var curItem = 0;
		$('dl dd').hide();
		$('dl dd:eq('+curItem+')').show();
		function rotate(e) {
			var dir = $(e.target).attr('id');
			if(e.target) { clearInterval(newsslide); };
			// Set the current position based on how many items there are.
			if(dir == "previous") {
				// Prev
				if(curItem > 0) {
					curItem = curItem - 1;
				} else {
					curItem = (itemLength-1);
				}
			} else {
				// Next
				if(curItem < (itemLength-1)) {
					curItem = curItem + 1;
				} else {
					curItem = 0;
				}
			}
			// Display the next item
			$('dl dd:eq('+curItem+')').siblings('dd').hide().end().fadeIn('slow');
			//alert($curItem + " / " + ($itemLength-1)) ;			
		}
		
		$('#next').click(rotate);
		$('#previous').click(rotate);
		
		newsslide = setInterval(rotate, 6000);
	}
});