$(document).ready(function(){
	if ($('#toolbox-user-pg').length > 0) $('#toolbox-user-pg #main .form-text').eq(0)[0].focus();
	
	$("input[@type=password], input[@type=text], textarea").focus(function(){
		val = $(this).attr('def');
		if ($(this).val() == val) $(this).val('');
		$(this).blur(function(){
			if ($(this).val() == '') $(this).val(val);
		});
	});
	
	if ($('.pageform').length <= 0) $('#page form:first').addClass('pageform');
	
	//update DOM from textfield
	$('.typelisten').keyup(function(event){
		if (event.keyCode == '13') event.preventDefault();
		$('#'+$(this).attr('element')).html($(this).val());
	});
	
	$('#nav li').hover(function(){
		var rent = $(this).parents('ul').parents('li');
		if (rent.attr('class').indexOf('expanded') <= -1 && rent.attr('class').indexOf('active') <= -1){
			$('#nav li.active.expanded ul').hide();
		}
		$(this).addClass('hover').find('ul').show();
	}, function(){
		
		$(this).removeClass('hover');
	});
	$('#nav').mouseout(function(){
		$('#nav li.expanded ul').hide();
		$('#nav li.expanded.active ul').show();
	});
	
	/*if ($('#page :checkbox').length > 0){
		$('#page :checkbox').simpleImageCheck({
			image: 'images2/icon_checkbox.gif',
			imageChecked: 'images2/icon_checkbox_hit.gif',
			imageOff: 'images2/icon_checkbox_off.gif',
			imageOffChecked: 'images2/icon_checkbox_offchecked.gif'
		});
	}*/
	
	if ($('textarea.html').length > 0){
		showcode = ($('textarea.html').attr('class').indexOf('codeview') > -1) ? true : false;
		$("textarea.html").htmlarea({
			/*toolbar: [
				["bold", "italic", "underline", "|", "forecolor"],
				["p", "h1", "h2", "h3", "h4", "h5", "h6"],
				["link", "unlink", "|", "image"],
				[{
					// This is how to add a completely custom Toolbar Button
					css: "spelling_button",
					text: "Check Spelling",
					action: function(btn){
						// 'btn' = jQuery object that represents the <A> "anchor" tag for the Toolbar Button
						//alert('SAVE!\n\n' + this.toHtmlString());
					}
				}]
			],*/
			toolbarText: $.extend({}, jHtmlArea.defaultOptions.toolbarText, {
				"html": "Toggle HTML Editor/Preview",
			}),
			loaded: function(){
				/*if (!showcode)*/ this.showHTMLView();
			}
		}).removeClass('resizable').htmlarea();
	}
	
	if ($('#previewSource').length > 0 && $('.previewWrap').length > 0){
		$('.previewWrap').html($('#previewSource').val());
	}
	
	$('.pagetabs li').click(function(e){
		if ($(this).parents('ul').attr('class').indexOf('maintabs') <= -1){
			$('.pagetabs li').removeClass('active');
			$(this).addClass('active');
			var idx = $($(this).parent().find('li')).index(this);
			targetel = $(this).parents('ul').next('fieldset');
			$(targetel).find('.tabbox').removeClass('active').parent().find('.tabbox:eq('+idx+')').addClass('active');
			e.preventDefault();
		}
	});
	
	//contact form
	$('#contactForm .form-submit').click(function(){		
		if (!$('#fname').val()){
			alert('Full Name is required.');
			$('#fname')[0].focus();
			return false;
		}	
		if (!$('#fphone').val()){
			alert('Phone Number is required.');
			$('#fphone')[0].focus();
			return false;
		} else if ($('#fphone').val().search(/[0-9\-()\s+]{8,}$/i) == -1){
			alert('Enter a valid Phone Number');
			$('#fphone')[0].focus();
			return false;
		}
		if (!$('#fmessage').val()){
			alert('Message field is required.');
			$('#fmessage')[0].focus();
			return false;
		}	
	});
	
});

function swf(){
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="1001" height="117" />\n');
    document.write('<param name="movie" value="header.swf" />\n');
    document.write('<param name="quality" value="high" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<embed src="header.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1001" height="117" menu="false" />\n');
    document.write('</embed>\n');
	document.write('</object>\n');
}