<?php 
defined('_JEXEC') or die();


/**
 * @package		Joomla Bamboo Zen Grid Framework
 * @Type        Core Framework Files
 * @version		v1.0
 * @author		Joomal Bamboo http://www.joomlabamboo.com
 * @copyright 	Copyright (C) 2007 - 2010 Joomla Bamboo
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */
	

	// This files loads the core js for the Zen Grid Framework and then parses it via the  JS Min compressor

	
	// Include JS MIn
	include_once (dirname(__FILE__).DS.'jsmin-1.1.1.php');
	
	// The files to include
    $files = array(JPATH_ROOT."/templates/zengridframework/js/menus/accordionMenu.js",JPATH_ROOT."/templates/zengridframework/js/menus/jquery.cookie.js");
    
    // Load core popup
    if ($zgfPanelJS) $files[] = JPATH_ROOT."/templates/zengridframework/js/modal/jquery.popup.js";

	// Load reveal popup
	$reveal ="";
    if ($reveal) $files[] = JPATH_ROOT."/templates/zengridframework/js/modal/jquery.reveal.js";
    
    // Load Superfish
    if ($superfish) $files[] = JPATH_ROOT."/templates/zengridframework/js/menus/superfish.js";

	// Load Superfish Hover Intent
    if ($superfish && $sfhover) $files[] = JPATH_ROOT."/templates/zengridframework/js/menus/jquery.hoverIntent.minified.js";

	// Load Slide.js
    $files[] = JPATH_ROOT."/templates/zengridframework/js/effects/slide.js";

	// Load Hidden Panel
    if (!$zgfPanelJS && $panel && $hiddenpanelLoad)  $files[] = JPATH_ROOT."/templates/zengridframework/js/modal/hiddenpanel.js";

	// Load JS for tabs
	if ($tabs) $files[] = JPATH_ROOT."/templates/zengridframework/js/tabs/jbtabs.js";
	
	// Load the template js file
    if ($extraJS) $files[] = JPATH_ROOT."/templates/$this->template/js/template.js";
  	   
    $js = "";

	
	// If we are only combining scripts.
	//if (!($compresscripts) && !($cachejs)) {
		
		foreach($files as $file) {
			$js .= JFile::read($file); 
		}
	
		// Create the js file
    	JFile::write(JPATH_ROOT.'/cache/zengridframework/js/zengrid.js', $js);
		
		// Set the ZengridJS variable which gets output in the zgf index
		$zengridJS = "<script type='text/javascript' src='$this->baseurl/cache/zengridframework/js/zengrid.js'></script>";
	//}

	// If we are combining, compressing and not caching
	//else if ($compresscripts && !($cachejs)) {
    
		// Run through the files
    //	foreach($files as $file) {
    //   	$js .= JSMin::minify(file_get_contents($file));
    //	}

	    // Create the js file
	//    JFile::write(JPATH_ROOT.'/cache/zengridframework/js/zengrid.js', $js);
		
		// Set the ZengridJS variable which gets output in the zgf index
	//	$zengridJS = "<script type='text/javascript' src='$this->baseurl/cache/zengridframework/js/zengrid.js'></script>\n";
	//}


	// If we are caching and or combining or compressing
	//else if ($cachejs && !($compresscripts) || $cachejs && $compresscripts) {
		
		// Set up the md5 hash
	//	$md5sum = '';
	//	foreach($files as $js)
	//	{
	//		$md5sum .= md5($js);
	//	}
	
		// Setting up the file name and path to the file
	//	$path = "cache/zengridframework/js/";
	//	$cache_filename = "js-".md5($md5sum).".php";
	//   $cache_fullpath = $path.DS.$cache_filename;
		
		// Grab the cache tiem from the template parameters				
	//	$cache_time = $this->params->get('cachetime', '100000' );
		
		
		// Set up the check to see if the file exists already or hasnt expired
	//	if (JFile::exists($cache_fullpath)) {
	//	    $diff = (time()-filectime($cache_fullpath));
	//	} else {
	//	    $diff = $cache_time+1;
	//	} 
		
	
	//	if ( $diff > $cache_time )
	//	{
	//		$outfile='<?php 
	//		ob_start ("ob_gzhandler");
	//		header("Content-type: application/x-javascript; charset: UTF-8");
	//		header("Cache-Control: must-revalidate");
	//		$offset = 60 * 60 ;
	//		$ExpStr = "Expires: " . 
	//			gmdate("D, d M Y H:i:s",
	//			time() + $offset) . " GMT";
	//		header($ExpStr);
	//		?
			

	//		foreach($files as $file)
	//		{
	
	//			if (JFile::exists($file)) {
	//				$outfile .= JFile::read($file); 
	//			}
	//		}
			
			
			// Output the combined but not compressed file
	//		if ($cachejs && !($compresscripts)) {
	//			JFile::write($cache_fullpath,$outfile);
	//		}
			
			
			// Output the combined and compressed file
	//		else if ($cachejs && $compresscripts) {
	
	//			JFile::write(JPATH_ROOT.'/cache/zengridframework/js/zengridtemp.js', $outfile);
	//			$newjs = JSMin::minify(file_get_contents(JPATH_ROOT.'/cache/zengridframework/js/zengridtemp.js'));
	
				// Create the js file
	//		    JFile::write($cache_fullpath,$newjs);
	//		}
	//}
	
			// Set the ZengridJS variable which gets output in the zgf index
	//	$zengridJS = '<script type="text/javascript" src="'.$this->baseurl.'/cache/zengridframework/js/'.$cache_filename.'"></script>';
	
//}
?>