$(document).ready(function() {

	$('#nav-secondary li').hover(
		function(){ $('ul', this).fadeIn('fast'); },
		function(){ $('ul', this).fadeOut('fast'); }
	);
	$("div.item").wrap('<div class="dialog">'+'<div class="bd">'+'<div class="c">'+'<div class="s">'+'</div>'+'</div>'+'</div>'+'</div>');

	$('div.dialog').prepend('<div class="hd">'+'<div class="c"></div>'+'</div>').append('<div class="ft">'+'<div class="c"></div>'+'</div>');

	$('#nav-primary li').hover(function() {
		$(this).addClass('over');
	}, function() {
		$(this).removeClass('over');
	});

	$('hr').wrap('<div class="hr"></div>');

	$('div.cta').each(function() {
		$cta = $(this);
		$href = $('a:first', $cta).attr('href');
		if($href != null) {
			$cta.hover(
				function(){ $(this).addClass('hover'); },
				function(){ $(this).removeClass('hover');}
			).click(function(){
				document.location = $href;
			});
		}
	});

	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top -40;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});

});



/* REWFW: FORMS */

$(document).ready(function(){

	$('#content form.rewfw').each(function(){
		 var dform = $(this);
		 $(dform).wrapInner('<div class="form-wrap"></div>');
		 $('.field input:text,.field input:password', dform).wrap('<span class="input-wrap"></span>');
		 $('.field select', dform).wrap('<span class="select-wrap"></span>');
		 $('.field textarea', dform).not('.richtext').wrap('<span class="textarea-wrap"></span>');
		 $('.field', dform).wrapInner('<span class="field-iwrap"></span>');
		 $('.token', dform).wrapInner('<span class="token-iwrap"></span>');
		 $('legend', dform).each(function() {
			var content = $(this).html();
			$(this).after('<h4 class="legend">'+ content +'</h4>').hide();
			$(this).remove();
		 });

/*
		$('button[type=submit]', dform).each(function(){
			$button = $(this);
			$label = $(this).html();
			$(this).wrap('<div class="button submit"></div>').after('<span class="label">'+$label+'</span>').parent().click(function() {
				$(this).parents('form').trigger('submit');
			});
		});
*/

	});

	$('.actions a.button').each(function(){
		$button = $(this);
		$label = $(this).html();
		$classes = $(this).attr('class').replace('button', '');
		$(this).wrap('<div class="button link ' + $classes + '"></div>').after('<span class="label">'+$label+'</span>');
		$('.button', this).live('click', function() {
			document.location = $('a', this).attr('href');
		});
	});

});