<?php  

function quasar_preprocess_search_block_form(&$variables) {
  $variables['form']['search_block_form']['#title'] = '';
  $variables['form']['search_block_form']['#size'] = 30;
  $variables['form']['search_block_form']['#value'] = 'search...';
  $variables['form']['search_block_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = '".$variables['form']['search_block_form']['#value']."';}", 'onfocus' => "if (this.value == '".$variables['form']['search_block_form']['#value']."') {this.value = '';}" );
  unset($variables['form']['search_block_form']['#printed']);

  $variables['search']['search_block_form'] = drupal_render($variables['form']['search_block_form']);

  $variables['search_form'] = implode($variables['search']);
}

function quasar_blocks($region) {
  $output = '';

  if ($list = block_list($region)) {
    $blockcounter = 1; // there is at least one block in this region
    foreach ($list as $key => $block) {
      // $key == <i>module</i>_<i>delta</i>
      $block->extraclass = ''; // add the 'extracclass' key to the $block object
      $block->num_count = 0;
      if ($blockcounter == 1){ // is this the first block in this region?
        $block->extraclass .= 'first'; 
      }
      elseif ($blockcounter == count($list)){ // is this the last block in this region?
        $block->extraclass .= 'last';
      }
      else {
      	$block->extraclass .= 'middle';
      }
      
      
      $output .= theme('block', $block);
      $blockcounter++;
    }
   
  }

  // Add any content assigned to this region through drupal_set_content() calls.
  $output .= drupal_get_content($region);

  return $output;
}


// Preprocess variables for node.tpl.php.
function quasar_preprocess_node(&$variables) {

// Let's get that read more link out of the generated links variable!
  unset($variables['content']['links']['node']['#links']['node-readmore']);

// Now let's put it back as it's own variable! So it's actually versatile!
    $variables['newreadmore'] = t('<div class="readon"><a href="!title" class="button">Read More</a> </div>',
      array(
        '!title' => $variables['node_url'],
      )
);
}

function quasar_preprocess_block(&$variables){
	
	$variables['block_count'] = count(block_list($variables['block']->region));
	
	if ($variables['block']->position_first){
		$variables['classes_array'][] = 'first';
	}
	if ($variables['block']->position_last){
	    $variables['classes_array'][] = 'last';
	}
}

function quasar_page_alter(&$page) {
  // Determine the position and count of blocks within regions.
  foreach ($page as &$region) {
    // Make sure this is a "region" element.
    if (is_array($region) && isset($region['#region'])) {
      $i = 0;
      foreach ($region as &$block) {
        // Make sure this is a "block" element.
        if (is_array($block) && isset($block['#block'])) {
          $block['#block']->position = $i++;
          // Set a flag for "first" and "last" blocks.
          $block['#block']->position_first = ($block['#block']->position == 0);
          $block['#block']->position_last = FALSE;
          $last_block =& $block;
        }
      }
      $last_block['#block']->position_last = TRUE;
      $region['#block_count'] = $i;
    }
  }
}

function quasar_preprocess_maintenance_page(&$vars) {
	quasar_preprocess($vars);
}

function quasar_preprocess(&$variables) {
	
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$variables['platform'] = _checkPlatform($user_agent);
	$thisBrowser = _checkBrowser($user_agent);
	$variables['browser_name'] = $thisBrowser[0];
	$variables['browser_version'] = $thisBrowser[1];
    $variables['browser_engine'] = _checkEngine($thisBrowser[0]);
	
	variable_set('thisTitle', "");
	$menus = menu_tree_page_data('main-menu'); 
	foreach($menus as $menu) {
	    //echo $menu['link']['title'] . " : " . $menu['link']['in_active_trail'];
	    if(!empty($menu['link']['in_active_trail']) AND $menu['link']['has_children']) {
	        variable_set('thisTitle', $menu['link']['title']);
	    }
	}
	
	
	$variables['path'] = base_path() . path_to_theme();
	$css_path = path_to_theme().'/css/';
	$js_path = path_to_theme() . '/js/';
	/*$variables['url'] = "http://" . $_SERVER['HTTP_HOST'] . url();*/
    $variables['uri'] = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    
    $variables['tabs2'] = menu_secondary_local_tasks();
	
	global $stylesList;
	
									
	$stylesList = array (
	    
	    'preset1' => array (
	        'name' => 'Preset 1',
	        'css_style' => 'style1',
	        'link_color' => '#3D9FD0',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    ),
	    'preset2' => array (
	        'name' => 'Preset 2',
	        'css_style' => 'style2',
	        'link_color' => '#3D9FD0',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    ),
	    'preset3' => array (
	        'name' => 'Preset 3',
	        'css_style' => 'style3',
	        'link_color' => '#71A311',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    ),
	    'preset4' => array (
	        'name' => 'Preset 4',
	        'css_style' => 'style4',
	        'link_color' => '#71A311',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    ),
	    'preset5' => array (
	        'name' => 'Preset 5',
	        'css_style' => 'style5',
	        'link_color' => '#cc0000',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    ),
	    'preset6' => array (
	        'name' => 'Preset 6',
	        'css_style' => 'style6',
	        'link_color' => '#cc0000',
	        'font_family' => 'lucida',
	    	'background_level' => 'high',
	    	'body_level' => 'high'
	    )
	    
	        
	);
				
	
	// presetstyle
	if( isset( $_COOKIE['quasar_presetstyle'] ) )
		$variables['quasar_presetstyle'] = $_COOKIE['quasar_presetstyle']; 
	else
		$variables['quasar_presetstyle'] = theme_get_setting('presetstyle');
	
	$style = $stylesList[$variables['quasar_presetstyle']];
	
	
	
	if (theme_get_setting('presetstyle') == "custom" OR isset( $_COOKIE['quasar_background_level'])) {
		if( isset( $_COOKIE['quasar_background_level'] ) )
			$variables['quasar_background_level'] = $_COOKIE['quasar_background_level']; 
		else
			$variables['quasar_background_level'] = theme_get_setting('background_level');
	}
	else 
		$variables['quasar_background_level'] = $style['background_level'];
	
	
	if (theme_get_setting('presetstyle') == "custom" OR isset( $_COOKIE['quasar_body_level'])) {
		if( isset( $_COOKIE['quasar_body_level'] ) )
			$variables['quasar_body_level'] = $_COOKIE['quasar_body_level']; 
		else
			$variables['quasar_body_level'] = theme_get_setting('body_level');
	}
	else 
		$variables['quasar_body_level'] = $style['body_level'];

	if (theme_get_setting('presetstyle') == "custom" OR isset( $_COOKIE['quasar_css_style'])) {
		if( isset( $_COOKIE['quasar_css_style'] ) )
			$variables['quasar_css_style'] = $_COOKIE['quasar_css_style']; 
		else
			$variables['quasar_css_style'] = theme_get_setting('css_style');
	}
	else 
		$variables['quasar_css_style'] = $style['css_style'];
		
	if (theme_get_setting('presetstyle') == "custom" OR isset( $_COOKIE['quasar_link_color'])) {
		if( isset( $_COOKIE['quasar_link_color'] ) )
			$variables['quasar_link_color'] = $_COOKIE['quasar_link_color']; 
		else
			$variables['quasar_link_color'] = theme_get_setting('link_color');
	}
	else 
		$variables['quasar_link_color'] = $style['link_color'];
	
	if (theme_get_setting('presetstyle') == "custom" OR isset( $_COOKIE['quasar_font_family'])) {
		if( isset( $_COOKIE['quasar_font_family'] ) )
			$variables['quasar_font_family'] = $_COOKIE['quasar_font_family']; 
		else
			$variables['quasar_font_family'] = theme_get_setting('font_family');
	}
	else 
		$variables['quasar_font_family'] = $style['font_family'];

	if (isset( $_COOKIE['quasar_default_font'])) {
		$variables['quasar_default_font'] = $_COOKIE['quasar_default_font']; 
	}
	else 
		$variables['quasar_default_font'] = theme_get_setting('default_font');		
	
	
	
	
	// set global for menu style if exists
	if( isset( $_COOKIE['quasar_menutype'] ) )
		$variables['quasar_menutype'] = $_COOKIE['quasar_menutype']; 
	else
		$variables['quasar_menutype'] = theme_get_setting('menutype');
	
	
	
	$variables['scripts'] = drupal_get_js();
	$variables['styles'] = drupal_get_css();

	

	if (strpos(request_uri(), 'wrapper') != false){
		$variables['template_file'] = 'page-wrapper';
	}

}

function quasar_getMBgrid($sidebarcount) {
	$mbgrid2 = array('6|6','8|4', '9|3','6|6','4|8', '3|9');
	$mbgrid3 = array('6|3|3', '8|2|2', '3|3|6', '2|2|8');

	$mbCount = $sidebarcount+1;
	
	$mbVar = "mainbodygrid_" . $mbCount;
	$mbNumber = theme_get_setting($mbVar);
	//echo "regions: " . $mbCount . " pulledval: " . $mbNumber;
	
	$maingrid = $sidegrid = $sidegrid2 = $mbNumber;
	
	// 1 REGION
	if($mbCount==1){$maingrid=12;}
	
	// 2 REGIONS 
	elseif($mbCount==2){
		$mbGridSelected = $mbgrid2[$mbNumber];
		//echo $mbGridSelected;
		$mbArray = explode("|", $mbGridSelected);
		// MS
		if($mbNumber < 3) { 
			$maingrid=$mbArray[0]; 
			$sidegrid=$mbArray[1];
		}
		// SM
		else {
			$sidegrid=$mbArray[0];
			$maingrid=$mbArray[1];
		}
	}
	// 3 REGIONS 
	elseif($mbCount==3){
		$mbGridSelected = $mbgrid3[$mbNumber];
		//echo $mbGridSelected;
		$mbArray = explode("|", $mbGridSelected);
		// MS
		if($mbNumber < 2) { 
			$maingrid=$mbArray[0]; 
			$sidegrid=$mbArray[1];
			$sidegrid2=$mbArray[2];
		}
		// SM
		else {
			$sidegrid=$mbArray[0];
			$sidegrid2=$mbArray[1];
			$maingrid=$mbArray[2];
		}
	}
	
	return array($maingrid, $sidegrid, $sidegrid2, $mbNumber);
}

function quasar_restore_defaults() {
	
	$cookie_path = "/";
	foreach($_COOKIE as $key => $value) {
		if(substr($key, 0, 7) == 'quasar_') {
			setcookie($key, '', 1, $cookie_path);
		}
	}
	
	
	drupal_goto('<front>');
}

function quasar_change_theme($change, $changeVal, $page=''){
	

	//change=showcase&styleVar=color2&bglevel=high&preset=style1
	
	$theme_settings = variable_get('theme_quasar_settings', array());
	
	$cookie_prefix = "quasar_";
	$cookie_time = time()+31536000;
	$cookie_path = "/";
	
	
	if($change && $changeVal){
		
		switch ($change){

			
			case 'fontfamily':
			
				$cookie_name = $cookie_prefix . "font_family";
				setcookie($cookie_name, $changeVal, $cookie_time);
			
			break;
			
			case 'tstyle':
				
				
				setcookie("quasar_presetstyle", $changeVal, $cookie_time, $cookie_path);
	
			break;		
	

			case 'menu_type':
				$cookie_name = $cookie_prefix . "menutype";
				setcookie($cookie_name, $changeVal, $cookie_time, $cookie_path);
			
			break;

		}


		
	}
	

	if ($page){
		drupal_goto("node/$page");
	}
	else {
		drupal_goto('<front>');
	}
	
}

function change_font($change, $page=''){

	$cookie_prefix = "quasar_";
	$cookie_time = time()+31536000;
	$cookie_path = "/";
	$cookie_name = $cookie_prefix . "default_font";
	setcookie($cookie_name, $change, $cookie_time, $cookie_path);
	
	$query = "openchooser=1";
	
	if ($page){
		drupal_goto("node/$page", $query);
	}
	else {
		drupal_goto("<front>", $query);
	}
	
}

function GantryBrowser() {
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$variables['platform'] = _checkPlatform($user_agent);
	//$this->_checkBrowser();
    //$this->_checkEngine();

	// add short version
	//if ($this->version != 'unknown') $this->shortversion = substr($this->version, 0, strpos($this->version, '.'));
	//else $this->shortversion = 'unknown';

    //$this->_createChecks();
}

function _checkPlatform($agent) {
	$platform;
	if (preg_match("/iPhone/", $agent) || preg_match("/iPod/", $agent)) {
		$platform = "iphone";
	}
	elseif (preg_match("/iPad/", $agent)) {
		$platform = "ipad";
	}
	elseif (preg_match("/Android/", $agent)) {
		$platform = "android";
	}
	elseif (preg_match("/Mobile/i", $agent)) {
		$platform = "mobile";
	}
	elseif (preg_match("/win/i", $agent)) {
		$platform = "win";
	}
	elseif (preg_match("/mac/i", $agent)) {
		$platform = "mac";
	}
	elseif (preg_match("/linux/i", $agent)) {
		$platform = "linux";
	} else {
		$platform = "unknown";
	}

	return $platform;
}

function _checkEngine($browserName){
    switch($browserName){
        case 'ie':
            $engine = 'trident';
            break;
		case 'minefield':
        case 'firefox':
            $engine = 'gecko';
            break;
        case 'android':
        case 'ipad':
        case 'iphone':
        case 'chrome':
        case 'safari':
            $engine = 'webkit';
            break;
        case 'opera':
            $engine = 'presto';
            break;
        default:
            $engine = 'unknown';
            break;
    }
    
    return $engine;
}

function _checkBrowser($agent) {
	$browser_array = array();
	// IE
	if (preg_match('/msie/i', $agent) && !preg_match('/opera/i', $agent)) {
		$result = explode(' ', stristr(str_replace(';', ' ', $agent), 'msie'));
		$browser_array[0] = 'ie';
		$browser_array[1] = $result[1];
	}
	// Firefox
	elseif (preg_match('/Firefox/', $agent)) {
		$result = explode('/', stristr($agent, 'Firefox'));
		$version = explode(' ', $result[1]);
		$browser_array[0] = 'firefox';
		$browser_array[1] = $version[0];
	}
	// Minefield
	elseif (preg_match('/Minefield/', $agent)) {
		$result = explode('/', stristr($agent, 'Minefield'));
		$version = explode(' ', $result[1]);
		$browser_array[0] = 'minefield';
		$browser_array[1] = $version[0];
	}
	// Chrome
	elseif (preg_match('/Chrome/', $agent)) {
		$result = explode('/', stristr($agent, 'Chrome'));
		$version = explode(' ', $result[1]);
		$browser_array[0] = 'chrome';
		$browser_array[1] = $version[0];
	}
	//Safari
	elseif (preg_match('/Safari/', $agent) && !preg_match('/iPhone/', $agent) && !preg_match('/iPod/', $agent) && !preg_match('/iPad/', $agent)) {
		$result = explode('/', stristr($agent, 'Version'));
		$browser_array[0] = 'safari';
		if (isset ($result[1])) {
			$version = explode(' ', $result[1]);
			$browser_array[1] = $version[0];
		} else {
			$browser_array[1] = 'unknown';
		}
	}
	// Opera
	elseif (preg_match('/opera/i', $agent)) {
		$result = stristr($agent, 'opera');

		if (preg_match('/\//', $result)) {
			$result = explode('/', $result);
			$version = explode(' ', $result[1]);
			$browser_array[0] = 'opera';
			$browser_array[1] = $version[0];
		} else {
			$version = explode(' ', stristr($result, 'opera'));
			$browser_array[0] = 'opera';
			$browser_array[1] = $version[1];
		}
	}
	// iPhone/iPod
	elseif (preg_match('/iPhone/', $agent) || preg_match('/iPod/', $agent)) {
		$result = explode('/', stristr($agent, 'Version'));
		$browser_array[0] = 'iphone';
		if (isset ($result[1])) {
			$version = explode(' ', $result[1]);
			$browser_array[1] = $version[0];
		} else {
			$browser_array[1] = 'unknown';
		}
	}
	// iPad
	elseif (preg_match('/iPad/', $agent)) {
		$result = explode('/', stristr($agent, 'Version'));
		$browser_array[0] = 'ipad';
		if (isset ($result[1])) {
			$version = explode(' ', $result[1]);
			$browser_array[1] = $version[0];
		} else {
			$browser_array[1] = 'unknown';
		}
	}
	// Android
	elseif (preg_match('/Android/', $agent)) {
		$result = explode('/', stristr($agent, 'Version'));
		$browser_array[0] = 'android';
		if (isset ($result[1])) {
			$version = explode(' ', $result[1]);
			$browser_array[1] = $version[0];
		} else {
			$browser_array[1] = "unknown";
		}
	} else {
		$browser_array[0] = "unknown";
		$browser_array[0] = "unknown";
	}
	
	return $browser_array;
}

//********************************************
// PRIMARY LINK MENU ITEM INFO
//********************************************
function main_menu_tree_output($tree) {
  $output = '';
  $items = array();

  if( isset( $_COOKIE['quasar_menutype'] ) )
	$this_mtype = $_COOKIE['quasar_menutype']; 
  else
	$this_mtype = theme_get_setting('menutype');
  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    
    $extra_class = NULL;
    //$extra_class = get_link_color($items[$i]['title']);
    
    if (stristr($i, 'active')) {
        $extra_class .= " active";
      }
    
    
    if ($i == 0) {
      //$extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      //$extra_class = 'last';
    }
    $link = main_menu_item_link($data['link'], $data['link']['has_children']);
   
    if ($data['below']) {
      $extra_class = "parent ";
      if($this_mtype == "splitmenu") {
      	$output .= main_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
      }	
      else {	
      	$output .= main_menu_item($link, $data['link']['has_children'], sub_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
      }
    }
    
    else {
      $output .= main_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }
  }
  return $output ? main_menu_tree($output) : '';
}

function sub_menu_tree_output($tree) {
  if( isset( $_COOKIE['quasar_menutype'] ) )
	$this_mtype = $_COOKIE['quasar_menutype']; 
  else
	$this_mtype = theme_get_setting('menutype');
  
  $output = '';
  $items = array();

  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    
    $extra_class = NULL;
    //$extra_class = get_link_color($items[$i]['title']);
    
    if (stristr($i, 'active')) {
        $extra_class .= " active";
      }
    
    
    if ($i == 0) {
      //$extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      //$extra_class = 'last';
    }
    $link = sub_menu_item_link($data['link'], $data['link']['has_children']);
    if ($data['below']) {
    	$extra_class = " parent f-parent-item f-menuparent-item";
      	if($this_mtype == "dfission" OR $this_mtype == "suckerfish") {
      		$output .= sub_menu_item($link, $data['link']['has_children'], tri_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
    	}
    	else {
    		$output .= sub_menu_item($link, $data['link']['has_children'], sub_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
    	}
    }
    else {
      $output .= sub_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }
  }
  return $output ? sub_menu_tree($output) : '';
}

function tri_menu_tree_output($tree) {
  $output = '';
  $items = array();

  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    
    $extra_class = NULL;
    //$extra_class = get_link_color($items[$i]['title']);
    
    if (stristr($i, 'active')) {
        $extra_class .= " active";
      }
    
    if ($i == 0) {
      //$extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      //$extra_class = 'last';
    }
    $link = tri_menu_item_link($data['link'], $data['link']['has_children']);
    if ($data['below']) {
      $extra_class = " parent ";
      $output .= tri_menu_item($link, $data['link']['has_children'], tri_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
    }
    else {
      $output .= tri_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }
  }
  return $output ? tri_menu_tree($output) : '';
}

//FULL MENU TREE
function main_menu_tree($tree) {	
  	
  	return '<ul class="menu">'. $tree .'</ul>';
}

//SUB MENU TREE
function sub_menu_tree($tree) {
  	$numCols = theme_get_setting('level2cols');
  	return '<div class="fusion-submenu-wrapper level2 columns' . $numCols . '"><div class="drop-top"></div><ul class="level2 columns' . $numCols . '">'. $tree .'</ul></div>';
}

//TRI MENU TREE
function tri_menu_tree($tree) {
	$numCols = theme_get_setting('level3cols');
  	return '<div class="fusion-submenu-wrapper level3 columns' . $numCols . '"><div class="drop-top"></div><ul class="level3 columns' . $numCols . '">'. $tree .'</ul></div>';
}

//MENU ITEM 
function main_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  //$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  $class = "item";
  $id = "";
  if (!empty($extra_class)) {
    $class .= " " . $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active';
  }
  
  $class .= " root f-main-parent f-mainparent-item";
  
  	
  return '<li class="'. $class .'">'. $link . $menu . "</li>\n";
	

}

//SUB MENU ITEM 
function sub_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  //$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  $class = "";
  if (!empty($extra_class)) {
    $class .= $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active';
  }
  return '<li class=" item1 f-submenu-item'. $class .'">'. $link . $menu . "</li>\n";
}

//TRI MENU ITEM
function tri_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  //$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  $class = "";
  if (!empty($extra_class)) {
    $class .= $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active';
  }
  return '<li class="'. $class .' item1 f-submenu-item">'. $link . $menu . "</li>\n";
}

function main_menu_item_link($link, $has_children = FALSE) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if(strlen(strstr($link['href'],"http"))>0) {
  	$href = $link['href'];	
  }
  else {
  	if(variable_get('clean_url', 0)) {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
  	}
  	else {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . "?q=" . drupal_get_path_alias($link['href']);
  	}
  }
  
  $subtext = $link['localized_options']['attributes']['title'];
  
  $class = "orphan item bullet";
  
  if($link['title'] == $subtext) {
  	$subtext = "";
  }
  
  $this_link = "<a class='" . $class . "' href='" . $href . "' title='" . $subtext . "'><span>" . $link['title'] . "</span></a>";
 
  
  //return l($link['title'], $link['href'], $link['localized_options']);
  return $this_link;
}

function sub_menu_item_link($link, $has_children = FALSE) {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $thisBrowser = _checkBrowser($user_agent);
    $browser_name = $thisBrowser[0];
    $browser_version = $thisBrowser[1];
    $ver = preg_replace ('/\.(.*)/','',$browser_version);
    $bname = $browser_name . $ver;

  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if(strlen(strstr($link['href'],"http"))>0) {
  	$href = $link['href'];	
  }
  else {
  	if(variable_get('clean_url', 0)) {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
  	}
  	else {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . "?q=" . drupal_get_path_alias($link['href']);
  	}
  }	
  
  $subtext = $link['localized_options']['attributes']['title'];
  
  if($link['title'] == $subtext) {
  	$subtext = "";
  }

  $class = "";
  
  if($subtext != "") {
  	$class .= "subtext ";
  }
  
  
  if($has_children) {
  	$class .= "daddy ";
  }
  else {
  	$class .= "orphan ";
  }
  
  $class .= "item bullet";
  if($bname == "ie7"){
  	$this_link = "<a class='" . $class . "' href='" . $href . "' title='" . $subtext . "'>" . $link['title'] . "</a>";
  
  }
  else {
    $this_link = "<a class='" . $class . "' href='" . $href . "' title='" . $subtext . "'><span>" . $link['title'] . "</span></a>";
    
    
  }
  //return l($link['title'], $link['href'], $link['localized_options']);
  return $this_link;
}

function tri_menu_item_link($link, $has_children = FALSE) {
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $thisBrowser = _checkBrowser($user_agent);
    $browser_name = $thisBrowser[0];
    $browser_version = $thisBrowser[1];
    $ver = preg_replace ('/\.(.*)/','',$browser_version);
    $bname = $browser_name . $ver;

  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if(strlen(strstr($link['href'],"http"))>0) {
  	$href = $link['href'];	
  }
  else {
  	if(variable_get('clean_url', 0)) {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
  	}
  	else {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . "?q=" . drupal_get_path_alias($link['href']);
  	}
  }	
  
  $subtext = $link['localized_options']['attributes']['title'];
  
  if($link['title'] == $subtext) {
  	$subtext = "";
  }
  
  
  $class = "";
  
  if($subtext != "") {
  	$class .= "subtext ";
  }
  
  if($has_children) {
  	$class .= "daddy ";
  }
  else {
  	$class .= "orphan ";
  }
  
  $class .= "item bullet";

  if($bname == "ie7"){
    $this_link = "<a class='" . $class . "' href='" . $href . "' title='" . $subtext . "'>" . $link['title'] . "</a>";

  }
  else {
    $this_link = "<a class='" . $class . "' href='" . $href . "' title='" . $subtext . "'><span>" . $link['title'] . "</span></a>";
    
    
  }

  //return l($link['title'], $link['href'], $link['localized_options']);
  return $this_link;
}

//******************************************************************************

//********************************************
// SECONDARY LINK MENU ITEM INFO
//********************************************

function sec_menu_tree_output($tree) {
  $output = '';
  $items = array();

  if( isset( $_COOKIE['quasar_menu_type'] ) )
	$this_mtype = $_COOKIE['quasar_menu_type']; 
  else
	$this_mtype = theme_get_setting('menu_type');
  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    
    $extra_class = NULL;
    //$extra_class = get_link_color($items[$i]['title']);
    
    if (stristr($i, 'active')) {
        $extra_class .= " active";
      }
    
    
    if ($i == 0) {
      //$extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      //$extra_class = 'last';
    }
    $link = sec_menu_item_link($data['link'], $data['link']['has_children']);
    
    $output .= sec_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    
  }
  return $output ? sec_menu_tree($output) : '';
}

//FULL MENU TREE
function sec_menu_tree($tree) {
  	return '<div class="moduletable"><ul id="mainlevel-top">'. $tree .'</ul></div>';
}

//MENU ITEM 
function sec_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  //$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  $class = "item1 png";
  $id = "";
  if (!empty($extra_class)) {
    $class .= " " . $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active';
    $id .= 'current';
  }
  if($id == ""){
  	return '<li class="'. $class .'">'. $link . $menu . "</li>\n";
  }
  else {
  	return '<li id="' . $id . '" class="'. $class .'">'. $link . $menu . "</li>\n";
  }
}
 
function sec_menu_item_link($link, $has_children = FALSE) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if(strlen(strstr($link['href'],"http"))>0) {
  	$href = $link['href'];	
  }
  else {
  	if(variable_get('clean_url', 0)) {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
  	}
  	else {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . "?q=" . drupal_get_path_alias($link['href']);
  	}
  }
  
  $subtext = $link['localized_options']['attributes']['title'];
  
  $this_link = "<a class='mainlevel-top' href='" . $href . "' title='" . $subtext . "'><span class='banner-big'>" . $link['title'] . "</span><span class='banner-small'>" . $subtext . "</span></a>"; 	
  //return l($link['title'], $link['href'], $link['localized_options']);
  return $this_link;
}

//******************************************************************************

//********************************************
// SPLIT MENU ITEM INFO
//********************************************
function split_menu_tree_output($tree) {
  $output = '';
  $items = array();

  if( isset( $_COOKIE['quasar_menu_type'] ) )
	$this_mtype = $_COOKIE['quasar_menu_type']; 
  else
	$this_mtype = theme_get_setting('menu_type');
  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    
    $extra_class = NULL;
    //$extra_class = get_link_color($items[$i]['title']);
    
    if (stristr($i, 'active')) {
        $extra_class .= " active";
      }
    
    
    if ($i == 0) {
      //$extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      //$extra_class = 'last';
    }
    $link = split_menu_item_link($data['link'], $data['link']['has_children']);
    
    $output .= split_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    
  }
  return $output ? split_menu_tree($output) : '';
}

//FULL MENU TREE
function split_menu_tree($tree) {
  	return '<ul class="menu level1">'. $tree .'</ul>';
}

//MENU ITEM 
function split_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  //$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  $class = "";
  $id = "";
  if (!empty($extra_class)) {
    $class .= " " . $extra_class;
  }
  if ($in_active_trail) {
    $class .= 'active';
    $id .= 'current';
  }
  if($id == ""){
  	return '<li class="'. $class .'">'. $link . $menu . "</li>\n";
  }
  else {
  	return '<li id="' . $id . '" class="'. $class .'">'. $link . $menu . "</li>\n";
  }
}
 
function split_menu_item_link($link, $has_children = FALSE) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  if(strlen(strstr($link['href'],"http"))>0) {
  	$href = $link['href'];	
  }
  else {
  	if(variable_get('clean_url', 0)) {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
  	}
  	else {
  		$href = $link['href'] == "<front>" ? base_path() : base_path() . "?q=" . drupal_get_path_alias($link['href']);
  	}
  }
  
  $subtext = $link['localized_options']['attributes']['title'];
  
  $this_link = "<a class='item' href='" . $href . "' title='" . $subtext . "'><span>" . $link['title'] . "</span></a>"; 	
  //return l($link['title'], $link['href'], $link['localized_options']);
  return $this_link;
}

//******************************************************************************


function quasar_links__system_navigation_menu($variables) {
  $output = '';
  foreach ($variables['links'] as $link) {
    $output .= l($link['title'], $link['href'], $link);
  }
  return $output;
}

function quasar_views_view_field_Showcase($view, $type, $nodes) {

    $fields = _views_get_fields();
    $output .= '<div id="info"></div><ul id="test-list">';
    foreach ($nodes as $node) {
        $item = "";
        $i = $node->nid;
        foreach ($view->field as $field) {
            $item .= views_theme_field("views_handle_field",$field['queryname'], $fields, $field, $node, $type);
        }
        $output .= '<li id="listItem_'.$i.'"><div class="handle" />'.$item.'</div></li>';
    }
    $output .= '</ul>';

return $output;
}


function quasar_user_login_block($form) {
  $form['name']['#title'] = t(''); //wrap any text in a t function
  $form['name']['#value'] = t('Username');
  $form['pass']['#title'] = t('');
  $form['pass']['#value'] = t('Password');
  $form['submit']['#title'] = t('submit');  
  //unset($form['links']['#value']); //remove links under fields
  return (drupal_render($form));
}


function quasar_button($variables) {
  $element = $variables['element'];
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'Button form-' . $element['#button_type'] . ' ' . $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'Button form-' . $element['#button_type'];
  }

  // Skip admin pages due to some issues with ajax not being able to find buttons.
  if (arg(0) == 'admin') {
    //return '<input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ') .'id="'. $element['#id'] .'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) ." />\n";
  }
  
  if ($element['#value'] == 'Search') {
    return '<input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ') .'id="'. $element['#id'] .'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) ." />\n";
  }

  return '<div class="readon"><input class="button" type="submit" ' . (empty($element['#name']) ? '' : 'name="' . $element['#name']
         . '" ')  . 'id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . '" ' . ' />'
         
         /*
         . '<span class="btn">'
         . '<span class="l"></span>'
         . '<span class="r"></span>'
         . '<span class="t">' . check_plain($element['#value']) . '</span>'
         . '</span></button>';
         */
         
        //.  check_plain($element['#value']) 
		. '</div>';

}



function quasar_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
    //$crumbs = '<div class="breadcrumb">';
    $crumbs = "";
    $array_size = count($breadcrumb);
    $i = 0;
    while ( $i < $array_size) {
     
      
          //$crumbs .= '<div class="breadcrumb-wrapper"><div class="module-l"><div class="module-r"><div class="module-inner"><div class="module-inner2">';
          if ($i == 0) {
            //$crumbs .= ' first';
          }
          /* if ($i+1 == $array_size) {
            $crumbs .= ' last';
          } */
          $crumbs .=  $breadcrumb[$i] . '<img src="' . base_path() . path_to_theme() . '/images/arrow.png">';
      
      
      $i++;
    }
    $crumbs .= '<span class="no-link">'. drupal_get_title() .'</span>';
    
    return '<div class="rt-breadcrumb-surround"><a id="breadcrumbs-home" href="' . base_path() . '"></a><span class="breadcrumbs pathway">' . $crumbs . '</span></div>';
  }
  

}



function quasar_adv_count_words($str) {
	$words = 0;
	$str = eregi_replace(" +", " ", $str);
	$array = explode(" ", $str);
	for($i=0;$i < count($array);$i++) {
		if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i]))
		$words++;
	}
	return $words;
}	


function quasar_comment_submitted($comment) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $comment),
      '!datetime' => format_date($comment->timestamp)
    ));
}

function quasar_node_submitted($node) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $node),
      '!datetime' => format_date($node->created),
    ));
}