<?php
/**
 # ot_ante - 	OT Ante  Template for Joomla 2.5!
 # author 			OmegaTheme.com
 # copyright 		Copyright(C) 2012 - OmegaTheme.com. All Rights Reserved.
 # @license 		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 # Website: 		http://omegatheme.com
 # Technical 		support: Forum - http://omegatheme.com/forum/
 **/
 /**------------------------------------------------------------------------
 * file: tpl.function.php 2.5.0 00001, March 2012 12:00:00Z OmegaTheme $
 * package:	OT Ante Template
 *------------------------------------------------------------------------*/
 
//No direct access!
defined( '_JEXEC' ) or die( 'Restricted access' );

//include_once(JPATH_ROOT . "/templates/" . $this->template . '/lib/OtModulesRenderer.php');	

	//Check IE Version for Fix Layout
	function browser()
	{
		$browser = array();
		// what ie browser version?
		if (array_key_exists('HTTP_USER_AGENT', $_SERVER) && preg_match('/(MSIE\\s?([\\d\\.]+))/', $_SERVER['HTTP_USER_AGENT'], $matches))
		{
			$browser['ie9'] = intval($matches[2]) == 9;
			$browser['ie8'] = intval($matches[2]) == 8;
			$browser['ie7'] = intval($matches[2]) == 7;
		}
		return $browser;
	}
	
	function isIe($version)
	{
		$browser = browser();
		if (array_key_exists('ie'.$version, $browser)) {
			return $browser['ie'.$version];
		}
		return false;
	}
	
	//Check Menu default is Home
	function isHome()
	{
		$mnu =& JSite::getMenu();
		return ($mnu->getActive() == $mnu->getDefault());
	}
	
	//Check Frontpage view
	function isFrontpage(){
		return (JRequest::getCmd( 'view' ) == 'frontpage') ;
	}
	
	$menu =& JSite::getMenu();
	$menuHome = $menu->getActive();
	if($menuHome == $menu->getDefault()){
		$home = 'home';
	}else{
		$home = '';
	}
	
	//$layoutView = &JRequest::getVar( 'layoutview' ) == $this->params->get('layoutType');
	
	/*+++++++++++++++++++Layout++++++++++++++++++++*/
	
	$template_url = $this->baseurl.'/templates/'.$this->template;
	
	//Include Main CSS
	$this->addStyleSheet($this->baseurl.'/templates/system/css/system.css');
	$this->addStyleSheet($this->baseurl.'/templates/system/css/general.css');
	$this->addStyleSheet($this->baseurl.'/templates/'.$this->template.'/css/template.css');
	
	//+++++++++++++++++++Configuration Width Template +++++++++++++++++++++++
	$presetCss = '';
	
	if($this->params->get('CustomWidthTemplate') == 1){
		if(trim($this->params->get('width_template')) != ''){
			$presetCss .= 'div.ot-width-temp {width: '.(trim($this->params->get('width_template'))).';}';
		}
		if($this->countModules('left')){
			$presetCss .= 'div.ot-leftcol {width: '.(trim($this->params->get('width_left'))).';}';
		}
		if($this->countModules('right')){
			$presetCss .= 'div.ot-rightcol {width: '.(trim($this->params->get('width_right'))).';}';
		}
	}
	
	//+++++++++++++++++++Extend Modules +++++++++++++++++++++++
	if($this->countModules('bottom-2') == 0){
		$presetCss .= 'div.ot-footer div.ot-bottom-1 {width: 100%}';
	}
	if($this->countModules('bottom-1') == 0){
		$presetCss .= 'div.ot-footer div.ot-bottom-2 {width: 100%}';
	}
	
	//+++++++++++++++++++Configuration Width of Boxes +++++++++++++++++++++++
	$unitWidthTopContentBoxes = trim($this->params->get('unitWidthTopContentBoxes'));
	
	//Custom Width TopContent Boxes
	$width_topcontents = explode(",", str_replace(array(" ",";", "(", ")"), array("", ",", "", ""), $this->params->get('width_topcontents')));
	
	$width_topcontents_additional_class = '';
	foreach (@$width_topcontents as $index => $width_topcontent) 
	{
		$width_topcontents[$index] = trim($width_topcontent);
	}
	$width_topcontents = array_unique($width_topcontents); 
	foreach ($width_topcontents as $width_topcontent) 
	{
		if (trim($width_topcontent ) != "" )
		{
			$width_topcontents_additional_class .= '
			.'.'width'.$width_topcontent. '{ width: '.$width_topcontent.$unitWidthTopContentBoxes.'; } 
			 ';
		}
	}
	
	//Custom Width BottomContent Boxes
	$unitWidthBottomContentBoxes = trim($this->params->get('unitWidthBottomContentBoxes'));
	
	$width_bottomcontents = explode(",", str_replace(array(" ",";", "(", ")"), array("", ",", "", ""), $this->params->get('width_bottomcontents')));
	
	$width_bottomcontents_additional_class = '';
	foreach (@$width_bottomcontents as $index => $width_bottomcontent) 
	{
		$width_bottomcontents[$index] = trim($width_bottomcontent);
	}
	$width_bottomcontents = array_unique($width_bottomcontents); 
	foreach ($width_bottomcontents as $width_bottomcontent) 
	{
		if (trim($width_bottomcontent ) != "" )
		{
			$width_bottomcontents_additional_class .= '
			.'.'width'.$width_bottomcontent. '{ width: '.$width_bottomcontent.$unitWidthBottomContentBoxes.'; } 
			 ';
		}
	}
	
	//Custom Width Bottom Boxes	
	$unitWidthBottomBoxes = trim($this->params->get('unitWidthBottomBoxes'));
	
	$width_bottomboxes = explode(",", str_replace(array(" ",";", "(", ")"), array("", ",", "", ""), $this->params->get('width_bottomBoxes')));
		
	$bottomboxes_additional_class = '';
	foreach (@$width_bottomboxes as $index => $width_bottombox) 
	{
		$width_bottomboxes[$index] = trim($width_bottombox);
	}
	$width_bottomboxes = array_unique($width_bottomboxes); 
	foreach ($width_bottomboxes as $width_bottombox) 
	{
		if (trim($width_bottombox ) != "" )
		{
			$bottomboxes_additional_class .= '
			.'.'width'.$width_bottombox. '{ width: '.$width_bottombox.$unitWidthBottomBoxes.'; } 
			 ';
		}
	}
		
	//+++++++++++++++++++Configuration Layout +++++++++++++++++++++++
	$layoutStyle = $this->params->get('layoutStyle');
	$this->addStyleSheet($template_url.'/css/layout/'.$layoutStyle.'.css');
	
	if($this->params->get('customBackground') == 1){
		if(trim($this->params->get('body_bgcolor')) != ''){
			$presetCss .= 'body#ot-body {background: '.$this->params->get('body_bgcolor').';}';
			//$presetCss .= 'body#ot-body {background-image: none; }';
		}
		if(trim($this->params->get('header_bgcolor')) != ''){
			$presetCss .= 'div.ot-header {background: '.$this->params->get('header_bgcolor').';}';
			//$presetCss .= 'div.ot-header {background-image: none; }';
		}
		if(trim($this->params->get('topcontents_bgcolor')) != ''){
			$presetCss .= 'div.ot-topcontents-i {background: '.$this->params->get('topcontents_bgcolor').';}';
			//$presetCss .= 'div.ot-topcontents-i {background-image: none; }';
		}
		if(trim($this->params->get('mainbody_bgcolor')) != ''){
			$presetCss .= 'div.ot-mainbody-i {background: '.$this->params->get('mainbody_bgcolor').';}';
			//$presetCss .= 'div.ot-mainbody-i {background-image: none; }';
		}
		if(trim($this->params->get('bottom_bgcolor')) != ''){
			$presetCss .= 'div.ot-bottom, div.ot-bottom-i {background: '.$this->params->get('bottom_bgcolor').';}';
			//$presetCss .= 'div.ot-bottom {background-image: none; }';
		}
	}
	
	//+++++++++++++++++++Configuration Body +++++++++++++++++++++++
	if($this->params->get('CustomBodyFont') == 1){
		if(trim($this->params->get('font_family')) != 'none'){
			$font_family = explode(':', trim($this->params->get('font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $font_family[0]));
			$presetCss .= 'body#ot-body {font-family: "'.$font_family[0].'";}';
		}
		if(trim($this->params->get('color_text')) != ''){
			$presetCss .= 'body#ot-body {color: '.$this->params->get('color_text').';}';
		}
		if(trim($this->params->get('color_links')) != ''){
			$presetCss .= 'a {color: '.$this->params->get('color_links').';}';
		}
		if(trim($this->params->get('fontSize')) != ''){
			$presetCss .= 'body#ot-body {font-size: '.$this->params->get('fontSize').';}';
		}
	}
	
	//+++++++++++++++++++Configuration Heading Tags++++++++++++++++++++
	if($this->params->get('CustomHeadingFont') == 1){
		// Custom style h1
		if(trim($this->params->get('h1font_family')) != 'none'){
			$h1font_family = explode(':', trim($this->params->get('h1font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h1font_family[0]));
			$presetCss .= 'h1 {font-family: "'.$h1font_family[0].'";}';
		}
		if(trim($this->params->get('h1_color')) != ''){
			$presetCss .= 'h1 {color: '.$this->params->get('h1_color').';}';
		}
		if(trim($this->params->get('h1font_size')) != ''){
			$presetCss .= 'h1 {font-size: '.$this->params->get('h1font_size').';}';
		}

		// Custom style h2
		if(trim($this->params->get('h2font_family')) != 'none'){
			$h2font_family = explode(':', trim($this->params->get('h2font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h2font_family[0]));
			$presetCss .= 'h2 {font-family: "'.$h2font_family[0].'";}';
		}
		if(trim($this->params->get('h2_color')) != ''){
			$presetCss .= 'h2 {color: '.$this->params->get('h2_color').';}';
		}
		if(trim($this->params->get('h2font_size')) != ''){
			$presetCss .= 'h2 {font-size: '.$this->params->get('h2font_size').';}';
		}	
		
		// Custom style h3
		if(trim($this->params->get('h3font_family')) != 'none'){
			$h3font_family = explode(':', trim($this->params->get('h3font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h3font_family[0]));
			$presetCss .= 'h3 {font-family: "'.$h3font_family[0].'";}';
		}
		if(trim($this->params->get('h3_color')) != ''){
			$presetCss .= 'h3 {color: '.$this->params->get('h3_color').';}';
		}
		if(trim($this->params->get('h3font_size')) != ''){
			$presetCss .= 'h3 {font-size: '.$this->params->get('h3font_size').';}';
		}
		
		// Custom style h4
		if(trim($this->params->get('h4font_family')) != 'none'){
			$h4font_family = explode(':', trim($this->params->get('h4font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h4font_family[0]));
			$presetCss .= 'h4 {font-family: "'.$h4font_family[0].'";}';
		}
		if(trim($this->params->get('h4_color')) != ''){
			$presetCss .= 'h4 {color: '.$this->params->get('h4_color').';}';
		}
		if(trim($this->params->get('h4font_size')) != ''){
			$presetCss .= 'h4 {font-size: '.$this->params->get('h4font_size').';}';
		}
		
		// Custom style h5
		if(trim($this->params->get('h5font_family')) != 'none'){
			$h5font_family = explode(':', trim($this->params->get('h5font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h5font_family[0]));
			$presetCss .= 'h5 {font-family: "'.$h5font_family[0].'";}';
		}
		if(trim($this->params->get('h5_color')) != ''){
			$presetCss .= 'h5 {color: '.$this->params->get('h5_color').';}';
		}
		if(trim($this->params->get('h5font_size')) != ''){
			$presetCss .= 'h5 {font-size: '.$this->params->get('h5font_size').';}';
		}
		
		// Custom style h6
		if(trim($this->params->get('h6font_family')) != 'none'){
			$h6font_family = explode(':', trim($this->params->get('h6font_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $h6font_family[0]));
			$presetCss .= 'h6 {font-family: "'.$h6font_family[0].'";}';
		}
		if(trim($this->params->get('h6_color')) != ''){
			$presetCss .= 'h6 {color: '.$this->params->get('h6_color').';}';
		}
		if(trim($this->params->get('h6font_size')) != ''){
			$presetCss .= 'h6 {font-size: '.$this->params->get('h6font_size').';}';
		}
	}

	//+++++++++++++++++++Configuration MainMenu++++++++++++++++++++
	if($this->params->get('CustomMainMenu') == 1){
		if(trim($this->params->get('mainnav_bgcolor')) != ''){
			$presetCss .= '#ot-mainmenu li .menu_mid, #ot-mainmenu ul.menu li.active, #ot-mainmenu ul.menu li.sfhover, #ot-mainmenu ul.menu li.active a, #ot-mainmenu ul.menu li.sfhover a, #ot-mainmenu ul.menu li.parent ul, #ot-mainmenu ul.menu li.parent ul li {background: '.$this->params->get('mainnav_bgcolor').';}';
			//$presetCss .= 'div#ot-mainmenu ul.menu li.active , div#ot-mainmenu ul.menu li.sfhover {background-image: none;}';
		}
		if(trim($this->params->get('mainnavfont_family')) != 'none'){
			$mainnavfont_family = explode(':', trim($this->params->get('mainnavfont_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $mainnavfont_family[0]));
			$presetCss .= 'div#ot-mainmenu ul.menu li a {font-family: "'.$mainnavfont_family[0].'";}';
		}
		if(trim($this->params->get('mainnav_color')) != ''){
			$presetCss .= 'div#ot-mainmenu ul.menu li.parent li a, div#ot-mainmenu ul.menu li.parent li.parent a, #ot-mainmenu ul.level0 li.parent ul li a span, div#ot-mainmenu ul.menu li.parent li a span, div#ot-mainmenu ul.menu li.parent li.parent a span {color: '.$this->params->get('mainnav_color').';}';
		}
		if(trim($this->params->get('mainnavfont_size')) != ''){
			$presetCss .= 'div#ot-mainmenu ul.menu li a {font-size: '.$this->params->get('mainnavfont_size').';}';
		}
	}
	
	//+++++++++++++++++++Configuration Blcokquote++++++++++++++++++++
	if($this->params->get('CustomBlockquote') == 1){
		if(trim($this->params->get('blockquotefont_family')) != 'none'){
			$blockquotefont_family = explode(':', trim($this->params->get('blockquotefont_family')));
			$this->addStyleSheet('http://fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $blockquotefont_family[0]));
			$presetCss .= 'blockquote {font-family: "'.$blockquotefont_family[0].'";}';
		}
		if(trim($this->params->get('blockquote_color')) != ''){
			$presetCss .= 'blockquote {color: '.$this->params->get('blockquote_color').';}';
		}
		if(trim($this->params->get('blockquotefont_size')) != ''){
			$presetCss .= 'blockquote {font-size: '.$this->params->get('blockquotefont_size').';}';
		}
	}
	
	//Include CSS of Configuration Params
	$this->addStyleDeclaration($presetCss);
	$this->addStyleDeclaration($width_topcontents_additional_class);
	$this->addStyleDeclaration($width_bottomcontents_additional_class);
	$this->addStyleDeclaration($bottomboxes_additional_class);
	
	// Load mootools
	JHTML::_('behavior.framework');
	
	$this->addScript($template_url.'/scripts/menudropdown.js');
	
	// load others js
	$this->addScript($template_url.'/scripts/otscript.js');
	
	
	// ie9 fix
	if (isIe(9))
	{
		$css = '<link rel="stylesheet" href="%s" type="text/css" />';
		$ie9[] = sprintf($css, $template_url.'/css/ie9.css');
		$this->addCustomTag('<!--[if IE 9]>'.implode("\n", $ie9).'<![endif]-->');
	}
	
	// ie8 fix
	if (isIe(8))
	{
		$css = '<link rel="stylesheet" href="%s" type="text/css" />';
		$ie8[] = sprintf($css, $template_url.'/css/ie8.css');
		$this->addCustomTag('<!--[if IE 8]>'.implode("\n", $ie8).'<![endif]-->');
	}
	
	// ie7 fix
	if (isIe(7))
	{
		$css = '<link rel="stylesheet" href="%s" type="text/css" />';
		$ie7[] = sprintf($css, $template_url.'/css/ie7.css');
		$this->addCustomTag('<!--[if IE 7]>'.implode("\n", $ie7).'<![endif]-->');
	}
?>
