<?php

include_once 'header.php';
if ($_GET['kid']) {
    $object_kid = $_GET['kid'];
    $fields = array('Image', 'Creator', 'Title', 'City', 'Country', 'Date Original', 'Description', 'Description French', 'Resource Identifier', 'Current Box', 'Original Format', 'Genre');
    $clause = new KORA_Clause('KID', '=', $object_kid);
    $results = KORA_Search(token, projectID, Object, $clause, $fields, array());
    echo "<div class='row'>";
    foreach ($results as $result) {
        $localName = $result['Image']['localName'];
        $full_image = getFullURLFromFileName($localName);
        $Thumb_image = getThumbURLFromFileName($localName);
        $detail_author = $result['Creator'];
        $detail_author = explode(', ', $detail_author[0]);
        $detail_title = $result['Title'];
        $detail_country = $result['Country'];
        $detail_city = $result['City'];
        $detail_date_original = "";
        $date_ = $result['Date Original'];
        if ($result['Date Original']['day']) {
            $detail_date_original .= $date_['day'] . " ";
        }
        if ($result['Date Original']['month']) {
            $detail_date_original .= getChMonth($date_['month']) . " ";
        }
        if ($result['Date Original']['year']) {
            $detail_date_original .= $date_['year'];
        }
        $detail_description = $result['Description'];
        $detail_description_french = $result['Description French'];
            echo '<a id = ' . $value['kid'] . 'single href="' . getFullURLFromFileName($value['Thumbnail']['localName']) . '" class="highslide" onclick="return hs.expand(this,	{ slideshowGroup: ' . $galleryTotal . '} )">
                <img src="' . getThumbURLFromFileName($value['Thumbnail']['localName']) . '" alt="' . htmlChars($value['Title']) . '" alt="Highslide JS" title="Click to enlarge" />
                </a>';
            echo '<div class="highslide-heading">' . $value['Title'] . '</div>';
            echo '<div class="highslide-caption">
                                   <a href="' . baseURL . pfolder . 'object/' . $value['kid'] . '/b">View Full Record</a>
                                </div></div>';
            $galleryTotal = $galleryTotal + 1;
        }
        if (!empty($value['Image'])) {
            $thumbWidth = 100;
            $thumbHeight = 120;
            //echo '<a href="'.baseURL.pfolder.'object/'.$value['kid'].'/"><img class="essayImg" width="'.$thumbWidth.'" height="'.$thumbHeight.'" src="'.getThumbURLFromFileName($value['Image']['localName']).'" alt="'.htmlChars($value['Title']).'" /></a>';
            //echo "<br />";
            echo '<div class="highslide-gallery">';
            echo '<a id = ' . $value['kid'] . 'single href="' . getFullURLFromFileName($value['Image']['localName']) . '" class="highslide" onclick="return hs.expand(this,	{ slideshowGroup: ' . $galleryTotal . '} )">
                <img src="' . getThumbURLFromFileName($value['Image']['localName']) . '" alt="' . htmlChars($value['Title']) . '" alt="Highslide JS" title="Click to enlarge" />
                </a>';
            echo '<div class="highslide-heading">' . $value['Title'] . '</div>';
            echo '<div class="highslide-caption">
                                   <a href="' . baseURL . pfolder . 'object/' . $value['kid'] . '/b">View Full Record</a>
                                </div></div>';
            $galleryTotal = $galleryTotal + 1;
        }
        //echo "<br />";
        ?>
</div><?php 
        $i++;
        if (!empty($value['Object Associator'])) {
            //collect object associators
            $obj_assocs = $value['Object Associator'];
        </div>
    </div>
</div>


<div class="row">
    <div class="large-12">
        <div class="panel" id="home_images">

		<?php 
$fields = array('Thumbnail', 'Order', 'URL');
$clause = new KORA_Clause('Section', '=', 'HighlightButton');
$results = KORA_Search(token, projectID, Section, $clause, $fields, array(array('field' => 'Order', 'direction' => SORT_ASC)));
foreach ($results as $result) {
    $localName = $result['Thumbnail']['localName'];
    $file = getFullURLFromFileName($localName);
    $image = getThumbURLFromFileName($localName);
    $image_button = "<div class='mali-image'><img width='335' height='188' src='{$file}' /></div>";
    //$button_URL = str_replace("/","",$result['URL']).".php";
    //$button_URL = str_replace("portofolio","portfolio",$button_URL);
    $arr = explode("/", $result['URL'], 2);
    if (getBetween($result['URL'], "/", "/")) {
        $button_URL = $arr[0] . ".php?name=";
        $button_URL .= getBetween($result['URL'], "/", "/");
    } else {
        $button_URL = $arr[0];
    }
    //$button_URL = array_filter($button_URL);
    echo "<a href='{$button_URL}'>{$image_button}</a>";
}
?>
            }
        } else {
            if ($value['Object Type'] == "Image") {
                if (!$imageHeader) {
                    ?>
				</ul><div class="title_related"><img src="<?php 
                    echo baseURL . pfolder;
                    ?>
images/images_gray.png" alt="Images" title="Images" />Images</div><ul>
				<?php 
                }
                $imageHeader = True;
                // var_dump(getFullURLFromFileName($value['Image']['localName']));
                if (!empty($value['Title'])) {
                    echo "<li>";
                    echo "<a href = '" . getFullURLFromFileName($value['Image']['localName']) . "' class='highslide' onclick='return hs.expand(this, { slideshowGroup: " . $galleryTotal . "} )'>" . $value['Title'] . "</a>";
                    echo '<div class="highslide-heading">' . $value['Title'] . '</div>';
                    echo '<div class="highslide-caption">
                       <a href="' . baseURL . pfolder . 'object/' . $value['kid'] . '/b">View Full Record</a>
                       </div>';
                    echo '</li>';
                    $galleryTotal = $galleryTotal + 1;
                    $docGroupNo++;
                    /*if(!empty($value['Image']))
                    				{
                    					//highslide display for SINGLE image
                    					echo '';
                    					echo '<li><a class="highslide" onclick="return hs.expand(this, { slideshowGroup: \'imgGroup-'.$imageGroupNo.'\' })" href="'.getThumbnailKORA($value['Image']['localName'], 700, 2000).'">'
                    					.$value['Title'].'</a>
                    			   		<div class="highslide-heading">'.$value['Title'].'</div>
                    			      	<div class="highslide-caption"><a href="'.baseURL.pfolder.'object/'.$value['kid'].'/">View Full Record</a><br />
            						 },
            						controls:{
            							height: 30,
            							fullscreen:false,
            							autoHide: false
            						},
            						audio: {
            							url: "http://flash.matrix.msu.edu/flowplayer/flowplayer.audio-3.2.2.swf"
            						}
            					}
            				});
            			</script>
            			<?php */
        }
        if (!empty($value['Video File'])) {
            $videoFile = mysql_escape_string(getFullURLFromFileName($value['Video File']['localName']));
            //echo $videoFile;
            ?>
            <video id = "videoPlayer" width="280" controls>
                  <source src="<?php 
            echo $videoFile;
            ?>
" type="video/mp4">
                  <source src="<?php 
            echo $videoFile;
            ?>
" type="video/ogg">
                 Your browser does not support HTML5 video.
           </video>
            <?php 
            /* var_dump($value['Video File']);
                    $assocs[] = $assoc;
                }
                //$gallery_fields = array('ALL');
                $gallery_fields = array('Title', 'Object Type', 'Image', 'Date Original', 'Description', 'Creditline', 'Multi-Part Associator', 'Object Associator');
                $gallery_order[] = array('field' => 'kid', 'direction' => SORT_ASC);
                //sort in order associated
                $gallery_query = new KORA_Clause('KID', 'IN', $assocs);
                $gallery_obj = KORA_Search(token, $projID, $objID, $gallery_query, $gallery_fields, $gallery_order);
                $i = 0;
                $imageGalleryGroupNo = 0;
                //var_dump($gallery_obj);
                foreach ($gallery_obj as $go) {
                    if (!empty($go['Image'])) {
                        if (empty($value['Image']) && empty($value['Audio File']) && empty($value['Video File'])) {
                            //highslide display for GALLERY of images associated with object
                            echo '<a class="highslide" onclick="return hs.expand(this, { slideshowGroup: \'imgGalgroup-' . $imageGalleryGroupNo . '\' })" href="' . getFullURLFromFileName($go['Image']['localName'], 1500, 1500) . '">';
                            //only print title for gallery group once
                            if ($i == 0) {
                                echo "View SlideShow";
                            }
                            //KID in link must be for full record, not multi-part
                            echo '</a>
			  	 				<div class="highslide-heading">' . $go['Title'] . '</div>
			  	    			<div class="highslide-caption"><a href="' . baseURL . pfolder . 'object/' . $value['kid'] . '/">View Full Record</a><br />
			   	  	 			<br />
			    	  			' . $go['Description'] . '<br /><br />
			    	  			' . $go['Creditline'] . ' (' . formatDate($go['Date Original']['month'], $go['Date Original']['day'], $go['Date Original']['year']) . ')' . '
			    	  			</div>
			     				<div class="clearboth"></div>';
                        }
                    }
			<?php 
if ($_GET['title']) {
    $fields = array('Thumbnail', 'Photographer', 'Title', 'Date', 'Location');
    $clause = new KORA_Clause('Section', '=', 'HighlightPhotographer');
    $results = KORA_Search(token, projectID, Section, $clause, $fields, array(array('field' => 'Order', 'direction' => SORT_ASC)));
    $pics_kid = array();
    $file = array();
    $image = array();
    $pic_photographer = array();
    $pic_title = array();
    $pic_date = array();
    $pic_location = array();
    foreach ($results as $result) {
        array_push($pics_kid, $result['kid']);
        $localName = $result['Thumbnail']['localName'];
        array_push($file, getFullURLFromFileName($localName));
        array_push($image, getThumbURLFromFileName($localName));
        array_push($pic_photographer, $result['Photographer']);
        array_push($pic_title, $result['Title']);
        array_push($pic_date, $result['Date']);
        array_push($pic_location, $result['Location']);
    }
    $pic_date_string = array();
    foreach ($pic_date as $value) {
        $str_date = "";
        if ($value['day']) {
            $str_date .= $value['day'] . " ";
        }
        if ($value['month']) {
            $str_date .= getChMonth($value['month']) . " ";
        }