/* ---------------- */
/* GLOBAL FUNCTIONS */
/* ---------------- */

// Jump to top of the page 
function jumpScroll() {
    window.scroll(0, 0);
}

// Clear input field text
function clearText(theText) {
    if (theText.value == theText.defaultValue) 
        theText.value = ""
}

// Reset input field text
function showText(theText) {
    if (theText.value == "") 
        theText.value = theText.defaultValue;
}


function perm_link(link) {
	close_mailing();
	$("#perm").show();
	$("#over-lay").show(); 
	$("#perm_link").val(link);

}

function close_perm() { 
	$("#perm").hide();
	$("#over-lay").hide(); 
}


function show_sharing(picID) {
	close_mailing();
	$("#picID").val(picID); 
	$("#share").show();
	$("#over-lay").show(); 
	$("#share .sharing").show();
	$("#share .share-btn").show();
	$("#share .result").hide(); 

}

function close_sharing() { 
	$("#share .sharing").show();
	$("#share .share-btn").show();
	$("#share .result").hide(); 
	$("#share").hide();
	$("#over-lay").hide();
}

function submit_sharing() { 
	name = jQuery.trim($("#send_your_name").val());
	email = jQuery.trim($("#send_your_email").val());
	message = jQuery.trim($("#send_message").val());
	to_name = jQuery.trim($("#send_to_name").val());
	to_email = jQuery.trim($("#send_to_email").val()); 
	picID = $("#picID").val(); 
	if(name.length > 0 && email.length > 0 && message.length > 0 && to_name.length > 0 && to_email.length > 0) {
		$.ajax({ 
			type: "POST",
			url: site_dir + "/lib/submit_sharing/",
			data: "name="+name+"&email="+email+"&message="+message+"&to_name="+to_name+"&to_email="+to_email+"&url="+port_url+"&picID="+picID,
			success: function(msg){
				if(msg == "1") {
					$("#send_your_name").val("");
					$("#send_your_email").val("");
					$("#send_message").val("");
					$("#send_to_name").val("");
					$("#send_to_email").val("");
					$("#share .sharing").hide();
					$("#share .share-btn").hide();
					$("#share .result").show();
					setTimeout("close_sharing()", 1500);
				}
			}
		}); 
	}
	else {
		alert("Please fill out all fields.");
	}
}

function show_mailing() {
	close_sharing();
	$("#mailing_list").show();
	$("#mailing_list_about").show();
	$("#over-lay").show(); 
}



function show_waiting() {
	close_sharing();
	$("#waiting_list").show();
	$("#over-lay").show(); 
}


function show_waiting2(eventID) {
	close_sharing();
	$("#waiting_list").show();
	$("#over-lay").show(); 
	$("#weventID").val(eventID);
}



function close_waiting() { 
	$("#waiting_list .mail-box").show();
	$("#waiting_list .mail-btn").show();
	$("#waiting_list .result").hide();
	$("#waiting_list").hide(); 
	$("#over-lay").hide(); 
}



function show_mailing2() { 
	var position = $("#footer_links_simple").position(); 
	$("#mailing_list2").show();
	$("#mailing_list2").css("left", position.left+ 460);
	$("#mailing_list2").css("top", position.top - 730);
	$('#footer_links2 ul a:contains("Mailing List")').removeClass().addClass('links_on'); 
}

function close_mailing() { 
	$("#mailing_list .mail-box").show();
	$("#mailing_list .mail-btn").show();
	$("#mailing_list .result").hide(); 
	$("#mailing_list").hide();
	$("#mailing_list_about").hide();
	$("#mailing_list2").hide();
	$("#over-lay").hide(); 
	$('#footer_links2 ul a:contains("Mailing List")').removeClass("links_on"); 
}


function submit_waiting2() { 
	eventID = $("#weventID").val(); 
	submit_waiting(eventID);
}


function submit_waiting(eventID) { 
	name = jQuery.trim($("#waiting_name").val()); 
	email = jQuery.trim($("#waiting_email").val());
	if(name.length > 0 && email.length > 0) {
		$.ajax({ 
			type: "POST",
			url: site_dir + "/lib/submit_waiting/",
			data: "name="+name+"&email="+email+"&eventID="+eventID, 
			success: function(msg){
				if(msg == "1") { 
					$("#waiting_name").val("");
					$("#waiting_email").val(""); 
					$("#waiting_list .mail-box").hide();
					$("#waiting_list .mail-btn").hide();
					$("#waiting_list .result").show();
					setTimeout("close_waiting()", 1500);
				}
				else {
					alert(msg);
				}
			}
		}); 
	}
	else {
		alert("Please fill out all fields.");
	}
}

function submit_mailing() { 
	name = jQuery.trim($("#your_name").val()); 
	arrName = name.split(" "); 
	fname = arrName[0];
	lname = "";
	for(i=1; i<arrName.length; i++) {
		lname = lname + " " + arrName[i];
	} 
	email = jQuery.trim($("#your_email").val());
	if(name.length > 0 && email.length > 0) {
		$.ajax({ 
			type: "POST",
			url: site_dir + "/lib/submit_mailing/",
			data: "name="+name+"&email="+email, 
			success: function(msg){
				if(msg == "1") { 
					$.ajax({ 
						type: "POST",
						url: "http://api.mailchimp.com/1.2/?method=listSubscribe&apikey=d160e7bfd77adf96f8c1482d91b0a9de-us1&id=58d88c7cf7&email_address="+email+"&merge_vars[FNAME]="+fname+"&merge_vars[LNAME]="+lname+"&double_optin=false&output=json",
						data: "FNAME="+fname+"&LNAME="+lname+"&EMAIL="+email
					}); 
					 $.ajax({
                                                type: "POST",
                                                url: "http://api.mailchimp.com/1.2/?method=listSubscribe&apikey=d160e7bfd77adf96f8c1482d91b0a9de-us1&id=58d88c7cf7&email_address="+email+"&merge_vars[FNAME]="+fname+"&merge_vars[LNAME]="+lname+"&double_optin=false&output=json"
                                        }); 
					$("#your_name").val("");
					$("#your_email").val(""); 
					$("#mailing_list .mail-box").hide();
					$("#mailing_list .mail-btn").hide();
					$("#mailing_list .result").show();
					setTimeout("close_mailing()", 1500);
				}
				else {
					alert(msg);
				}
			}
		}); 
	}
	else {
		alert("Please fill out all fields.");
	}
}

portsub = setTimeout("close_port()", 100); 
portsub2 = setTimeout("close_port()", 100); 
worksub = setTimeout("close_work()", 100); 
cur_sub = 0;
cur_sub2 = 0;

/*
function port_menu_open() {
	adjust_port();
	clearTimeout(portsub);
	$('#port-sub').fadeIn("fast"); 
} 
*/

function port_sub_menu_open(subID) {
	clearTimeout(portsub);
	id = subID.split("|")[1];
	if(id != cur_sub) {
		$('.sub2').hide(); 
		$('.sub3').hide(); 
		$('#sub'+id).fadeIn("fast"); 
		cur_sub = id;
		cur_sub2 = 0;
	}
} 

function port_sub_menu_open2(subID) {
	clearTimeout(portsub);
	id = subID.split("|")[1];
	if(id != cur_sub2) {
		$('.sub3').hide(); 
		$('#sub2'+id).fadeIn("fast"); 
		cur_sub2 = id;
	}
	
} 

function port_menu_close() {
	portsub = setTimeout("close_port()", 1000); 
} 

function close_port() {
	cur_sub = 0;
	clearTimeout(portsub);
	$('.sub2').hide(); 
	$('.sub3').hide(); 
	$('#port-sub').fadeOut("fast");
}

function work_menu_open() {
	clearTimeout(worksub);
	$('#work-sub').fadeIn("fast"); 
} 

function work_menu_close() {
	worksub = setTimeout("close_work()", 1000); 
} 

function close_work() {
	$('#work-sub').fadeOut("fast");
}


function adjust_port() {
	//w = Math.round(($("#port-sub").width() + 8) * 1.02);
	w = $("#port-sub").width() + 10;
	$(".sub2").css("margin-left", w+"px"); 
}


$(document).ready(function() { 
	adjust_port(); 
	$('input').checkBox(); 
	Cufon.replace('h1');
	Cufon.replace('.input_fields');
	Cufon.replace('.input_titles');
	Cufon.replace('.input_titles_small');
	Cufon.replace('.contact_ty');
	Cufon.replace('.required_fields');
	Cufon.replace('.reg_notes');
	Cufon.replace('.returning_users');
	Cufon.replace('.details');
	Cufon.replace('.thumbnail_block .title');
	Cufon.replace('.workshop_content .title');
	Cufon.replace('.workshop_content .date');
	Cufon.replace('.description_block .price');
	Cufon.replace('#blog_content .posted .title'); 
	Cufon.replace('#blog_content .posted .title a', { hover: true, hoverables: { a: true } }); 
	Cufon.replace('#blog_content .posted .date');
	Cufon.replace('#blog_content .posted .category');
	Cufon.replace('#blog_content .blog_content_footer'); 
	Cufon.replace('#blog_content .blog_content_footer a', { hover: true, hoverables: { a: true } }); 
	Cufon.replace('button');
	Cufon.replace('#content_container .send_button');
	Cufon.replace('#content_container .join_button');
	Cufon.replace('#content_container .login_button');
	Cufon.replace('#right_column #title');
	Cufon.replace('.right_column');
	Cufon.replace('#disclaimer');
	Cufon.replace('#table .title');
	Cufon.replace('#table .total_title');
	Cufon.replace('#discount .discount_title');
	Cufon.replace('#info #posts .title'); 
	Cufon.replace('#info #posts .title2'); 
	Cufon.replace('#error');
	Cufon.replace('#login_error');
	Cufon.replace('#register-ty');
	Cufon.replace('.shipping_col');
	Cufon.replace('#table td'); 
	Cufon.replace('#portfolio-options .btn a',{ hover: true, hoverables: { a: true } }); 
	Cufon.replace('#main_nav a', { hover: true, hoverables: { a: true } }); 
	Cufon.replace('span.port-item');
	Cufon.replace('span.port-item2');
	Cufon.replace('#account_links a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#footer_links1 a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#footer_links2 a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#footer_links_simple a', { hover: true, hoverables: { a: true } });
	Cufon.replace('.description_price a.txt', { hover: true, hoverables: { a: true } });
	Cufon.replace('.description_price span.label');
	Cufon.replace('.description_price2 a', { hover: true, hoverables: { a: true } });
	Cufon.replace('.thumbnail_block .links a', { hover: true, hoverables: { a: true } });
	Cufon.replace('.setup_account a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#blog_menu a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#left_column .links a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#right_column #posts a', { hover: true, hoverables: { a: true } });
	Cufon.replace('.left_column #categories li .title', { hover: true, hoverables: { a: true } }); 
	Cufon.replace('#commentform label');
	Cufon.replace('h3#comments');
	Cufon.replace('#content h3');
	Cufon.replace('#respond h3');
	Cufon.replace('h2.pagetitle'); 
	Cufon.replace('#terms h2'); 
	Cufon.replace('#search_content .hdr');
	Cufon.replace('#search_content .pages');
	Cufon.replace('#search_content .search_item a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#search_content .paging');
	Cufon.replace('#search_content .paging a', { hover: true, hoverables: { a: true } });
	Cufon.replace('#myaccount .left_column a', { hover: true, hoverables: { a: true } });
	Cufon.replace('b.workshop_title');


	$('#port-nav').mouseover(function() { 
		port_menu_open();
	}); 
	$('#port-nav').mouseout(function() { 
		port_menu_close();
	}); 
	$('#port-nav-on').mouseover(function() { 
		port_menu_open();
	}); 
	$('#port-nav-on').mouseout(function() { 
		port_menu_close();
	}); 
	$('#port-sub').mouseover(function() { 
		port_menu_open();
	}); 
	$('#port-sub').mouseout(function() { 
		port_menu_close();
	}); 

	$('.port-item').mouseover(function() { 
		currentId = $(this).attr('id');
		port_sub_menu_open(currentId);
	}); 
	$('.port-item2').mouseover(function() { 
		currentId = $(this).attr('id');
		port_sub_menu_open2(currentId);
	});

	$('#work-nav').mouseover(function() { 
		work_menu_open();
	}); 
	$('#work-nav').mouseout(function() { 
		work_menu_close();
	}); 
	$('#work-nav-on').mouseover(function() { 
		work_menu_open();
	}); 
	$('#work-nav-on').mouseout(function() { 
		work_menu_close();
	}); 
	$('#work-sub').mouseover(function() { 
		work_menu_open();
	}); 
	$('#work-sub').mouseout(function() { 
		work_menu_close();
	}); 


});


