/* Init */
$(document).ready(function(){
	/* Init header slider */
	if ( $("#header-slider img").length > 1 ) {
		$("#header-slider").easySlider({
			auto: true,
			continuous: true,
			pause:5000,
			speed:1500
		});
		$("#header-slider img").fadeIn(1500);
	}
	$("a[rel='lightbox']").lightBox();
	$("#subcontents .subcontent a.expand").click(function(){
		$("#subcontents .subcontent a.expand.hide").removeClass('hide');
		$("#subcontents .subcontent .subcontent-body.expanded").removeClass('expanded');
		$(this).addClass('hide');
		$(this).siblings(".subcontent-body").addClass('expanded');
		return false;
	});
	$("div.subhelp").click(function(){
		var subjectID = $(this).attr("rel");
		showHelpDialog(subjectID);
		return false;
	});
	setTimeout(function(){
		$('#sharer').css('top',($(window).height() - $('#sharer').height())/2);
	},100);
	$(window).scroll(scrollSharer);
});

function scrollSharer() {
	top_value = ( $(document).scrollTop() + ($(window).height() - $('#sharer').height())/2 ) + "px";
	$('#sharer').animate({ top:top_value }, { queue: false, duration: 350 });
}

function showHelpDialog(subjectID) {
	$("#help-request").load("includes/box/help.cfm",{ subjectID:subjectID },function(){
		var form = $("#help-request form");
		$(form).initForm({bind:true}).submit(function(){
			$("#help-request").load("includes/box/help.cfm",$(form).serializeObj(),function(){ });
			return false;
		});
	});
	return false;
}

try {
	Cufon.replace('h1,h2,h3,h4,h5,h6');
/*
	Cufon.replace('#mainmenu li span',{
		fontSize:15,
		textShadow: '1px 1px black'
	});
*/
	Cufon.replace('#portfolio .project p.title');
} catch (err) {}

var formClassSelector = 'form.mr-form,.mr-form form';

$.fn.center = function(parent) {
	if ( !parent || ( parent.length && parent.length == 0 ) )
		parent = $(this).parent();
	$(this).css("top", Math.max(0,($(parent).height()-$(this).height())/2));
	$(this).css("left",Math.max(0,($(parent).width()-$(this).width())/2));
}
