function toggleFontImageFields(selectElement){
	v = parseInt($(selectElement).val());
	switch(v){
		case 1://fonts
			$('#font_fields').show();
			$('#manage_fonts').show();
			$('#image_fields').hide();
			$('#homepage_feature_checkbox').hide();
			$('#image_assignment_options').hide();
		break;
		case 2://images
			$('#font_fields').hide();
			$('#manage_fonts').hide();
			$('#image_fields').show();
			$('#homepage_feature_checkbox').show();
			$('#image_assignment_options').show();
		break;
	}
}

function selectPurchasableFamily(selectElement, u, baseUrl){
	family_select = $(selectElement);
	font_select = $("#image_font_id");
	url = u+"?record_id="+family_select.val();

	if(family_select.val() == "NULL"){
		$("#image_font_id").hide();
		$("#image_font_id").val(0);
		
		return;
	}else{
		$("#image_font_id").show();
	}
	//get styles from ajax request
	$.get(url, function(d, status, req){
		data = JSON.parse(d);	

		//update style list
		//wipe out existing options
		$("#image_font_id option").remove();


		//put in new options
		$("#image_font_id").append($("<option value='NULL'>Please select</option>"));
		$.each(data["fonts"], function(key, values) {
			$("#image_font_id").append($('<option></option>').val(values["id"]).html(values["name"]));			
		});
	});
}

function toggleBookmark(link, url, record_id){
	$.post(url, {'record_id' : record_id}, function(data){
		$(link).replaceWith(data);
	})
	return false;		
}

function bookmark(link, url, record_id){
	$.post(url, {'record_id' : record_id}, function(data){
		$(link).replaceWith(data);
	})
	return false;	
}
function removeBookmark(link, url, record_id){
	$.post(url, {'record_id' : record_id}, function(data){
		// alert(data);
		$(link).replaceWith(data);
	})
	return false;
}

function scrollToEl(el, onComplete) {
	$('html, body').animate({
		scrollTop: el.offset().top
	}, 500, onComplete);
}

function closeStatic() {
  scrollToEl($("#header"), function(){$("#dialog").fadeOut();});
  $("a.static_page").removeClass("active_nav");
}

function openStatic(el) {
//alert(el.name);
//alert($("a[name$='support']").name);
  page = el.attr('name');
  page_title = el.text();
  $("a.static_page").removeClass("active_nav");
  el.addClass("active_nav");

  //get the page contents
  $.get(baseUrl+"page?page="+page, function(data, status, req){
    page_title = page_title + "<a href='javascript:' onclick=\"closeStatic();return false;\" class='ui-dialog-titlebar-close ui-corner-all' role='button'><span class='ui-icon ui-icon-closethick'>close</span></a>"
    $("#dialog .dialog-titlebar").html(page_title)
    $("#dialog .dialog-content").html(data);
    $("#dialog").show();
    scrollToEl($("#footer"));
    $(".dialog-content").scrollTop( 0 );
    // $("#dialog").dialog({title : page_title, dialogClass : "staticDialog"});
  })


}

function togglePurchasable(){
	$("#purchasableDiv").slideToggle();
}

function submitOrder(){
	cart = $("#cart");
	cart.submit();
}

$(function(){
	$('a.static_page').each(function(i, element){
		el = $(element);
	
		//setup click handler for all those that are labeled static pages
		el.click(function(){
                        openStatic($(this));
                        return false;
		})
	})
	$('div.button_link').each(function(i, element){
		el = $(element);
		a = el.find("a")
		href = a.attr('href');
		// a.click(function(){return false;});
		el.click(function(){window.location.replace(href)});
	})
	// $('div.button_link').click(function(){alert('hi')})
})

