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();

		break;
		case 2://images
			$('#manage_fonts').hide();
			$('#font_fields').hide();
			$('#image_fields').show();
			$('#homepage_feature_checkbox').show();
		break;
	}
}

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(){
	$('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')})
})

