// JQuery READY!
$(document).ready(function(){
	
	// JQuery Form
	var options = {
		target: '#alert'
	}; 
	$('#contact_form').ajaxForm(options);
	
	// HIDDEN ELEMENTS
	$(".jquery_hide").hide();
	$("#alert").hide();
	$("#content").hide();
	$("#content").slideDown('slow');
	
	$("#portfolio_heading").toggle(
		function(){
			$("#portfolio").slideDown('slow');
			return false;
		},
		function(){
			$("#portfolio").slideUp('slow');
			return false;
		}
	);
	$("#close_portfolio").click(
		function(){
			$("#portfolio_heading").triggerHandler('click');
			return false;
		}
	);
	
	$("#resume_heading").toggle(
		function(){
			$("#resume").slideDown('slow');
			return false;
		},
		function(){
			$("#resume").slideUp('slow');
			return false;
		}
	);
	$("#close_resume").click(
		function(){
			$("#resume_heading").triggerHandler('click');
			return false;
		}
	);
	
	$("#contact_heading").toggle(
		function(){
			$("#contact").slideDown('slow');
			$(this).css({'background-image' : 'none'})
			return false;
		},
		function(){
			$("#contact").slideUp('slow', function(){
				$("#contact_heading").css({'background-image' : 'url(/images/shadows/shadow_top.png)'})
			});
			return false;
		}
	);
	
	// DESCRIPTIONS
	$(".show_description").click(showDescription);
	$(".description b.close").click(hideDescription);

});

// FORMS
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
	  		return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
	  		this.value = '';
		else if (type == 'checkbox' || type == 'radio')
	  		this.checked = false;
		else if (tag == 'select')
	  		this.selectedIndex = -1;
  	});
};

// PORTFOLIO PARTS
function loadPart(name, id) {
	$(id).hide().load('/portfolio-pages'+name, function(){
		$(this).find('.jquery_hide').hide();
		$(this).find(".show_description").click(showDescription);
		$(this).find(".description b.close").click(hideDescription);
		$(this).slideDown('slow');
		$('#load_'+this.id).slideUp('slow');
	});
	return false;
}
function showDescription() {
	$(this).slideUp('fast');
	$(this).prev().slideDown('fast');
	return false;
}
function hideDescription() {
	$(this).parent().slideUp('fast');
	$(this).parent().next().slideDown('fast');
	return false;
}

// PRINT BY DIV
function printDiv(id, css) {
	var div = document.getElementById(id);
	var win = window.open('','','left=0,top=0,width=0,height=0,toolbar=0,scrollbars=0,status=0'); 
	win.document.write("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/reset.css\" media=\"all\" /><link rel=\"stylesheet\" type=\"text/css\" href=\""+css+"\" media=\"all\" /></head><body>");
	win.document.write(div.innerHTML);
	win.document.write("</body></html>");
	win.document.close();
	win.focus();
	win.print();
	win.close();
}