<?php
/**
 * pragmaMx  Content Management System
 * Copyright (c) 2005-2007 pragmaMx Dev Team - http://pragmaMx.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * $Revision: 1.1.2.5 $
 * $Author: tora60 $
 * $Date: 2007/10/21 14:02:13 $
 *
 * this file based on:
 * Coppermine Photo Gallery
 * Copyright (c) 2003-2005 Coppermine Dev Team
 * v1.1 originally written by Gregory DEMAR
 * 
 * 
 * modifyed by Olaf Herfurth / TerraProject (www.terraproject.de) 12/2009
 * Slideshow with javascript :
 *    Copyright 2000-2003 Patrick Fitzgerald
 *    http://slideshow.barelyfitz.com/
 
 */

defined('mxMainFileLoaded') or die('access denied');
// //// Beginn Blockkonfiguration  //////////////////////////
// der Name/Pfad des Gallerymoduls
$cpg_name = 'Gallery';
// Anzahl der Thumbnails
$limit = 6;
// Zeit zwischen den Bildwechseln
$Slide_Timout=4500;
// Höhe des Scrollbereiches (marquee-tag)
$scrollheight = '80';
// Liste der Alben, aus denen keine Bilder angezeigt werden sollen. Die ID's durch Komma trennen.
$exluded_albums = '';
// //// Ende Blockkonfiguration  ////////////////////////////
if (@file_exists('modules/' . $cpg_name . '/blocks.inc.php')) {
    include('modules/' . $cpg_name . '/blocks.inc.php');
	
} else {
    if (mxIsAdmin()) {
        $content = 'The module "' . $cpg_name . '" doesn\'t exist or is not correctly installed. Please install this module or change the Variable $cpg_name in file blocks/' . basename(__file__) . '.';
    }
    return;
}
// Abfragebedingung für versteckte Alben erstellen
$exluded_albums = preg_split('#\s*,\s*#', trim($exluded_albums));
foreach($exluded_albums as $ex) {
    $excluded[] = intval($ex);
}
$exluded_albums = '';
if (isset($excluded)) {
    $exluded_albums = ' AND p.aid NOT IN (' . implode(',', $excluded) . ')';
}

$result = sql_query("
SELECT p.pid, p.url_prefix, p.filepath, p.filename, p.aid, p.pic_rating, p.votes, p.title
FROM $CONFIG[TABLE_PICTURES] AS p INNER JOIN $CONFIG[TABLE_ALBUMS] AS a ON (p.aid = a.aid)
WHERE p.approved='YES' AND p.votes >= '{$CONFIG['min_votes_for_rating']}' AND " . $vis_groups . " " . $exluded_albums . "
ORDER BY p.pic_rating DESC, p.votes DESC, p.pid DESC
LIMIT $limit");


	pmxHeader::add('<SCRIPT type="text/javascript" src="includes/javascript/gallery_slideshow.js"></SCRIPT>');

    
	// auf Grund Problemen mit FF wird das script 2x eingebunden. Ich habe keine Ahnung, warum das dann geht.....
	
	$output = '<SCRIPT type="text/javascript" src="includes/javascript/gallery_slideshow.js"></SCRIPT>
	          <SCRIPT type="text/javascript">
	           SLIDES1 = new slideshow("SLIDES1");
			   ';
$pic = 0;
while ($row = sql_fetch_array($result)) {
    if (empty($row['title'])) {
        if (preg_match('#^(.+)\.[^.]{2,4}$#', $row['filename'], $matches)) {
            $row['title'] = $matches[1];
        }
        $row['title'] = str_replace('_', ' ', $row['title']);
    }
	$picture=get_pic_url($row, 'thumb');
	$piclink='modules.php?name=' . $cpg_name . '&act=displayimage&album=toprated&cat=0&pos=' . $pic;
	if ($pic==0) $startpic=$picture;
	

	$output.= 'SLIDES1.add_slide(s = new slide("'.$picture.'"));
                 s.link = "'.$piclink.'";
			  ';
	
    $pic++;
}

	$output.= "for (var i=0; i < SLIDES1.slides.length; i++) {
		  s = SLIDES1.slides[i];
		  s.timeout=".$Slide_Timout.";
		  s.filter = 'progid:DXImageTransform.Microsoft.Fade()';
		  } 
		  </SCRIPT>";

	
	$content= $output;
	$content.= "
	            <center><A ID=\"ss1_img_link\" HREF=\"javascript:SLIDES1.hotlink()\" ><IMG name=\"SLIDESIMG1\" src=\"".$startpic ."\"  height=\"".$scrollheight."\"                style=\"filter:progid:DXImageTransform.Microsoft.Fade()\" alt=\"Top images\"></A>
	            </center>";
	
	$content.= '
	       <SCRIPT type="text/javascript">
			<!--

			if (document.images) {
			
			SLIDES1.image = document.images.SLIDESIMG1;
			SLIDES1.update();
			SLIDES1.play();
			window.onload = function () { 
			   "SLIDES1.play()";
			}
			   
			}
			// Create a function to ramp up the image opacity in Mozilla
			var fadein_opacity = 0.04;
			var fadein_img = SLIDES1.image;
			function fadein(opacity) {
			  if (typeof opacity != "undefined") fadein_opacity = opacity;
			  if (fadein_opacity < 0.99 && fadein_img && fadein_img.style &&
				  typeof fadein_img.style.MozOpacity != "undefined") {
			
				fadein_opacity += .05;
				fadein_img.style.MozOpacity = fadein_opacity;
				setTimeout("fadein()", 50);
			  }
			}
			
			// Tell the slideshow to call our function whenever the slide is changed
			SLIDES1.post_update_hook = function() { fadein(0.04); }
			//-->
			</SCRIPT>
          ';

?>