<!-- bectin -->
<?php
// This code sets the background images of the body tag to be the full_text image from the article.
// If no article is assigned, it chooses the image from the first article in the category of the selected article.
// If the first article in the category doesn't have an image then it chooses the default.
    $app = JFactory::getApplication();

    if($app->input->getCmd('option') == "com_content" && $app->input->getCmd('view') == "article" ) {
        $article_id = $app->input->getCmd('id');
    
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select($db->quoteName('catid'));
        $query->from($db->quoteName('#__content'));
        $query->where($db->quoteName('id') . ' = '. $db->quote($article_id));
        $db->setQuery($query);
        $cat_id = $db->loadResult();
    
    
    // if the current page has an assigned background photo
        $article = JTable::getInstance("content");
        $article->load(JRequest::getInt("id")); // Get Article ID
        
        $article_images = $article->get("images"); // Get image parameters
        $pictures = json_decode($article_images); // Split the parameters apart
        // Print the image
        if ($pictures->{'image_fulltext'}!='') // there is an image in the image_fulltext field
        {
        echo "<style> body {background: url('../" . $pictures->{'image_fulltext'} . $pictures->{'image_fulltext_alt'} . "');background-attachment: fixed; color: #444;}</style>";
        }
        
        else
        {
        //If the current article does not have an assigned background photo choose category image
    
            $query="SELECT params FROM #__categories WHERE id=$cat_id";
            $db->setQuery($query);
            $db->query();
            $article_images= $db->loadAssocList();
            $pictures = json_decode($article_images[0][params]); // Split the parameters apart
            if ($pictures->{'image'}!='') // there is an image in the image field
            {
            echo "<style> body {background: url('../" . $pictures->{'image'} . "');background-attachment: fixed; color: #444;}</style>";
            }
            else
            {
                echo "<style> body {background: url('/images/backgrounds/bg2000.jpg');background-attachment: fixed; color: #444;}</style>";            
            }
        }
    }
// set background for contacts
    $option   = JRequest::getCmd('option');
    $view   = JRequest::getCmd('view');        
    if ($view=='contact') echo "<style> body {background: url('/images/backgrounds/run.jpg');background-attachment: fixed; color: #444;}</style>";
?>
<!-- end bectin -->