$(document).ready(function() {
    // generate page titles based on the h1 tag
    // if this is the homepage display the site name first
    // otherwise display the page name first
    // for some reason the title coming from the admin system is adding
    // a newline before the text, so trim it.
    
    // figure out if we're on the english or french site
	var lang = 'en';
	if ($('title').html().indexOf('Boeuf') > 0 || $('title').html().indexOf('boeuf') > 0) {
	  lang = 'fr';
	}
	
	var text = {
		title: {
			en: 'Canadian Beef',
			fr: 'Boeuf Canadien'
		},
		slogan: {
			en: 'Goodness in every bite',
			fr: 'Toujours bon pour vous'
		}
	};
    
    // grab the h1 tag, if it doesn't exist grab the existing title tag
    if ($('h1').length > 0) {
        var title = $('h1').html();
    } else {
        var title = $('title').html();
    }
	
	// the french page titles have some extra text, remove it
	// string: 'Centre d'information sur le boeuf - '
	if (lang == 'fr' && title.indexOf('information sur le boeuf') > 0) {
		title = title.replace('Centre d\'information sur le boeuf - ', '');
	}
	
	// by default display 'pagename | sitename'
	// if this is the homepage, display 'sitename | slogan'
	// for some reason the title coming from the admin system is adding a
	// newline before the text, so trim it.
	if (title.indexOf('Goodness in every bite') > 0 || title.indexOf('Accueil') > 0) {
		var title = text['title'][lang] + ' | ' + text['slogan'][lang];
	} else {
		var title = jQuery.trim(title) + ' | ' + text['title'][lang];
	}
	
    // IE has a different way of referencing the title tag
    if ($.browser.msie) {
		document.title = title;
    } else {
		jQuery('title').html(title);
    }
    
    // add meta tags for SEO & Facebook sharing purposes
    // http://www.lexiconn.com/blog/2009/11/addthis-share-with-facebook-passing-title-description-and-thumbnail-image
    // http://wiki.developers.facebook.com/index.php/Facebook_Share/Specifying_Meta_Tags
    
    $('meta[name=title]').attr('content', title);
    $('meta[name=description]').attr('content',  $('.intro').html());
    
    //title_tag.after('<meta name="title" content="' + title + '" />');
    //$('meta[name=title]').after('<meta name="description" content="' + $('.intro').html() + '" />');
    
    //.NET automatically renders an inline 'style' attribute as follows:
    // style="border-width:0px;"  <-- get rid of it
    $('img').removeAttr('style');
    
    // add the header image to be used for Facebook sharing
    // only recipes header images have a selector, so add one if it doesn't exist.
    /*if ($('img.headerimage').length == 0) {
        $('#MidCenterCol .content img').attr('class', 'headerimage');
    }
    
    if ($('img.headerimage').length > 0) {
        var img = 'http://www.beefinfo.org' + $('img.headerimage').attr('src');
        $('meta[name=description]').after('<link rel="image_src" href="' + img + '" />');
    }*/
    
});