<?php 

/**
 * Page alter.
 */
function ucc_2016_page_alter($page) {
	$mobileoptimized = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'MobileOptimized',
		'content' =>  'width'
		)
	);
	$handheldfriendly = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'HandheldFriendly',
		'content' =>  'true'
		)
	);
	$viewport = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'viewport',
		'content' =>  'width=device-width, initial-scale=1'
		)
	);
	drupal_add_html_head($mobileoptimized, 'MobileOptimized');
	drupal_add_html_head($handheldfriendly, 'HandheldFriendly');
	drupal_add_html_head($viewport, 'viewport');
}

/**
 * Preprocess variables for html.tpl.php
 */
function ucc_2016_preprocess_html(&$variables) {
	
    /**
	 * Add IE8 Support
	 */
	drupal_add_css(
        path_to_theme() . '/css/ie8.css', 
        array(
            'group' => CSS_THEME, 
            'browsers' => array('IE' => '(lt IE 9)', '!IE' => FALSE), 
            'preprocess' => FALSE
        )
    );
    
	/**
	* Bootstrap CDN
	*/
  if (theme_get_setting('bootstrap_css_cdn', 'ucc_2016')) {
      $cdn = '//maxcdn.bootstrapcdn.com/bootstrap/' . theme_get_setting('bootstrap_css_cdn', 'ucc_2016')  . '/css/bootstrap.min.css';
      drupal_add_css($cdn, array('type' => 'external'));
  }
  
  if (theme_get_setting('bootstrap_js_cdn', 'ucc_2016')) {
      $cdn = '//maxcdn.bootstrapcdn.com/bootstrap/' . theme_get_setting('bootstrap_js_cdn', 'ucc_2016')  . '/js/bootstrap.min.js';
      drupal_add_js($cdn, array('type' => 'external'));
  }
	
	/**
	* Add Javascript for enable/disable scrollTop action
	*/
	if (theme_get_setting('scrolltop_display', 'ucc_2016')) {

		drupal_add_js('
    jQuery(document).ready(function($) { 
		  $(window).scroll(function() { 
  			 if($(this).scrollTop() != 0) { $("#toTop").fadeIn(); } 
         else { $("#toTop").fadeOut(); }
  		});
  		$("#toTop").click(function() {
  			$("body,html").animate({scrollTop:0},800);
  		});
		});
    ',
		array('type' => 'inline', 'scope' => 'header'));
	}
	//EOF:Javascript
}

/**
 * Override or insert variables into the html template.
 */
function ucc_2016_process_html(&$vars) {
	// Hook into color.module
	if (module_exists('color')) {
	_color_html_alter($vars);
	}
}

/**
 * Preprocess variables for page template.
 */
function ucc_2016_preprocess_page(&$variables) {

	/**
	 * insert variables into page template.
	 */
	if($variables['page']['sidebar_first'] && $variables['page']['sidebar_second']) { 
		$variables['sidebar_grid_class'] = 'col-md-3';
		$variables['main_grid_class'] = 'col-md-6';
	} elseif ($variables['page']['sidebar_first'] || $variables['page']['sidebar_second']) {
		$variables['sidebar_grid_class'] = 'col-md-4';
		$variables['main_grid_class'] = 'col-md-8';		
	} else {
		$variables['main_grid_class'] = 'col-md-12';			
	}
  //*/
  
  if(isset($variables['node']->type)):
  switch($variables['node']->type):
  
    case 'landing_page':
      $variables["theme_hook_suggestions"][] = 'page__landingpage';
      break;
  
    case 'school':
      $variables["theme_hook_suggestions"][] = 'page__school';
      break;

    case 'program':
      $variables["theme_hook_suggestions"][] = 'page__program';
      break;    
    
  endswitch;
  endif;
    
}

/**
 * Override or insert variables into the page template.
 */
function ucc_2016_process_page(&$variables) {
  // Hook into color.module.
  if (module_exists('color')) {
    _color_page_alter($variables);
  }
}

/**
 * Preprocess variables for block.tpl.php
 */
/*function ucc_2016_preprocess_block(&$variables) {
	
}* /
function ucc_2016_preprocess_block(&$variables) {
  $variables['classes_array'][]='clearfix';
  $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->region; 
  $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module; 
  $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->delta; 
  // Add block description as template suggestion $block = block_custom_block_get($variables['block']->delta); 
  // Transform block description to a valid machine name if (!empty($block['info'])) { setlocale(LC_ALL, 'en_US'); 
  // required for iconv() $variables['theme_hook_suggestions'][] = 'block__' . str_replace(' ', '_', strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $block['info']))); } 
} 
//*/

/**
 * Override theme_breadrumb().
 *
 * Print breadcrumbs as a list, with separators.
 * /
function ucc_2016_breadcrumb($variables) {
	$breadcrumb = $variables['breadcrumb'];
	if (!empty($breadcrumb)) {
		$breadcrumb[] = drupal_get_title();
		$breadcrumbs = '<ol class="breadcrumb">';
		$count = count($breadcrumb) - 1;
		foreach ($breadcrumb as $key => $value) { $breadcrumbs .= '<li>' . $value . '</li>'; }
		$breadcrumbs .= '</ol>';
		return $breadcrumbs;
	}
}
//*/

/**
 * Search block form alter.
 */
function ucc_2016_form_alter(&$form, &$form_state, $form_id) {
	if ($form_id == 'search_block_form') {
	 unset($form['search_block_form']['#title']);
   unset($form['search_block_form']['#size']);
   $form['search_block_form']['#title_display'] = 'invisible';
   $form_default = t('Search this website...');
   $form['search_block_form']['#default_value'] = $form_default;
   $form['actions']['submit']['#attributes']['value'][] = '';
   $form['search_block_form']['#attributes'] = array(
    'onblur' => "if (this.value == '') {this.value = '{$form_default}';}",
    'onfocus' => "if (this.value == '{$form_default}') {this.value = '';}"
   );
	}
}
  