<?php

/*
* Implementation of hook_user()
*
*/
function framerefresh_user($op, &$edit, &$account, $category = NULL) {
global $base_url;
$URL = $base_url;
global $user;
$UserName = $user->name;
$TopFrame = variable_get('framerefresh_top_frame','playerFrame');
$ContentFrame = variable_get('framerefresh_content_frame','contentFrame');


  switch ($op) {
    case 'logout':
	print "<script type=\"text/javascript\">top.frames['$TopFrame'].location.reload();top.frames['$ContentFrame'].location = '$URL/user';</script>";
	drupal_set_message("You have successfully logged out.  See you next time!");
    break;
	case 'login':
    print "<script type=\"text/javascript\">top.frames['$TopFrame'].location.reload();top.frames['$ContentFrame'].location = '$URL/user';</script>";
	drupal_set_message("Hi $UserName, welcome back to Plexphonic!");
    break;
  }
}

function framerefresh_menu() {

  $items = array();

  $items['admin/settings/framerefresh'] = array(
    'title' => 'Configure Frame Refresh',
    'description' => 'Set the names of your frames so that Frame Refresh can maintain their states for you.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('framerefresh_admin'),
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
   );

  return $items;
}

function framerefresh_admin() {
  $form = array();
  $form['framerefresh_top_frame'] = array(
    '#type' => 'textfield',
    '#title' => t('Top Frame Name'),
	'#default_value' => variable_get('framerefresh_top_frame', ''),
    '#size' => 30,
	'#maxlength' => 30,
    '#description' => t('For example:  playerFrame'),
	'#required' => FALSE
  );
  $form['framerefresh_content_frame'] = array(
    '#type' => 'textfield',
    '#title' => t('Content Frame Name'),
	'#default_value' => variable_get('framerefresh_content_frame', ''),
    '#size' => 30,
	'#maxlength' => 30,
    '#description' => t('For example:  contentFrame'),
	'#required' => FALSE
  );
  
  return system_settings_form($form);
}