<?php
echo '<?xml version="1.0" ?>';
?>
<Module>
<ModulePrefs title="The Orchard Artist News Gadget"
	title_url="http://www.theorchard.com" description="Artist News"
	author="The Orchard" author_email="paulo@theorchard.com" thumbnail=""
	screenshot="" />
<UserPref name="artist_id" display_name="Artist ID" required="true"
	default_value=""></UserPref>
<UserPref name="highlight" display_name="Highlight"
	default_value="#FF0000"></UserPref>
<UserPref name="dimension" display_name="Dimension" datatype="enum"
	default_value="S">
<EnumValue value="S" display_value="Small" />
<EnumValue value="L" display_value="Large" />
</UserPref>
<UserPref name="theme" display_name="Theme" datatype="enum"
	default_value="light">
<EnumValue value="light" display_value="Light" />
<EnumValue value="dark" display_value="Dark" />
</UserPref>
<Content type="html">
<![CDATA[
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
			<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
			<link href="/css/artist-redesign.css" rel="stylesheet" type="text/css">
			<title>News Gadget</title>
			<style>
				.blurb a,
				.blurb a:link,
				.blurb a:visited,
				.blurb a:hover {
					color: <?=(isset ( $this->highlight ) ? "#" . $this->highlight : "#000000")?>;
				}
				.linkText {
					cursor: pointer;
					color: <?=(isset ( $this->highlight ) ? "#" . $this->highlight : "#000000")?>;
					font-weight: bold;
					font-size: 16px;
					padding: 2px 0;
					width: 100%;
				}
			</style>
			<script type="text/javascript" src="/scripts/jquery-1.4.2.min.js"></script>
			<script type="text/javascript" src="/scripts/jquery.tools1.1.2.min.js"></script>
			</head>
			<body>
				<div id="container">
					<div id="widgetNewsContainer" class="<?
					$className = "";
					if (isset ( $this->dimension ) && isset ( $this->theme )) {
						switch ($this->dimension) {
							case "S" :
								switch ($this->theme) {
									case "light" :
										$className = "smallWhite";
										break;
									case "dark" :
										$className = "smallBlack";
										break;
								}
								break;
							case "L" :
								switch ($this->theme) {
									case "light" :
										$className = "largeWhite";
										break;
									case "dark" :
										$className = "largeBlack";
										break;
								}
								break;
						}
					}
					echo $className;
					?>">
						<ul>
							<li id="widgetNewsHeader" class="bold">News<a id="orchardLogo" onmousedown="window.open('http://www.theorchard.com/artist/<?=$this->artist_id?>/bio')"></a></li>
							<?php
							if(count($this->news) <= 0){ ?>
								<li style="background:<?=($this->theme == "light" ? "#fff" : "#3f3f3f")?>">
									<div class="no-data">
										<div class="no-data-icon">
											<img src="<?=($this->theme == "light" ? "/gadget/img/News-light.svg" : "/gadget/img/News-dark.svg")?>"/>
										</div>
										<div style="padding:0 12px 40px 12px;text-align:center;font-weight:600;color:<?=($this->theme == "light" ? "#b5b5b5" : "#eeeeee")?>">
											No news stories found.
										</div>
									</div>
								</li>
							<?php
							}
							?>
						</ul>
						<?php
						if(count($this->news) > 0){
						?>
						<ul id="news_list">
						</ul>
						<?php } ?>
						<div id="nav">
							<div class="iconWrap left">
								<a style="cursor:pointer" onclick="leftarrow()" id="leftNav"></a>
							</div>
							<div class="iconWrap right">
								<a style="cursor:pointer" onclick="rightarrow()" id="rightNav"></a>
							</div>
							<div class="clear"></div>
						</div>
					</div>
				</div>
			<script>
				var currentPage = 0;
				var numRecordsPerPage = 5;
				var news = new Array();
				var totalPages = Math.ceil(<?=count($this->news)?>/numRecordsPerPage);
				function showArrows() {
				    if (currentPage > 0) {
				        $('.iconWrap.left').addClass('left-nav');
				    } else {
				        $('.iconWrap.left').removeClass('left-nav');
				    }
				    if ((currentPage + 1) >= totalPages) {
				        $('.iconWrap.right').addClass('right-nav');
				    } else {
				        $('.iconWrap.right').removeClass('right-nav');
				    }
				}
				function populateNewsList(page, numPerPage){
					$("#news_list").html("");
					var start = parseInt(numPerPage) * parseInt(page);
					var end = start + parseInt(numPerPage);
					for(var z=start; z<end; z++){
						if(news[z] == undefined) continue;
						$("#news_list").append('<li '+(z%2==0 ? 'class="even'+((z==start ? " first" : (z==end-1 ? " last" : "")))+'"' : '')+'><div class="linkText" onmousedown="window.open(\''+news[z]["link"]+'\')">'+news[z]["link_text"]
						+'</div><div class="blurb">'+news[z]["blurb"]
						+'</div><div class="newsLink">'+news[z]["source"]
						+'</div><div class="clear"></div></li>');
					}
					/*var embedAreaDiv = $(parent.document).find("#embedCodeArea");
					if(embedAreaDiv.attr("id") != undefined && embedAreaDiv.attr("id") != "" && embedAreaDiv.attr("id") != null){
						var tmpEmbedAreaDiv = embedAreaDiv.html();
						embedAreaDiv.html(tmpEmbedAreaDiv.replace("height:-1","height:"+$("#container").height()));
					}*/
				}
				function leftarrow() {
				    if (currentPage > 0) {
				        currentPage--;
				        populateNewsList(currentPage, numRecordsPerPage);
				    }
				    showArrows();
				}
				function rightarrow() {
				    if ((currentPage + 1) != totalPages) {
				        currentPage++;
				        populateNewsList(currentPage, numRecordsPerPage);
				    }
				    showArrows();
				}
				<?php
				if (isset ( $this->news )) {

					foreach ( $this->news as $k => $v ) {
						?>
							var tmp_news = new Array();
							tmp_news["index"] = <?=$k?>;
							tmp_news["link_text"] = "<?=$this->escapejs($v->link_text)?>";
							tmp_news["link"] = "<?=$this->escapejs($v->link)?>";
							tmp_news["source"] = "<?=$this->escapejs($v->source)?>";
							tmp_news["date_created"] = "<?=date("m/d/Y",strtotime($v->date_created))?>";
							tmp_news["blurb"] = <?=json_encode(substr(strip_tags($v->blurb),0,300).(strlen($v->blurb) > 300 ? "<span>.....</span>" : ""))?>;
							news.push(tmp_news);
							<?php
					}
				}
				?>
				$(document).ready(function(){
					<?php
					if (isset ( $this->highlight )) {
					?>

					<?php
					}
						if(count($this->news) < 6) {
					?>
						$("#leftNav").hide();
						$("#rightNav").hide();
						$(".iconWrap").hide();
					<?php
						}
					?>
					populateNewsList(currentPage, numRecordsPerPage);
				});
			</script>
			</body>
			</html>
		]]>
</Content>
</Module>