
var enotionz = {
	createTwitterBadge: function() {
			
		$.jTwitter('enotionz', 4, function(posts){
			var output = '<div class="ez-sidebarTitle"> <p><a href="http://twitter.com/enotionz" title="follow me!" target="_new">@Enotionz</a></p></div> \
				<div id="ez-tweets">';
			
			for (var i=0; i<posts.length; i++){
				var date = posts[i].created_at,
					id = posts[i].id,
					tweet = posts[i].text,
					replyTo = posts[i].in_reply_to_screen_name,
					replyId = posts[i].in_reply_to_status_id;

				output += '\
					<div class="tw-post" id="'+ id +'"> \
						<div class="tw-date">' + enotionz.convertTwitterDate(date) +  '</div> \
						<div class="tw-tweet">' + tweet ;
					
				if (replyTo != null) { output += ' <span class="tw-inReply">(<a href="http://twitter.com/' + replyTo + '/status/' + 
						replyId + '" target="_new">in reply to ' + replyTo + '</a>)</span>'; }
				output += '</div></div>';
				
			}
			output += '</div>';
			
			$("#ez-TwitterBadge").html(output);
			return false;
		});
		return false;
	},
	convertTwitterDate: function(strDate) {
		var date = new Date(strDate);
		var hour = (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()),
			minute = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()),
			ampm =  (date.getHours()>11 ? "PM" : "AM");
			
		return hour + ':' + minute + ' ' + ampm + ' ' + strDate.split(" ")[1] + '. ' + strDate.split(" ")[2];
	},

	showImage: function(id,label){
		if(label == "") label = "all";

		$.getJSON('../gallery/functions.php?id=' + id + '&label=' + label + '&sid=' + Math.random(), function(image) {
			var listing = "", traverse = "", ezImage = "", ezdesc = "";
			var prev = "0", next = "0";		
			/* Creates listing of images */
			for (var i=0; i<image.listing.length; i++){
				var active = (image.listing[i] == image.id ? ' class="ezgal-active"' : '');
				
				if(image.listing[i] == image.id) {
					if (i != 0)	prev = image.listing[i-1];
					if (i != image.listing.length-1)	next = image.listing[i+1];
				}

				listing += '<li' + active  + '><a href="gallery.php?id=' + image.listing[i] + '&label=' + image.setLabel +
					'" onclick="enotionz.showImage(' + image.listing[i] + ',\'' + image.setLabel + '\'); return false;">' + 
					(i+1 < 10 ? '0': '') + (i+1) + '</a></li>';

			}

			/* creates previous & next functionality */
			traverse += '<a ' + (prev == "0" ? 'class="ez-previous disabled" href="#" onclick="return false;"' : 'class="ez-previous" href="gallery.php?id=' + prev + '&label=' + image.setLabel + '" onclick="enotionz.showImage(' + prev + ',\'' + image.setLabel + '\'); return false;"') + '><span>Previous Item</span></a>'; 
			traverse += '<a ' + ( next == "0" ? 'class="ez-next disabled" href="#" onclick="return false;"' : 'class="ez-next" href="gallery.php?id=' + next + '&label=' + image.setLabel  + '" onclick="enotionz.showImage(' + next + ',\'' + image.setLabel + '\'); return false;"') + '><span>Next Item</span></a>'; 

			$("ul#ez-gallery").html(listing);
			$(".ez-traverse").html(traverse);

			/* Creates image & description */
			$("#ez-galPlaceholder").css({"width" : image.width + "px", "height" : image.height + "px", "background-image" : "url(gallery/" + 
				image.label.replace(/ /gi,'_') + "/" + image.file  + ")"});
			$("#imageTitle").html(image.name);
			$("#imageDesc").html(image.description);

			//$.historyLoad("http://www.enotionz.net/gallery.php&" + image.name);
		});
	},

}

$(document).ready(function(){
	if ($("#ez-TwitterBadge").length > 0) {
		enotionz.createTwitterBadge();
	}

	if ($("#ez-gallery").length > 0) {
	}


});

